Commit
·
db8e668
1
Parent(s):
dd0805f
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,76 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: other
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
pipeline_tag: sentence-similarity
|
3 |
+
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
language: en
|
8 |
license: other
|
9 |
+
datasets:
|
10 |
+
- FremyCompany/BioLORD-Dataset
|
11 |
---
|
12 |
+
|
13 |
+
# FremyCompany/BioLORD-STAMB2-v1
|
14 |
+
This model was trained using BioLORD, a new pre-training strategy for producing meaningful representations for clinical sentences and biomedical concepts. 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. 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 establishes a new state of the art for text similarity on both clinical sentences (MedSTS) and biomedical concepts (MayoSRS).
|
15 |
+
|
16 |
+
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).
|
17 |
+
<img width="640" src="https://s3.amazonaws.com/moonup/production/uploads/1665568401241-5f04e8865d08220171a0ad3f.png" />
|
18 |
+
|
19 |
+
|
20 |
+
## General purpose
|
21 |
+
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.
|
22 |
+
|
23 |
+
## Citation
|
24 |
+
This dataset accompanies the [BioLORD: Learning Ontological Representations from Definitions](https://TODO/) paper, accepted in the EMNLP 2022 Findings. When you use this dataset, please cite the original paper as follows:
|
25 |
+
|
26 |
+
```latex
|
27 |
+
TODO
|
28 |
+
```
|
29 |
+
|
30 |
+
## Usage (Sentence-Transformers)
|
31 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
32 |
+
```
|
33 |
+
pip install -U sentence-transformers
|
34 |
+
```
|
35 |
+
Then you can use the model like this:
|
36 |
+
```python
|
37 |
+
from sentence_transformers import SentenceTransformer
|
38 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
39 |
+
|
40 |
+
model = SentenceTransformer('FremyCompany/BioLORD-STAMB2-v1')
|
41 |
+
embeddings = model.encode(sentences)
|
42 |
+
print(embeddings)
|
43 |
+
```
|
44 |
+
## Usage (HuggingFace Transformers)
|
45 |
+
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.
|
46 |
+
```python
|
47 |
+
from transformers import AutoTokenizer, AutoModel
|
48 |
+
import torch
|
49 |
+
import torch.nn.functional as F
|
50 |
+
|
51 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
52 |
+
def mean_pooling(model_output, attention_mask):
|
53 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
54 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
55 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
56 |
+
|
57 |
+
# Sentences we want sentence embeddings for
|
58 |
+
sentences = ["Cat scratch injury", "Cat scratch disease", "Bartonellosis"]
|
59 |
+
|
60 |
+
# Load model from HuggingFace Hub
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
62 |
+
model = AutoModel.from_pretrained('FremyCompany/BioLORD-STAMB2-v1')
|
63 |
+
|
64 |
+
# Tokenize sentences
|
65 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
66 |
+
|
67 |
+
# Compute token embeddings
|
68 |
+
with torch.no_grad():
|
69 |
+
model_output = model(**encoded_input)
|
70 |
+
# Perform pooling
|
71 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
72 |
+
# Normalize embeddings
|
73 |
+
sentence_embeddings = F.normalize(sentence_embeddings, p=2, dim=1)
|
74 |
+
print("Sentence embeddings:")
|
75 |
+
print(sentence_embeddings)
|
76 |
+
```
|