Tom Aarsen
commited on
Commit
·
b6cfe69
1
Parent(s):
5459159
embeddings models -> embedding models
Browse files
README.md
CHANGED
@@ -101,9 +101,9 @@ from transformers import AutoTokenizer, AutoModel
|
|
101 |
import torch
|
102 |
|
103 |
|
104 |
-
#Mean Pooling - Take attention mask into account for correct averaging
|
105 |
def mean_pooling(model_output, attention_mask):
|
106 |
-
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
107 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
108 |
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
109 |
|
@@ -122,7 +122,7 @@ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tenso
|
|
122 |
with torch.no_grad():
|
123 |
model_output = model(**encoded_input)
|
124 |
|
125 |
-
# Perform pooling. In this case,
|
126 |
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
127 |
|
128 |
print("Sentence embeddings:")
|
@@ -132,7 +132,7 @@ print(sentence_embeddings)
|
|
132 |
|
133 |
## Usage (Text Embeddings Inference (TEI))
|
134 |
|
135 |
-
[Text Embeddings Inference (TEI)](https://github.com/huggingface/text-embeddings-inference) is a blazing fast inference solution for text
|
136 |
|
137 |
- CPU:
|
138 |
```bash
|
|
|
101 |
import torch
|
102 |
|
103 |
|
104 |
+
# Mean Pooling - Take attention mask into account for correct averaging
|
105 |
def mean_pooling(model_output, attention_mask):
|
106 |
+
token_embeddings = model_output[0] # First element of model_output contains all token embeddings
|
107 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
108 |
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
109 |
|
|
|
122 |
with torch.no_grad():
|
123 |
model_output = model(**encoded_input)
|
124 |
|
125 |
+
# Perform pooling. In this case, mean pooling
|
126 |
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
127 |
|
128 |
print("Sentence embeddings:")
|
|
|
132 |
|
133 |
## Usage (Text Embeddings Inference (TEI))
|
134 |
|
135 |
+
[Text Embeddings Inference (TEI)](https://github.com/huggingface/text-embeddings-inference) is a blazing fast inference solution for text embedding models.
|
136 |
|
137 |
- CPU:
|
138 |
```bash
|