ai-forever
commited on
Commit
·
dfc02d5
1
Parent(s):
da6ad08
Update README.md
Browse files
README.md
CHANGED
@@ -21,13 +21,13 @@ from transformers import AutoTokenizer, AutoModel
|
|
21 |
import torch
|
22 |
|
23 |
#Mean Pooling - Take attention mask into account for correct averaging
|
24 |
-
|
25 |
def mean_pooling(model_output, attention_mask):
|
26 |
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
27 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
28 |
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
|
29 |
sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
30 |
return sum_embeddings / sum_mask
|
|
|
31 |
#Sentences we want sentence embeddings for
|
32 |
sentences = ['Привет! Как твои дела?',
|
33 |
'А правда, что 42 твое любимое число?']
|
|
|
21 |
import torch
|
22 |
|
23 |
#Mean Pooling - Take attention mask into account for correct averaging
|
|
|
24 |
def mean_pooling(model_output, attention_mask):
|
25 |
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
26 |
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
27 |
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
|
28 |
sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
29 |
return sum_embeddings / sum_mask
|
30 |
+
|
31 |
#Sentences we want sentence embeddings for
|
32 |
sentences = ['Привет! Как твои дела?',
|
33 |
'А правда, что 42 твое любимое число?']
|