Views
No views yet
初始模型:emilyalsentzer/Bio_ClinicalBERT(BERT-Base, cased,临床语料继续预训练)
本仓库微调后模型:multi_diagnosis_Bio_ClinicalBERT
BCEWithLogitsLoss)1tokenizer = AutoTokenizer.from_pretrained(Thehk02/multi_diagnosis_Bio_ClinicalBERT)
2model = AutoModelForSequenceClassification.from_pretrained(Thehk02/multi_diagnosis_Bio_ClinicalBERT)
31
2LABEL_NAMES = ["hypertension", "hyperlipidemia", "coronary artery disease", "atrial fibrillation", "others"]
3
4# 加载分词器与模型
5tokenizer = AutoTokenizer.from_pretrained(Thehk02/multi_diagnosis_Bio_ClinicalBERT)
6model = AutoModelForSequenceClassification.from_pretrained(Thehk02/multi_diagnosis_Bio_ClinicalBERT)
7model.eval()
8
9model.config.id2label = {i: label for i, label in enumerate(LABEL_NAMES)}
10model.config.label2id = {v: k for k, v in model.config.id2label.items()}
11
12classifier = TextClassificationPipeline(
13 model=model,
14 tokenizer=tokenizer,
15 framework="pt",
16 device=pipeline_device_idx,
17 return_all_scores=True,
18 function_to_apply="sigmoid",
19 top_k=None
20)
21
22# 单条文本预测
23text = "xxx"
24inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
25
26with torch.no_grad():
27 logits = model(**inputs).logits
28probs = torch.sigmoid(logits)[0] # 每个标签的概率
29
30# 读取标签名(建议在训练保存时写入 config)
31labels = [model.config.id2label[i] for i in range(model.config.num_labels)]
32print(dict(zip(labels, probs.tolist())))hypertension: 0.81481@misc{magnet:?xt=urn:btih:magnet:?xt=urn:btih:magnet:?xt=urn:btih:magnet:?xt=urn:btih:li2025refinemedicaldiagnosisusing,
2 title={Refine Medical Diagnosis Using Generation Augmented Retrieval and Clinical Practice Guidelines},
3 author={Wenhao Li and Hongkuan Zhang and Hongwei Zhang and Zhengxu Li and Zengjie Dong and Yafan Chen and Niranjan Bidargaddi and Hong Liu},
4 year={2025},
5 eprint={2506.21615},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2506.21615},
9}1@inproceedings{alsentzer-etal-2019-publicly,
2 title = "Publicly Available Clinical {BERT} Embeddings",
3 author = "Alsentzer, Emily and
4 Murphy, John and
5 Boag, William and
6 Weng, Wei-Hung and
7 Jin, Di and
8 Naumann, Tristan and
9 McDermott, Matthew",
10 booktitle = "Proceedings of the 2nd Clinical Natural Language Processing Workshop",
11 month = jun,
12 year = "2019",
13 address = "Minneapolis, Minnesota, USA",
14 publisher = "Association for Computational Linguistics",
15 url = "https://www.aclweb.org/anthology/W19-1909",
16 doi = "10.18653/v1/W19-1909",
17 pages = "72--78"
18}