FremyCompany
commited on
Commit
•
1343694
1
Parent(s):
6b47569
Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,120 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: other
|
3 |
license_name: ihtsdo-and-nlm-licences
|
4 |
license_link: https://www.nlm.nih.gov/databases/umls.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
language: en
|
8 |
license: other
|
9 |
license_name: ihtsdo-and-nlm-licences
|
10 |
license_link: https://www.nlm.nih.gov/databases/umls.html
|
11 |
+
datasets:
|
12 |
+
- FremyCompany/BioLORD-Dataset
|
13 |
+
- FremyCompany/AGCT-Dataset
|
14 |
+
widget:
|
15 |
+
- source_sentence: bartonellosis
|
16 |
+
sentences:
|
17 |
+
- cat scratch disease
|
18 |
+
- cat scratch wound
|
19 |
+
- tick-borne orbivirus fever
|
20 |
+
- cat fur
|
21 |
+
|
22 |
---
|
23 |
+
|
24 |
+
# FremyCompany/BioLORD-2023
|
25 |
+
This model was trained using BioLORD, a new pre-training strategy for producing meaningful representations for clinical sentences and biomedical concepts.
|
26 |
+
|
27 |
+
State-of-the-art methodologies operate by maximizing the similarity in representation of names referring to the same concept, and preventing collapse through contrastive learning. However, because biomedical names are not always self-explanatory, it sometimes results in non-semantic representations.
|
28 |
+
|
29 |
+
BioLORD overcomes this issue by grounding its concept representations using definitions, as well as short descriptions derived from a multi-relational knowledge graph consisting of biomedical ontologies. Thanks to this grounding, our model produces more semantic concept representations that match more closely the hierarchical structure of ontologies. BioLORD-2023 establishes a new state of the art for text similarity on both clinical sentences (MedSTS) and biomedical concepts (MayoSRS).
|
30 |
+
|
31 |
+
This model is based on [sentence-transformers/all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) and was further finetuned on the [BioLORD-Dataset](https://huggingface.co/datasets/FremyCompany/BioLORD-Dataset) and LLM-generated definitions from the [Automatic Glossary of Clinical Terminology (AGCT)](https://huggingface.co/datasets/FremyCompany/AGCT-Dataset).
|
32 |
+
|
33 |
+
## Sibling models
|
34 |
+
|
35 |
+
This model is accompanied by other models in the BioLORD-2023 series, which you might want to check:
|
36 |
+
|
37 |
+
- [BioLORD-2023-C](https://huggingface.co/FremyCompany/BioLORD-2023-C) (contrastive training only; for NEL tasks)
|
38 |
+
- [BioLORD-2023-S](https://huggingface.co/FremyCompany/BioLORD-2023-S) (best hyperparameters; no model averaging)
|
39 |
+
- [BioLORD-2023](https://huggingface.co/FremyCompany/BioLORD-2023) (best model after model averaging; this model)
|
40 |
+
- [BioLORD-2023-M](https://huggingface.co/FremyCompany/BioLORD-2023-M) (multilingual model; distilled from BioLORD-2023)
|
41 |
+
|
42 |
+
## Training strategy
|
43 |
+
|
44 |
+
### Summary of the 3 phases
|
45 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/my94lNjxATRU_Rg5knUZ8.png)
|
46 |
+
|
47 |
+
### Contrastive phase: details
|
48 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/_jE2ETcXkLvYLr7TeOdci.png)
|
49 |
+
|
50 |
+
### Self-distallation phase: details
|
51 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/7xuqi231RB0OzvcxK3bf-.png)
|
52 |
+
|
53 |
+
## Citation
|
54 |
+
This model accompanies the [BioLORD-2023: Learning Ontological Representations from Definitions](https://arxiv.org/abs/TBD) paper. When you use this model, please cite the original paper as follows:
|
55 |
+
|
56 |
+
```latex
|
57 |
+
@inproceedings{remy-et-al-2023-biolord,
|
58 |
+
title = "{B}io{LORD}: Semantic Textual Representations Fusing LLM and Clinical Knowledge Graph Insights",
|
59 |
+
author = "Remy, François and
|
60 |
+
Demuynck, Kris and
|
61 |
+
Demeester, Thomas",
|
62 |
+
month = dec,
|
63 |
+
year = "2023",
|
64 |
+
publisher = "ArXiv",
|
65 |
+
}
|
66 |
+
```
|
67 |
+
|
68 |
+
## Usage (Sentence-Transformers)
|
69 |
+
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.
|
70 |
+
|
71 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
72 |
+
```
|
73 |
+
pip install -U sentence-transformers
|
74 |
+
```
|
75 |
+
Then you can use the model like this:
|
76 |
+
```python
|
77 |
+
from sentence_transformers import SentenceTransformer
|
78 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
79 |
+
|
80 |
+
model = SentenceTransformer('FremyCompany/BioLORD-STAMB2-v1')
|
81 |
+
embeddings = model.encode(sentences)
|
82 |
+
print(embeddings)
|
83 |
+
```
|
84 |
+
## Usage (HuggingFace Transformers)
|
85 |
+
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.
|
86 |
+
```python
|
87 |
+
from transformers import AutoTokenizer, AutoModel
|
88 |
+
import torch
|
89 |
+
import torch.nn.functional as F
|
90 |
+
|
91 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
92 |
+
def mean_pooling(model_output, attention_mask):
|
93 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
94 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
95 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
96 |
+
|
97 |
+
# Sentences we want sentence embeddings for
|
98 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
99 |
+
|
100 |
+
# Load model from HuggingFace Hub
|
101 |
+
tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
102 |
+
model = AutoModel.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
103 |
+
|
104 |
+
# Tokenize sentences
|
105 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
106 |
+
|
107 |
+
# Compute token embeddings
|
108 |
+
with torch.no_grad():
|
109 |
+
model_output = model(**encoded_input)
|
110 |
+
# Perform pooling
|
111 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
112 |
+
# Normalize embeddings
|
113 |
+
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
114 |
+
print("Sentence embeddings:")
|
115 |
+
print(sentence_embeddings)
|
116 |
+
```
|
117 |
+
|
118 |
+
## License
|
119 |
+
My own contributions for this model are covered by the MIT license.
|
120 |
+
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.
|