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