🚀 BIOMed_NER:生物醫學實體命名實體識別
BIOMed_NER 是一個用於識別生物醫學實體的命名實體識別(NER)模型,它藉助 DeBERTaV3 來識別生物醫學實體。該模型可用於從臨床文本中提取結構化信息,例如疾病、醫療程序、藥物和解剖學術語等。
✨ 主要特性
為何選擇 DeBERTa 進行生物醫學 NER?
DeBERTa(具有解耦注意力的解碼增強型 BERT)在自然語言處理(NLP)模型架構方面實現了重大飛躍,尤其適用於生物醫學文本等複雜領域中的命名實體識別(NER)等細微任務。以下是選擇 DeBERTa 作為 BIOMed_NER 模型的理想原因:
-
先進的解耦注意力機制
- DeBERTa 超越了傳統的 Transformer 模型,採用了獨特的解耦注意力機制,分別對單詞內容和單詞位置進行編碼。這使得 DeBERTa 能夠捕捉生物醫學術語的上下文含義,並理解複雜的句子結構,這對於準確標記經常具有重疊或高度特定術語的生物醫學實體至關重要。
-
增強的嵌入以實現更豐富的上下文理解
- 生物醫學文本通常包含長句子、專業術語以及實體之間的層次關係(例如,“糖尿病”與“1 型糖尿病”)。DeBERTa 改進的嵌入層使其能夠比傳統的 Transformer 模型更好地捕捉這些細微關係,從而在理解富含上下文的醫學文檔方面特別有效。
-
在下游 NLP 任務上的卓越性能
- DeBERTa 在 GLUE 和 SQuAD 等 NLP 基準測試中始終名列前茅,這證明了它在不同任務上的泛化能力。這種高性能對於 BIOMed_NER 尤其有益,因為準確識別生物醫學實體之間的細微差異可以顯著提高從非結構化臨床筆記中提取的結構化數據的質量。
-
為最優遷移學習進行預訓練
- 利用“基礎”DeBERTaV3 變體,我們可以利用在大量文本上預訓練的模型,從而為在特定領域的生物醫學數據上進行微調提供了良好的基礎。這種預訓練結合在數據集上的微調,使 BIOMed_NER 能夠準確區分從疾病、藥物到臨床事件和解剖結構等生物醫學實體。
-
針對大型生物醫學數據集的高效微調
- DeBERTa 在準確性和效率方面都進行了優化,使得在大型複雜數據集上進行訓練變得更加容易,而無需過多的計算資源。這意味著在模型開發過程中可以進行更快的迭代,並擁有更易於部署的管道。
通過為 BIOMed_NER 選擇 DeBERTa,我們構建了一個能夠出色理解醫學複雜語言的模型,為醫療應用提供了高精度和上下文深度。無論是研究人員分析臨床數據,還是應用程序對患者記錄進行結構化處理,DeBERTa 都使 BIOMed_NER 能夠有效地提取、標記和組織關鍵的醫療信息。
🔧 技術細節
超參數
- 基礎模型:
microsoft/deberta-v3-base
- 學習率:
3e - 5
- 批量大小:
8
- 梯度累積步數:
2
- 調度器:帶預熱的餘弦調度器
- 訓練輪數:
30
- 優化器:AdamW,β值為
(0.9, 0.999)
,ε值為 1e - 8
💻 使用示例
基礎用法
from transformers import pipeline
model_path = "Helios9/BIOMed_NER"
pipe = pipeline(
task="token-classification",
model=model_path,
tokenizer=model_path,
aggregation_strategy="simple"
)
text = ("A 48-year-old female presented with vaginal bleeding and abnormal Pap smears. "
"Upon diagnosis of invasive non-keratinizing SCC of the cervix, she underwent a radical "
"hysterectomy with salpingo-oophorectomy which demonstrated positive spread to the pelvic "
"lymph nodes and the parametrium.")
result = pipe(text)
print(result)
高級用法
def merge_consecutive_entities(entities, text):
entities = sorted(entities, key=lambda x: x['start'])
merged_entities = []
current_entity = None
for entity in entities:
if current_entity is None:
current_entity = entity
elif (
entity['entity_group'] == current_entity['entity_group'] and
(entity['start'] <= current_entity['end'])
):
current_entity['end'] = max(current_entity['end'], entity['end'])
current_entity['word'] = text[current_entity['start']:current_entity['end']]
current_entity['score'] = (current_entity['score'] + entity['score']) / 2
else:
merged_entities.append(current_entity)
current_entity = entity
if current_entity:
merged_entities.append(current_entity)
return merged_entities
from transformers import pipeline
model_path = "Helios9/BIOMed_NER"
pipe = pipeline(
task="token-classification",
model=model_path,
tokenizer=model_path,
aggregation_strategy="simple"
)
text = ("A 48-year-old female presented with vaginal bleeding and abnormal Pap smears. "
"Upon diagnosis of invasive non-keratinizing SCC of the cervix, she underwent a radical "
"hysterectomy with salpingo-oophorectomy which demonstrated positive spread to the pelvic "
"lymph nodes and the parametrium.")
result = pipe(text)
final_result=merge_consecutive_entities(result,text)
print(final_result)
輸出示例
輸出將是一個包含已識別實體的列表,其中包含實體類型、得分以及在文本中的起始/結束位置。以下是示例輸出格式:
[
{
"entity_group": "Disease_disorder",
"score": 0.98,
"word": "SCC of the cervix",
"start": 63,
"end": 80
},
...
]
📚 詳細文檔
使用場景
- 從醫療記錄的非結構化文本中提取臨床信息。
- 為下游生物醫學研究或應用程序構建結構化數據。
- 通過突出顯示相關生物醫學實體來協助醫療專業人員。
該模型在 Hugging Face 上公開可用,可輕鬆集成到醫療文本分析應用程序中。