Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fine-tuned bert-base-chinese for intent recognition task on [dataset](https://huggingface.co/datasets/nlp-guild/intent-recognition-biomedical)
|
2 |
+
|
3 |
+
# Usage
|
4 |
+
```python
|
5 |
+
|
6 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
7 |
+
from transformers import TextClassificationPipeline
|
8 |
+
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("nlp-guild/bert-base-chinese-finetuned-intent_recognition-biomedical")
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained("nlp-guild/bert-base-chinese-finetuned-intent_recognition-biomedical")
|
11 |
+
nlp = TextClassificationPipeline(model = model, tokenizer = tokenizer)
|
12 |
+
|
13 |
+
label_set = [
|
14 |
+
'定义',
|
15 |
+
'病因',
|
16 |
+
'预防',
|
17 |
+
'临床表现(病症表现)',
|
18 |
+
'相关病症',
|
19 |
+
'治疗方法',
|
20 |
+
'所属科室',
|
21 |
+
'传染性',
|
22 |
+
'治愈率',
|
23 |
+
'禁忌',
|
24 |
+
'化验/体检方案',
|
25 |
+
'治疗时间',
|
26 |
+
'其他'
|
27 |
+
]
|
28 |
+
|
29 |
+
def readable_results(top_k:int, usr_query:str):
|
30 |
+
raw = nlp(usr_query, top_k = top_k)
|
31 |
+
def f(x):
|
32 |
+
index = int(x['label'][6:])
|
33 |
+
x['label'] = label_set[index]
|
34 |
+
|
35 |
+
for i in raw:
|
36 |
+
f(i)
|
37 |
+
return raw
|
38 |
+
|
39 |
+
readable_results(3,'得了心脏病怎么办')
|
40 |
+
|
41 |
+
'''
|
42 |
+
[{'label': '治疗方法', 'score': 0.9994503855705261},
|
43 |
+
{'label': '其他', 'score': 0.00018375989748165011},
|
44 |
+
{'label': '临床表现(病症表现)', 'score': 0.00010841596667887643}]
|
45 |
+
'''
|
46 |
+
```
|