🚀 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}
}