Бадертдинов Ибрагим
commited on
Commit
·
4b10cf9
1
Parent(s):
86db702
Upload models
Browse files- README.md +28 -0
- config.json +27 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tf_model.h5 +3 -0
- tokenizer_config.json +1 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# BERT large model multitask (cased) for Sentence Embeddings in Russian language.
|
2 |
+
For better quality, use mean token embeddings.
|
3 |
+
## Usage (HuggingFace Models Repository)
|
4 |
+
You can use the model directly from the model repository to compute sentence embeddings:
|
5 |
+
```python
|
6 |
+
from transformers import AutoTokenizer, AutoModel
|
7 |
+
import torch
|
8 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
9 |
+
def mean_pooling(model_output, attention_mask):
|
10 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
11 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
12 |
+
sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
|
13 |
+
sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
14 |
+
return sum_embeddings / sum_mask
|
15 |
+
#Sentences we want sentence embeddings for
|
16 |
+
sentences = ['Привет! Как твои дела?',
|
17 |
+
'А правда, что 42 твое любимое число?']
|
18 |
+
#Load AutoModel from huggingface model repository
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained("sberbank-ai/sbert_large_nlu_ru")
|
20 |
+
model = AutoModel.from_pretrained("sberbank-ai/sbert_large_nlu_ru")
|
21 |
+
#Tokenize sentences
|
22 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=24, return_tensors='pt')
|
23 |
+
#Compute token embeddings
|
24 |
+
with torch.no_grad():
|
25 |
+
model_output = model(**encoded_input)
|
26 |
+
#Perform pooling. In this case, mean pooling
|
27 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
28 |
+
```
|
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/Users/ibragim/Downloads/sbert_nlu_mltsk",
|
3 |
+
"attention_probs_dropout_prob": 0.1,
|
4 |
+
"directionality": "bidi",
|
5 |
+
"gradient_checkpointing": false,
|
6 |
+
"hidden_act": "gelu",
|
7 |
+
"hidden_dropout_prob": 0.1,
|
8 |
+
"hidden_size": 1024,
|
9 |
+
"initializer_range": 0.02,
|
10 |
+
"intermediate_size": 4096,
|
11 |
+
"layer_norm_eps": 1e-12,
|
12 |
+
"max_position_embeddings": 512,
|
13 |
+
"model_type": "bert",
|
14 |
+
"num_attention_heads": 16,
|
15 |
+
"num_hidden_layers": 24,
|
16 |
+
"pad_token_id": 0,
|
17 |
+
"pooler_fc_size": 768,
|
18 |
+
"pooler_num_attention_heads": 12,
|
19 |
+
"pooler_num_fc_layers": 3,
|
20 |
+
"pooler_size_per_head": 128,
|
21 |
+
"pooler_type": "first_token_transform",
|
22 |
+
"position_embedding_type": "absolute",
|
23 |
+
"transformers_version": "4.4.0.dev0",
|
24 |
+
"type_vocab_size": 2,
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 120138
|
27 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a7e6a6d0a2d2140ebe7ccda6c907b51ffb9bf47b6d57db57a99e4c0d98a292fa
|
3 |
+
size 1712498565
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7e4a4603fa5d9df44e5a00c6e8cb0e721c6f92dc784b75b31148f9921bbdb271
|
3 |
+
size 1708149528
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "special_tokens_map_file": null, "name_or_path": "/Users/ibragim/Downloads/sbert_nlu_mltsk", "do_basic_tokenize": true, "never_split": null}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|