File size: 1,291 Bytes
37f6fdf |
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 |
fine-tuned bert-base-chinese for intent recognition task on [dataset](https://huggingface.co/datasets/nlp-guild/intent-recognition-biomedical)
# Usage
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import TextClassificationPipeline
tokenizer = AutoTokenizer.from_pretrained("nlp-guild/bert-base-chinese-finetuned-intent_recognition-biomedical")
model = AutoModelForSequenceClassification.from_pretrained("nlp-guild/bert-base-chinese-finetuned-intent_recognition-biomedical")
nlp = TextClassificationPipeline(model = model, tokenizer = tokenizer)
label_set = [
'定义',
'病因',
'预防',
'临床表现(病症表现)',
'相关病症',
'治疗方法',
'所属科室',
'传染性',
'治愈率',
'禁忌',
'化验/体检方案',
'治疗时间',
'其他'
]
def readable_results(top_k:int, usr_query:str):
raw = nlp(usr_query, top_k = top_k)
def f(x):
index = int(x['label'][6:])
x['label'] = label_set[index]
for i in raw:
f(i)
return raw
readable_results(3,'得了心脏病怎么办')
'''
[{'label': '治疗方法', 'score': 0.9994503855705261},
{'label': '其他', 'score': 0.00018375989748165011},
{'label': '临床表现(病症表现)', 'score': 0.00010841596667887643}]
'''
``` |