🚀 MedCPT介绍
MedCPT能够生成生物医学文本的嵌入向量,可用于语义搜索(密集检索)。该模型包含两个编码器:
本仓库包含MedCPT查询编码器。
MedCPT基于来自PubMed搜索日志的2.55亿个查询 - 文章对进行了前所未有的大规模预训练,在多个零样本生物医学信息检索数据集上取得了最先进的性能。一般来说,它有三个使用场景:
- 使用两个编码器进行查询到文章的搜索。
- 使用查询编码器进行查询表示,用于聚类或查询到查询的搜索。
- 使用文章编码器进行文章表示,用于聚类或文章到文章的搜索。
更多详细信息,请查看我们的论文(《Bioinformatics》,2023年)。请注意,发布版本与论文中报告的版本略有不同。
🚀 快速开始
案例1:使用MedCPT查询编码器
import torch
from transformers import AutoTokenizer, AutoModel
model = AutoModel.from_pretrained("ncbi/MedCPT-Query-Encoder")
tokenizer = AutoTokenizer.from_pretrained("ncbi/MedCPT-Query-Encoder")
queries = [
"diabetes treatment",
"How to treat diabetes?",
"A 45-year-old man presents with increased thirst and frequent urination over the past 3 months.",
]
with torch.no_grad():
encoded = tokenizer(
queries,
truncation=True,
padding=True,
return_tensors='pt',
max_length=64,
)
embeds = model(**encoded).last_hidden_state[:, 0, :]
print(embeds)
print(embeds.size())
输出结果如下:
tensor([[ 0.0413, 0.0084, -0.0491, ..., -0.4963, -0.3830, -0.3593],
[ 0.0801, 0.1193, -0.0905, ..., -0.5380, -0.5059, -0.2944],
[-0.3412, 0.1521, -0.0946, ..., 0.0952, 0.1660, -0.0902]])
torch.Size([3, 768])
这些嵌入向量与MedCPT文章编码器生成的嵌入向量处于同一空间。
案例2:使用查询对PubMed进行语义搜索
我们已经在https://ftp.ncbi.nlm.nih.gov/pub/lu/MedCPT/pubmed_embeddings/ 提供了由MedCPT文章编码器生成的所有PubMed文章的嵌入向量。你可以直接下载这些嵌入向量,使用你的查询对PubMed进行搜索。
📄 许可证
🙏 致谢
本工作得到了美国国立卫生研究院国家医学图书馆内部研究项目的支持。
⚠️ 免责声明
本工具展示了美国国家医学图书馆(NLM)国家生物技术信息中心(NCBI)计算生物学部门的研究成果。本网站生成的信息未经临床专业人员审核和监督,不应用于直接诊断或医疗决策。个人不应仅根据本网站生成的信息改变其健康行为。美国国立卫生研究院(NIH)不会独立验证本工具生成信息的有效性或实用性。如果你对本网站生成的信息有疑问,请咨询医疗保健专业人员。有关NCBI免责政策的更多信息,请参考相关内容。
📚 引用
如果你觉得本仓库有帮助,请按以下方式引用MedCPT:
@article{jin2023medcpt,
title={MedCPT: Contrastive Pre-trained Transformers with large-scale PubMed search logs for zero-shot biomedical information retrieval},
author={Jin, Qiao and Kim, Won and Chen, Qingyu and Comeau, Donald C and Yeganova, Lana and Wilbur, W John and Lu, Zhiyong},
journal={Bioinformatics},
volume={39},
number={11},
pages={btad651},
year={2023},
publisher={Oxford University Press}
}