|
--- |
|
language: en |
|
license: apache-2.0 |
|
library_name: transformers |
|
tags: |
|
- pharmacy |
|
- drug-classification |
|
- onnx |
|
--- |
|
|
|
# 药品分类模型(ONNX格式) |
|
|
|
## 模型描述 |
|
BERT-base微调的药品分类模型,转换为ONNX格式 |
|
|
|
## 使用方式 |
|
```python |
|
from transformers import AutoTokenizer, pipeline |
|
from onnxruntime import InferenceSession |
|
|
|
tokenizer = AutoTokenizer.from_pretrained("您的用户名/模型名") |
|
session = InferenceSession("model.onnx") |
|
|
|
# 预处理 |
|
inputs = tokenizer("I have a headache", return_tensors="np") |
|
|
|
# 推理 |
|
outputs = session.run(None, dict(inputs)) |
|
predicted_id = outputs[0].argmax() |
|
|
|
|
|
##前端使用方式 |
|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8" /> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
|
<title>Transformers.js Example</title> |
|
</head> |
|
<body> |
|
<h1>Transformers.js in Browser</h1> |
|
<script type="module"> |
|
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/transformers'; |
|
// 创建一个pipeline |
|
const classifier = await pipeline('text-classification','xuxiaoda/drug_classification'); |
|
// 推理 |
|
const result = await classifier('What are the drugs for treating high blood pressure?'); |
|
console.log(result[0].label); |
|
</script> |
|
</body> |
|
</html> |