|
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}] |
|
''' |
|
``` |