demdecuong commited on
Commit ·
ab1128c
1
Parent(s): 8800bcc
update readme
Browse files
README.md
CHANGED
|
@@ -1 +1,39 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This is finetune version of [SimCSE: Simple Contrastive Learning of Sentence Embeddings](https://arxiv.org/abs/2104.08821)
|
| 2 |
+
, train unsupervised on 570K stroke sentences from : stroke books, quora medical, quora's stroke and human annotates.
|
| 3 |
+
|
| 4 |
+
### Extract sentence representation
|
| 5 |
+
```
|
| 6 |
+
from transformers import AutoTokenizer, AutoModel
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("demdecuong/stroke_simcse")
|
| 8 |
+
model = AutoModel.from_pretrained("demdecuong/stroke_simcse")
|
| 9 |
+
|
| 10 |
+
text = "What are disease related to red stroke's causes?"
|
| 11 |
+
inputs = tokenizer(text, return_tensors='pt')
|
| 12 |
+
outputs = model(**inputs)[1]
|
| 13 |
+
```
|
| 14 |
+
### Build up embedding for database
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
database = [
|
| 18 |
+
'What is the daily checklist for stroke returning home',
|
| 19 |
+
'What are some tips for stroke adapt new life',
|
| 20 |
+
'What should I consider when using nursing-home care'
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
embedding = torch.zeros((len(database),768))
|
| 24 |
+
|
| 25 |
+
for i in range(len(database)):
|
| 26 |
+
inputs = tokenizer(database[i], return_tensors="pt")
|
| 27 |
+
outputs = model(**inputs)[1]
|
| 28 |
+
embedding[i] = outputs
|
| 29 |
+
|
| 30 |
+
print(embedding.shape)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
### Result
|
| 34 |
+
On our Poc testset , which contains pairs of matching question related to stroke from human-generated.
|
| 35 |
+
|
| 36 |
+
| Model | Top-1 Accuracy |
|
| 37 |
+
| ------------- | ------------- |
|
| 38 |
+
| SimCSE (supervised) | 75.83 |
|
| 39 |
+
| SimCSE (ours) | 76.66 |
|