FremyCompany
commited on
Commit
•
89fee17
1
Parent(s):
eb8e9cf
Update README.md
Browse files
README.md
CHANGED
@@ -1,5 +1,132 @@
|
|
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:
|
8 |
+
- en
|
9 |
+
- es
|
10 |
+
- fr
|
11 |
+
- de
|
12 |
+
- nl
|
13 |
+
- da
|
14 |
+
- sv
|
15 |
license: other
|
16 |
license_name: ihtsdo-and-nlm-licences
|
17 |
license_link: https://www.nlm.nih.gov/databases/umls.html
|
18 |
+
datasets:
|
19 |
+
- FremyCompany/BioLORD-Dataset
|
20 |
+
- FremyCompany/AGCT-Dataset
|
21 |
+
widget:
|
22 |
+
- source_sentence: bartonellosis
|
23 |
+
sentences:
|
24 |
+
- cat scratch disease
|
25 |
+
- cat scratch wound
|
26 |
+
- tick-borne orbivirus fever
|
27 |
+
- cat fur
|
28 |
---
|
29 |
+
|
30 |
+
# FremyCompany/BioLORD-2023-M
|
31 |
+
This model was trained using BioLORD, a new pre-training strategy for producing meaningful representations for clinical sentences and biomedical concepts.
|
32 |
+
|
33 |
+
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.
|
34 |
+
|
35 |
+
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 (EHR-Rel-B).
|
36 |
+
|
37 |
+
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).
|
38 |
+
|
39 |
+
It supports 7 European languages officially (English, Spanish, French, German, Dutch, Danish and Swedish), and many other languages unofficially.
|
40 |
+
|
41 |
+
## Sibling models
|
42 |
+
|
43 |
+
This model is accompanied by other models in the BioLORD-2023 series, which you might want to check:
|
44 |
+
|
45 |
+
- [BioLORD-2023-M](https://huggingface.co/FremyCompany/BioLORD-2023-M) (multilingual model; distilled from BioLORD-2023; this model)
|
46 |
+
- [BioLORD-2023](https://huggingface.co/FremyCompany/BioLORD-2023) (best monolingual English model; after model averaging)
|
47 |
+
- [BioLORD-2023-S](https://huggingface.co/FremyCompany/BioLORD-2023-S) (best monolingual English model; no model averaging)
|
48 |
+
- [BioLORD-2023-C](https://huggingface.co/FremyCompany/BioLORD-2023-C) (monolingual English model; contrastive training only)
|
49 |
+
|
50 |
+
You can also take a look at last year's model and paper:
|
51 |
+
|
52 |
+
- [BioLORD-2022](https://huggingface.co/FremyCompany/BioLORD-STAMB2-v1) (also known as BioLORD-STAMB2-v1)
|
53 |
+
|
54 |
+
## Training strategy
|
55 |
+
|
56 |
+
### Summary of the 3 phases
|
57 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/my94lNjxATRU_Rg5knUZ8.png)
|
58 |
+
|
59 |
+
### Contrastive phase: details
|
60 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/_jE2ETcXkLvYLr7TeOdci.png)
|
61 |
+
|
62 |
+
### Self-distallation phase: details
|
63 |
+
![image/png](https://cdn-uploads.huggingface.co/production/uploads/5f04e8865d08220171a0ad3f/7xuqi231RB0OzvcxK3bf-.png)
|
64 |
+
|
65 |
+
## Citation
|
66 |
+
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:
|
67 |
+
|
68 |
+
```latex
|
69 |
+
@inproceedings{remy-et-al-2023-biolord,
|
70 |
+
title = "{B}io{LORD}: Semantic Textual Representations Fusing LLM and Clinical Knowledge Graph Insights",
|
71 |
+
author = "Remy, François and
|
72 |
+
Demuynck, Kris and
|
73 |
+
Demeester, Thomas",
|
74 |
+
month = dec,
|
75 |
+
year = "2023",
|
76 |
+
publisher = "ArXiv",
|
77 |
+
}
|
78 |
+
```
|
79 |
+
|
80 |
+
## Usage (Sentence-Transformers)
|
81 |
+
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.
|
82 |
+
|
83 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
84 |
+
```
|
85 |
+
pip install -U sentence-transformers
|
86 |
+
```
|
87 |
+
Then you can use the model like this:
|
88 |
+
```python
|
89 |
+
from sentence_transformers import SentenceTransformer
|
90 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
91 |
+
|
92 |
+
model = SentenceTransformer('FremyCompany/BioLORD-STAMB2-v1')
|
93 |
+
embeddings = model.encode(sentences)
|
94 |
+
print(embeddings)
|
95 |
+
```
|
96 |
+
## Usage (HuggingFace Transformers)
|
97 |
+
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.
|
98 |
+
```python
|
99 |
+
from transformers import AutoTokenizer, AutoModel
|
100 |
+
import torch
|
101 |
+
import torch.nn.functional as F
|
102 |
+
|
103 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
104 |
+
def mean_pooling(model_output, attention_mask):
|
105 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
106 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
107 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
108 |
+
|
109 |
+
# Sentences we want sentence embeddings for
|
110 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
111 |
+
|
112 |
+
# Load model from HuggingFace Hub
|
113 |
+
tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
114 |
+
model = AutoModel.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
115 |
+
|
116 |
+
# Tokenize sentences
|
117 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
118 |
+
|
119 |
+
# Compute token embeddings
|
120 |
+
with torch.no_grad():
|
121 |
+
model_output = model(**encoded_input)
|
122 |
+
# Perform pooling
|
123 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
124 |
+
# Normalize embeddings
|
125 |
+
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
126 |
+
print("Sentence embeddings:")
|
127 |
+
print(sentence_embeddings)
|
128 |
+
```
|
129 |
+
|
130 |
+
## License
|
131 |
+
My own contributions for this model are covered by the MIT license.
|
132 |
+
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.
|