qiaojin commited on
Commit
52ea8ab
1 Parent(s): cda3e75

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +74 -0
README.md CHANGED
@@ -3,3 +3,77 @@ 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
+ **MedCPT has been pre-trained by an unprecedented scale of 255M query-article pairs from PubMed search logs**. In general, there are three use cases:
13
+ 1. Query-to-article search with both encoders.
14
+ 2. Query representation for clustering or query-to-query search with the [query encoder)[https://huggingface.co/ncbi/MedCPT-Query-Encoder].
15
+ 3. Article representation for clustering or article-to-article search with the (prticle encoder)[https://huggingface.co/ncbi/MedCPT-Article-Encoder].
16
+
17
+ For more details, please check out our [paper](https://arxiv.org/abs/2307.00589) (Bioinformatics, 2023).
18
+
19
+ # Using the MedCPT Query Encoder
20
+
21
+ ```python
22
+ import torch
23
+ from transformers import AutoTokenizer, AutoModel
24
+
25
+ model = AutoModel.from_pretrained("ncbi/MedCPT-Query-Encoder")
26
+ tokenizer = AutoTokenizer.from_pretrained("ncbi/MedCPT-Query-Encoder")
27
+
28
+ queries = [
29
+ "diabetes treatment",
30
+ "How to treat diabetes?",
31
+ "A 45-year-old man presents with increased thirst and frequent urination over the past 3 months.",
32
+ ]
33
+
34
+ with torch.no_grad():
35
+ # tokenize the queries
36
+ encoded = tokenizer(
37
+ queries,
38
+ truncation=True,
39
+ padding=True,
40
+ return_tensors='pt',
41
+ max_length=64,
42
+ )
43
+
44
+ # encode the queries (use the [CLS] last hidden states as the representations)
45
+ embeds = model(**encoded).last_hidden_state[:, 0, :]
46
+
47
+ print(embeds)
48
+ print(embeds.size())
49
+ ```
50
+ The output will be:
51
+ ```bash
52
+ tensor([[ 0.0413, 0.0084, -0.0491, ..., -0.4963, -0.3830, -0.3593],
53
+ [ 0.0801, 0.1193, -0.0905, ..., -0.5380, -0.5059, -0.2944],
54
+ [-0.3412, 0.1521, -0.0946, ..., 0.0952, 0.1660, -0.0902]])
55
+ torch.Size([3, 768])
56
+ ```
57
+
58
+ ## Acknowledgments
59
+
60
+ This work was supported by the Intramural Research Programs of the National Institutes of Health, National Library of Medicine.
61
+
62
+ ## Disclaimer
63
+
64
+ 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.
65
+
66
+ ## Citation
67
+
68
+ If you find this repo helpful, please cite MedCPT by:
69
+
70
+ ```bibtext
71
+ @misc{jin2023MedCPT,
72
+ title={MedCPT: Contrastive Pre-trained Transformers with Large-scale PubMed Search Logs for Zero-shot Biomedical Information Retrieval},
73
+ author={Qiao Jin and Won Kim and Qingyu Chen and Donald C. Comeau and Lana Yeganova and John Wilbur and Zhiyong Lu},
74
+ year={2023},
75
+ eprint={2307.00589},
76
+ archivePrefix={arXiv},
77
+ primaryClass={cs.IR}
78
+ }
79
+ ```