🚀 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 上公开可用,可轻松集成到医疗文本分析应用程序中。