File size: 4,879 Bytes
f449516 4a492fb 2741e26 4a492fb 9b5001c 4a492fb 0f5dbc4 4a492fb 1c48abd 4a492fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
---
license: other
license_name: public-domain
license_link: LICENSE
---
# MedCPT Introduction
**MedCPT generates embeddings of biomedical texts that can be used for semantic search (dense retrieval)**. The model contains two encoders:
- [MedCPT Query Encoder](https://huggingface.co/ncbi/MedCPT-Query-Encoder): compute the embeddings of short texts (e.g., questions, search queries, sentences).
- [MedCPT Article Encoder](https://huggingface.co/ncbi/MedCPT-Article-Encoder): compute the embeddings of articles (e.g., PubMed titles & abstracts).
**This repo contains the MedCPT Article Encoder.**
**MedCPT has been pre-trained by an unprecedented scale of 255M query-article pairs from PubMed search logs**, and has been shown to achieve state-of-the-art performance on several zero-shot biomedical IR datasets. In general, there are three use cases:
1. Query-to-article search with both encoders.
2. Query representation for clustering or query-to-query search with the [query encoder](https://huggingface.co/ncbi/MedCPT-Query-Encoder).
3. Article representation for clustering or article-to-article search with the [article encoder](https://huggingface.co/ncbi/MedCPT-Article-Encoder).
For more details, please check out our [paper](https://arxiv.org/abs/2307.00589) (Bioinformatics, 2023). Please note that the released version is slightly different from the version reported in the paper.
# Case 1. Using the MedCPT Article Encoder
```python
import torch
from transformers import AutoTokenizer, AutoModel
model = AutoModel.from_pretrained("ncbi/MedCPT-Article-Encoder")
tokenizer = AutoTokenizer.from_pretrained("ncbi/MedCPT-Article-Encoder")
# each article contains a list of two texts (usually a title and an abstract)
articles = [
[
"Diagnosis and Management of Central Diabetes Insipidus in Adults",
"Central diabetes insipidus (CDI) is a clinical syndrome which results from loss or impaired function of vasopressinergic neurons in the hypothalamus/posterior pituitary, resulting in impaired synthesis and/or secretion of arginine vasopressin (AVP). [...]",
],
[
"Adipsic diabetes insipidus",
"Adipsic diabetes insipidus (ADI) is a rare but devastating disorder of water balance with significant associated morbidity and mortality. Most patients develop the disease as a result of hypothalamic destruction from a variety of underlying etiologies. [...]",
],
[
"Nephrogenic diabetes insipidus: a comprehensive overview",
"Nephrogenic diabetes insipidus (NDI) is characterized by the inability to concentrate urine that results in polyuria and polydipsia, despite having normal or elevated plasma concentrations of arginine vasopressin (AVP). [...]",
],
]
with torch.no_grad():
# tokenize the articles
encoded = tokenizer(
articles,
truncation=True,
padding=True,
return_tensors='pt',
max_length=512,
)
# encode the queries (use the [CLS] last hidden states as the representations)
embeds = model(**encoded).last_hidden_state[:, 0, :]
print(embeds)
print(embeds.size())
```
The output will be:
```bash
tensor([[-0.0189, 0.0115, 0.0988, ..., -0.0655, 0.3155, -0.0357],
[-0.3402, -0.3064, -0.0749, ..., -0.0799, 0.3332, 0.1263],
[-0.2764, -0.0506, -0.0608, ..., 0.0389, 0.2532, 0.1580]])
torch.Size([3, 768])
```
These embeddings are also in the same space as those generated by the MedCPT query encoder.
# Case 2. Use the Pre-computed Embeddings
We have provided the embeddings of all PubMed articles generated by the MedCPT article encoder at https://ftp.ncbi.nlm.nih.gov/pub/lu/MedCPT/pubmed_embeddings/.
# Acknowledgments
This work was supported by the Intramural Research Programs of the National Institutes of Health, National Library of Medicine.
# Disclaimer
This tool shows the results of research conducted in the Computational Biology Branch, NCBI/NLM. The information produced on this website is not intended for direct diagnostic use or medical decision-making without review and oversight by a clinical professional. Individuals should not change their health behavior solely on the basis of information produced on this website. NIH does not independently verify the validity or utility of the information produced by this tool. If you have questions about the information produced on this website, please see a health care professional. More information about NCBI's disclaimer policy is available.
# Citation
If you find this repo helpful, please cite MedCPT by:
```bibtext
@misc{jin2023MedCPT,
title={MedCPT: Contrastive Pre-trained Transformers with Large-scale PubMed Search Logs for Zero-shot Biomedical Information Retrieval},
author={Qiao Jin and Won Kim and Qingyu Chen and Donald C. Comeau and Lana Yeganova and John Wilbur and Zhiyong Lu},
year={2023},
eprint={2307.00589},
archivePrefix={arXiv},
primaryClass={cs.IR}
}
``` |