qiaojin commited on
Commit
4a492fb
1 Parent(s): 337020a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md CHANGED
@@ -3,3 +3,90 @@ license: other
3
  license_name: public-domain
4
  license_link: LICENSE
5
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  license_name: public-domain
4
  license_link: LICENSE
5
  ---
6
+ # MedCPT Introduction
7
+
8
+ **MedCPT generates embeddings of biomedical texts that can be used for semantic search (dense retrieval)**. The model contains two encoders:
9
+ - [MedCPT Query Encoder](https://huggingface.co/ncbi/MedCPT-Query-Encoder): compute the embeddings of short texts (e.g., questions, search queries, sentences).
10
+ - [MedCPT Article Encoder](https://huggingface.co/ncbi/MedCPT-Article-Encoder): compute the embeddings of articles (e.g., PubMed titles & abstracts).
11
+
12
+ **This repo contains the MedCPT Article Encoder.**
13
+
14
+ **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:
15
+ 1. Query-to-article search with both encoders.
16
+ 2. Query representation for clustering or query-to-query search with the [query encoder](https://huggingface.co/ncbi/MedCPT-Query-Encoder).
17
+ 3. Article representation for clustering or article-to-article search with the [article encoder](https://huggingface.co/ncbi/MedCPT-Article-Encoder).
18
+
19
+ For more details, please check out our [paper](https://arxiv.org/abs/2307.00589) (Bioinformatics, 2023).
20
+
21
+ # Using the MedCPT Article Encoder
22
+
23
+ ```python
24
+ import torch
25
+ from transformers import AutoTokenizer, AutoModel
26
+
27
+ model = AutoModel.from_pretrained("ncbi/MedCPT-Article-Encoder")
28
+ tokenizer = AutoTokenizer.from_pretrained("ncbi/MedCPT-Article-Encoder")
29
+
30
+ # each article contains a list of two texts (usually a title and an abstract)
31
+ articles = [
32
+ [
33
+ "Diagnosis and Management of Central Diabetes Insipidus in Adults",
34
+ "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). [...]",
35
+ ],
36
+ [
37
+ "Adipsic diabetes insipidus",
38
+ "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. [...]",
39
+ ],
40
+ [
41
+ "Nephrogenic diabetes insipidus: a comprehensive overview",
42
+ "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). [...]",
43
+ ],
44
+ ]
45
+
46
+ with torch.no_grad():
47
+ # tokenize the queries
48
+ encoded = tokenizer(
49
+ articles,
50
+ truncation=True,
51
+ padding=True,
52
+ return_tensors='pt',
53
+ max_length=512,
54
+ )
55
+
56
+ # encode the queries (use the [CLS] last hidden states as the representations)
57
+ embeds = model(**encoded).last_hidden_state[:, 0, :]
58
+
59
+ print(embeds)
60
+ print(embeds.size())
61
+ ```
62
+ The output will be:
63
+ ```bash
64
+ tensor([[-0.0189, 0.0115, 0.0988, ..., -0.0655, 0.3155, -0.0357],
65
+ [-0.3402, -0.3064, -0.0749, ..., -0.0799, 0.3332, 0.1263],
66
+ [-0.2764, -0.0506, -0.0608, ..., 0.0389, 0.2532, 0.1580]])
67
+ torch.Size([3, 768])
68
+ ```
69
+ These embeddings are also in the same space as those generated by the MedCPT query encoder.
70
+
71
+ # Acknowledgments
72
+
73
+ This work was supported by the Intramural Research Programs of the National Institutes of Health, National Library of Medicine.
74
+
75
+ # Disclaimer
76
+
77
+ 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.
78
+
79
+ # Citation
80
+
81
+ If you find this repo helpful, please cite MedCPT by:
82
+
83
+ ```bibtext
84
+ @misc{jin2023MedCPT,
85
+ title={MedCPT: Contrastive Pre-trained Transformers with Large-scale PubMed Search Logs for Zero-shot Biomedical Information Retrieval},
86
+ author={Qiao Jin and Won Kim and Qingyu Chen and Donald C. Comeau and Lana Yeganova and John Wilbur and Zhiyong Lu},
87
+ year={2023},
88
+ eprint={2307.00589},
89
+ archivePrefix={arXiv},
90
+ primaryClass={cs.IR}
91
+ }
92
+ ```