FremyCompany commited on
Commit
413bd0f
1 Parent(s): 5194a76

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +75 -1
README.md CHANGED
@@ -42,4 +42,78 @@ François Remy, Kris Demuynck, Thomas Demeester<br>
42
  ### 📖 Annotation-preserving machine translation of English corpora to validate Dutch clinical concept extraction tools
43
  Under review, with a preprint available on Medrxiv.org, 2024<br>
44
  Tom Seinen, Jan Kors, Erik van Mulligen, Peter Rijnbeek<br>
45
- [view online](https://www.medrxiv.org/content/medrxiv/early/2024/03/15/2024.03.14.24304289.full.pdf)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  ### 📖 Annotation-preserving machine translation of English corpora to validate Dutch clinical concept extraction tools
43
  Under review, with a preprint available on Medrxiv.org, 2024<br>
44
  Tom Seinen, Jan Kors, Erik van Mulligen, Peter Rijnbeek<br>
45
+ [view online](https://www.medrxiv.org/content/medrxiv/early/2024/03/15/2024.03.14.24304289.full.pdf)
46
+
47
+
48
+ ## Citation
49
+ This model accompanies the [BioLORD-2023: Learning Ontological Representations from Definitions](https://arxiv.org/abs/2311.16075) paper. When you use this model, please cite the original paper as follows:
50
+
51
+ ```latex
52
+ @article{remy-etal-2023-biolord,
53
+ author = {Remy, François and Demuynck, Kris and Demeester, Thomas},
54
+ title = "{BioLORD-2023: semantic textual representations fusing large language models and clinical knowledge graph insights}",
55
+ journal = {Journal of the American Medical Informatics Association},
56
+ pages = {ocae029},
57
+ year = {2024},
58
+ month = {02},
59
+ issn = {1527-974X},
60
+ doi = {10.1093/jamia/ocae029},
61
+ url = {https://doi.org/10.1093/jamia/ocae029},
62
+ eprint = {https://academic.oup.com/jamia/advance-article-pdf/doi/10.1093/jamia/ocae029/56772025/ocae029.pdf},
63
+ }
64
+ ```
65
+
66
+ ## Usage (Sentence-Transformers)
67
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search. This model has been finentuned for the biomedical domain. While it preserves a good ability to produce embeddings for general-purpose text, it will be more useful to you if you are trying to process medical documents such as EHR records or clinical notes. Both sentences and phrases can be embedded in the same latent space.
68
+
69
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
70
+ ```
71
+ pip install -U sentence-transformers
72
+ ```
73
+ Then you can use the model like this:
74
+ ```python
75
+ from sentence_transformers import SentenceTransformer
76
+ sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
77
+
78
+ model = SentenceTransformer('FremyCompany/BioLORD-2023-M')
79
+ embeddings = model.encode(sentences)
80
+ print(embeddings)
81
+ ```
82
+
83
+ ## Usage (HuggingFace Transformers)
84
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
85
+ ```python
86
+ from transformers import AutoTokenizer, AutoModel
87
+ import torch
88
+ import torch.nn.functional as F
89
+
90
+ #Mean Pooling - Take attention mask into account for correct averaging
91
+ def mean_pooling(model_output, attention_mask):
92
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
93
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
94
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
95
+
96
+ # Sentences we want sentence embeddings for
97
+ sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
98
+
99
+ # Load model from HuggingFace Hub
100
+ tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-2023-M')
101
+ model = AutoModel.from_pretrained('FremyCompany/BioLORD-2023-M')
102
+
103
+ # Tokenize sentences
104
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
105
+
106
+ # Compute token embeddings
107
+ with torch.no_grad():
108
+ model_output = model(**encoded_input)
109
+ # Perform pooling
110
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
111
+ # Normalize embeddings
112
+ sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
113
+ print("Sentence embeddings:")
114
+ print(sentence_embeddings)
115
+ ```
116
+
117
+ ## License
118
+ My own contributions for this model are covered by the MIT license.
119
+ However, given the data used to train this model originates from UMLS and SnomedCT, you will need to ensure you have proper licensing of UMLS and SnomedCT before using this model. Both UMLS and SnomedCT are free of charge in most countries, but you might have to create an account and report on your usage of the data yearly to keep a valid license.