File size: 1,316 Bytes
006e0da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3b4fb69
006e0da
3b4fb69
006e0da
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---
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>