ai-forever commited on
Commit
b4af5fd
1 Parent(s): 95c66a0

Upload 10 files

Browse files
.gitattributes CHANGED
@@ -7,3 +7,4 @@
7
  *.ot filter=lfs diff=lfs merge=lfs -text
8
  *.onnx filter=lfs diff=lfs merge=lfs -text
9
  *.msgpack filter=lfs diff=lfs merge=lfs -text
 
 
7
  *.ot filter=lfs diff=lfs merge=lfs -text
8
  *.onnx filter=lfs diff=lfs merge=lfs -text
9
  *.msgpack filter=lfs diff=lfs merge=lfs -text
10
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,53 +1,143 @@
1
  ---
2
- language:
3
- - ru
4
  tags:
5
- - PyTorch
6
- - Transformers
 
 
 
 
7
  ---
8
 
9
- # BERT large model (uncased) for Sentence Embeddings in Russian language.
10
- The model is described [in this article](https://habr.com/ru/company/sberdevices/blog/527576/)
11
- For better quality, use mean token embeddings.
12
 
13
- ## Usage (HuggingFace Models Repository)
14
 
15
- You can use the model directly from the model repository to compute sentence embeddings:
16
- ```python
17
- from transformers import AutoTokenizer, AutoModel
18
- import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
 
20
 
21
- #Mean Pooling - Take attention mask into account for correct averaging
22
- def mean_pooling(model_output, attention_mask):
23
- token_embeddings = model_output[0] #First element of model_output contains all token embeddings
24
- input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
25
- sum_embeddings = torch.sum(token_embeddings * input_mask_expanded, 1)
26
- sum_mask = torch.clamp(input_mask_expanded.sum(1), min=1e-9)
27
- return sum_embeddings / sum_mask
28
 
 
29
 
 
30
 
31
- #Sentences we want sentence embeddings for
32
- sentences = ['Привет! Как твои дела?',
33
- 'А правда, что 42 твое любимое число?']
34
 
35
- #Load AutoModel from huggingface model repository
36
- tokenizer = AutoTokenizer.from_pretrained("ai-forever/sbert_large_nlu_ru")
37
- model = AutoModel.from_pretrained("ai-forever/sbert_large_nlu_ru")
38
 
39
- #Tokenize sentences
40
- encoded_input = tokenizer(sentences, padding=True, truncation=True, max_length=24, return_tensors='pt')
 
41
 
42
- #Compute token embeddings
43
- with torch.no_grad():
44
- model_output = model(**encoded_input)
 
 
 
 
 
 
 
 
45
 
46
- #Perform pooling. In this case, mean pooling
47
- sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
 
 
48
  ```
49
 
50
- # Authors
51
- + [SberDevices](https://sberdevices.ru/) Team.
52
- + Aleksandr Abramov: [HF profile](https://huggingface.co/Andrilko), [Github](https://github.com/Ab1992ao), [Kaggle Competitions Master](https://www.kaggle.com/andrilko);
53
- + Denis Antykhov: [Github](https://github.com/gaphex);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: []
3
+ library_name: sentence-transformers
4
  tags:
5
+ - sentence-transformers
6
+ - sentence-similarity
7
+ - feature-extraction
8
+ base_model: ai-forever/sbert_large_nlu_ru
9
+ widget: []
10
+ pipeline_tag: sentence-similarity
11
  ---
12
 
13
+ # SentenceTransformer based on ai-forever/sbert_large_nlu_ru
 
 
14
 
15
+ This is a [sentence-transformers](https://www.SBERT.net) model finetuned from [ai-forever/sbert_large_nlu_ru](https://huggingface.co/ai-forever/sbert_large_nlu_ru). It maps sentences & paragraphs to a 1024-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.
16
 
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+ - **Model Type:** Sentence Transformer
21
+ - **Base model:** [ai-forever/sbert_large_nlu_ru](https://huggingface.co/ai-forever/sbert_large_nlu_ru) <!-- at revision 95c66a03e1cea189286bf8ba895999f1fd355d8c -->
22
+ - **Maximum Sequence Length:** 512 tokens
23
+ - **Output Dimensionality:** 1024 tokens
24
+ - **Similarity Function:** Cosine Similarity
25
+ <!-- - **Training Dataset:** Unknown -->
26
+ <!-- - **Language:** Unknown -->
27
+ <!-- - **License:** Unknown -->
28
+
29
+ ### Model Sources
30
+
31
+ - **Documentation:** [Sentence Transformers Documentation](https://sbert.net)
32
+ - **Repository:** [Sentence Transformers on GitHub](https://github.com/UKPLab/sentence-transformers)
33
+ - **Hugging Face:** [Sentence Transformers on Hugging Face](https://huggingface.co/models?library=sentence-transformers)
34
 
35
+ ### Full Model Architecture
36
 
37
+ ```
38
+ SentenceTransformer(
39
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
40
+ (1): Pooling({'word_embedding_dimension': 1024, '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, 'include_prompt': True})
41
+ )
42
+ ```
 
43
 
44
+ ## Usage
45
 
46
+ ### Direct Usage (Sentence Transformers)
47
 
48
+ First install the Sentence Transformers library:
 
 
49
 
50
+ ```bash
51
+ pip install -U sentence-transformers
52
+ ```
53
 
54
+ Then you can load this model and run inference.
55
+ ```python
56
+ from sentence_transformers import SentenceTransformer
57
 
58
+ # Download from the 🤗 Hub
59
+ model = SentenceTransformer("sentence_transformers_model_id")
60
+ # Run inference
61
+ sentences = [
62
+ 'The weather is lovely today.',
63
+ "It's so sunny outside!",
64
+ 'He drove to the stadium.',
65
+ ]
66
+ embeddings = model.encode(sentences)
67
+ print(embeddings.shape)
68
+ # [3, 1024]
69
 
70
+ # Get the similarity scores for the embeddings
71
+ similarities = model.similarity(embeddings, embeddings)
72
+ print(similarities.shape)
73
+ # [3, 3]
74
  ```
75
 
76
+ <!--
77
+ ### Direct Usage (Transformers)
78
+
79
+ <details><summary>Click to see the direct usage in Transformers</summary>
80
+
81
+ </details>
82
+ -->
83
+
84
+ <!--
85
+ ### Downstream Usage (Sentence Transformers)
86
+
87
+ You can finetune this model on your own dataset.
88
+
89
+ <details><summary>Click to expand</summary>
90
+
91
+ </details>
92
+ -->
93
+
94
+ <!--
95
+ ### Out-of-Scope Use
96
+
97
+ *List how the model may foreseeably be misused and address what users ought not to do with the model.*
98
+ -->
99
+
100
+ <!--
101
+ ## Bias, Risks and Limitations
102
+
103
+ *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
104
+ -->
105
+
106
+ <!--
107
+ ### Recommendations
108
+
109
+ *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
110
+ -->
111
+
112
+ ## Training Details
113
+
114
+ ### Framework Versions
115
+ - Python: 3.9.6
116
+ - Sentence Transformers: 3.0.0
117
+ - Transformers: 4.41.2
118
+ - PyTorch: 2.3.0
119
+ - Accelerate:
120
+ - Datasets: 2.19.2
121
+ - Tokenizers: 0.19.1
122
+
123
+ ## Citation
124
+
125
+ ### BibTeX
126
+
127
+ <!--
128
+ ## Glossary
129
+
130
+ *Clearly define terms in order to be accessible across audiences.*
131
+ -->
132
+
133
+ <!--
134
+ ## Model Card Authors
135
+
136
+ *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
137
+ -->
138
+
139
+ <!--
140
+ ## Model Card Contact
141
+
142
+ *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
143
+ -->
config.json CHANGED
@@ -1,8 +1,10 @@
1
  {
 
2
  "architectures": [
3
  "BertModel"
4
  ],
5
  "attention_probs_dropout_prob": 0.1,
 
6
  "directionality": "bidi",
7
  "gradient_checkpointing": false,
8
  "hidden_act": "gelu",
@@ -21,6 +23,10 @@
21
  "pooler_num_fc_layers": 3,
22
  "pooler_size_per_head": 128,
23
  "pooler_type": "first_token_transform",
 
 
 
24
  "type_vocab_size": 2,
 
25
  "vocab_size": 120138
26
  }
 
1
  {
2
+ "_name_or_path": "ai-forever/sbert_large_nlu_ru",
3
  "architectures": [
4
  "BertModel"
5
  ],
6
  "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
  "directionality": "bidi",
9
  "gradient_checkpointing": false,
10
  "hidden_act": "gelu",
 
23
  "pooler_num_fc_layers": 3,
24
  "pooler_size_per_head": 128,
25
  "pooler_type": "first_token_transform",
26
+ "position_embedding_type": "absolute",
27
+ "torch_dtype": "float32",
28
+ "transformers_version": "4.41.2",
29
  "type_vocab_size": 2,
30
+ "use_cache": true,
31
  "vocab_size": 120138
32
  }
config_sentence_transformers.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "3.0.0",
4
+ "transformers": "4.41.2",
5
+ "pytorch": "2.3.0"
6
+ },
7
+ "prompts": {},
8
+ "default_prompt_name": null,
9
+ "similarity_fn_name": null
10
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cea5e5ebffd98391d7c119f2d35a50e546aad6aea7c883bb584754874d27f622
3
+ size 1707679808
modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
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
+ ]
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json CHANGED
@@ -1 +1,7 @@
1
- {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json CHANGED
@@ -1 +1,57 @@
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": "./cased_L-24_H-1024_A-16_pytorch", "do_basic_tokenize": true, "never_split": null}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": true,
48
+ "mask_token": "[MASK]",
49
+ "model_max_length": 1000000000000000019884624838656,
50
+ "never_split": null,
51
+ "pad_token": "[PAD]",
52
+ "sep_token": "[SEP]",
53
+ "strip_accents": null,
54
+ "tokenize_chinese_chars": true,
55
+ "tokenizer_class": "BertTokenizer",
56
+ "unk_token": "[UNK]"
57
+ }