🚀 FremyCompany/BioLORD-2023-C
本模型旨在解决临床句子和生物医学概念的有意义表示问题,通过新的预训练策略BioLORD进行训练,能在临床句子和生物医学概念的文本相似度任务上达到新的最优效果。
🚀 快速开始
本模型是一个基于sentence-transformers
的模型,它可以将句子和段落映射到768维的密集向量空间,可用于聚类或语义搜索等任务。该模型针对生物医学领域进行了微调,在处理医学文档(如电子健康记录或临床笔记)时会更有用。
安装依赖
pip install -U sentence-transformers
代码示例
from sentence_transformers import SentenceTransformer
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
model = SentenceTransformer('FremyCompany/BioLORD-2023-C')
embeddings = model.encode(sentences)
print(embeddings)
✨ 主要特性
- 创新预训练策略:使用BioLORD预训练策略,利用定义和多关系知识图谱中的简短描述来构建概念表示,克服了传统方法可能产生非语义表示的问题。
- 语义匹配度高:生成的概念表示更具语义性,能更好地匹配本体的层次结构。
- 领域针对性强:针对生物医学领域进行微调,在处理医学文档时表现更优。
📦 安装指南
若要使用此模型,需安装sentence-transformers
库:
pip install -U sentence-transformers
💻 使用示例
基础用法
from sentence_transformers import SentenceTransformer
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
model = SentenceTransformer('FremyCompany/BioLORD-2023-C')
embeddings = model.encode(sentences)
print(embeddings)
高级用法
若不使用sentence-transformers
库,可按以下方式使用模型:
from transformers import AutoTokenizer, AutoModel
import torch
import torch.nn.functional as F
def mean_pooling(model_output, attention_mask):
token_embeddings = model_output[0]
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-2023-C')
model = AutoModel.from_pretrained('FremyCompany/BioLORD-2023-C')
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
with torch.no_grad():
model_output = model(**encoded_input)
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
print("Sentence embeddings:")
print(sentence_embeddings)
📚 详细文档
模型背景
当前最先进的方法通过最大化指代同一概念的名称表示的相似性,并通过对比学习防止崩溃。但由于生物医学名称并非总是自解释的,有时会导致非语义表示。BioLORD通过使用定义以及从由生物医学本体组成的多关系知识图谱中提取的简短描述来构建其概念表示,克服了这一问题。
相关模型
本模型是BioLORD - 2023系列的一部分,该系列的其他模型如下:
你还可以查看去年的模型和论文:
训练策略
三阶段概述

对比阶段详情

自蒸馏阶段详情

引用信息
本模型伴随论文BioLORD - 2023: Learning Ontological Representations from Definitions。使用此模型时,请按以下方式引用原文:
@article{remy-etal-2023-biolord,
author = {Remy, François and Demuynck, Kris and Demeester, Thomas},
title = "{BioLORD-2023: semantic textual representations fusing large language models and clinical knowledge graph insights}",
journal = {Journal of the American Medical Informatics Association},
pages = {ocae029},
year = {2024},
month = {02},
issn = {1527-974X},
doi = {10.1093/jamia/ocae029},
url = {https://doi.org/10.1093/jamia/ocae029},
eprint = {https://academic.oup.com/jamia/advance-article-pdf/doi/10.1093/jamia/ocae029/56772025/ocae029.pdf},
}
🔧 技术细节
本模型基于sentence - transformers/all - mpnet - base - v2,并在BioLORD - Dataset和来自Automatic Glossary of Clinical Terminology (AGCT)的大语言模型生成的定义上进行了进一步微调。
📄 许可证
本模型的个人贡献部分遵循MIT许可证。然而,由于训练此模型使用的数据源自UMLS和SnomedCT,在使用此模型之前,你需要确保拥有UMLS和SnomedCT的适当许可证。UMLS和SnomedCT在大多数国家都是免费的,但你可能需要创建一个账户并每年报告数据使用情况以保持有效许可证。
属性 |
详情 |
模型类型 |
基于sentence - transformers的生物医学微调模型 |
训练数据 |
BioLORD - Dataset、Automatic Glossary of Clinical Terminology (AGCT) |
⚠️ 重要提示
由于训练数据源自UMLS和SnomedCT,使用此模型前需确保拥有UMLS和SnomedCT的适当许可证。
💡 使用建议
若要处理医学文档(如电子健康记录或临床笔记),使用此模型会更有帮助。同时,安装sentence - transformers
库可更方便地使用该模型。