Add new SentenceTransformer model.
Browse files- README.md +41 -1
- modules.json +6 -0
README.md
CHANGED
@@ -5,12 +5,13 @@ tags:
|
|
5 |
- sentence-transformers
|
6 |
- feature-extraction
|
7 |
- sentence-similarity
|
|
|
8 |
|
9 |
---
|
10 |
|
11 |
# ditengm/bge-base-en-v1.5-fine-tuned_reels_1.1
|
12 |
|
13 |
-
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a
|
14 |
|
15 |
<!--- Describe your model here -->
|
16 |
|
@@ -35,6 +36,44 @@ print(embeddings)
|
|
35 |
|
36 |
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
## Evaluation Results
|
39 |
|
40 |
<!--- Describe how your model was evaluated -->
|
@@ -47,6 +86,7 @@ For an automated evaluation of this model, see the *Sentence Embeddings Benchmar
|
|
47 |
```
|
48 |
SentenceTransformer(
|
49 |
(0): Transformer({'max_seq_length': 768, 'do_lower_case': False}) with Transformer model: BertModel
|
|
|
50 |
)
|
51 |
```
|
52 |
|
|
|
5 |
- sentence-transformers
|
6 |
- feature-extraction
|
7 |
- sentence-similarity
|
8 |
+
- transformers
|
9 |
|
10 |
---
|
11 |
|
12 |
# ditengm/bge-base-en-v1.5-fine-tuned_reels_1.1
|
13 |
|
14 |
+
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.
|
15 |
|
16 |
<!--- Describe your model here -->
|
17 |
|
|
|
36 |
|
37 |
|
38 |
|
39 |
+
## Usage (HuggingFace Transformers)
|
40 |
+
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.
|
41 |
+
|
42 |
+
```python
|
43 |
+
from transformers import AutoTokenizer, AutoModel
|
44 |
+
import torch
|
45 |
+
|
46 |
+
|
47 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
48 |
+
def mean_pooling(model_output, attention_mask):
|
49 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
50 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
51 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
52 |
+
|
53 |
+
|
54 |
+
# Sentences we want sentence embeddings for
|
55 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
56 |
+
|
57 |
+
# Load model from HuggingFace Hub
|
58 |
+
tokenizer = AutoTokenizer.from_pretrained('ditengm/bge-base-en-v1.5-fine-tuned_reels_1.1')
|
59 |
+
model = AutoModel.from_pretrained('ditengm/bge-base-en-v1.5-fine-tuned_reels_1.1')
|
60 |
+
|
61 |
+
# Tokenize sentences
|
62 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
63 |
+
|
64 |
+
# Compute token embeddings
|
65 |
+
with torch.no_grad():
|
66 |
+
model_output = model(**encoded_input)
|
67 |
+
|
68 |
+
# Perform pooling. In this case, mean pooling.
|
69 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
70 |
+
|
71 |
+
print("Sentence embeddings:")
|
72 |
+
print(sentence_embeddings)
|
73 |
+
```
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
## Evaluation Results
|
78 |
|
79 |
<!--- Describe how your model was evaluated -->
|
|
|
86 |
```
|
87 |
SentenceTransformer(
|
88 |
(0): Transformer({'max_seq_length': 768, 'do_lower_case': False}) with Transformer model: BertModel
|
89 |
+
(1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False})
|
90 |
)
|
91 |
```
|
92 |
|
modules.json
CHANGED
@@ -4,5 +4,11 @@
|
|
4 |
"name": "0",
|
5 |
"path": "",
|
6 |
"type": "sentence_transformers.models.Transformer"
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
]
|
|
|
4 |
"name": "0",
|
5 |
"path": "",
|
6 |
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
}
|
14 |
]
|