Update README.md
Browse files
README.md
CHANGED
@@ -1,144 +1,207 @@
|
|
1 |
---
|
2 |
-
language:
|
|
|
3 |
library_name: sentence-transformers
|
4 |
tags:
|
5 |
- sentence-transformers
|
6 |
- sentence-similarity
|
7 |
- feature-extraction
|
8 |
-
datasets: []
|
9 |
widget: []
|
10 |
pipeline_tag: sentence-similarity
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
#
|
14 |
|
15 |
-
This is a [sentence-transformers](https://www.SBERT.net) model trained. 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 |
-
|
|
|
18 |
|
19 |
-
### Model Description
|
20 |
-
- **Model Type:** Sentence Transformer
|
21 |
-
<!-- - **Base model:** [Unknown](https://huggingface.co/unknown) -->
|
22 |
-
- **Maximum Sequence Length:** 8192 tokens
|
23 |
-
- **Output Dimensionality:** 1024 tokens
|
24 |
-
- **Similarity Function:** Cosine Similarity
|
25 |
-
<!-- - **Training Dataset:** Unknown -->
|
26 |
-
<!-- - **Language:** Unknown -->
|
27 |
-
<!-- - **License:** Unknown -->
|
28 |
|
29 |
-
|
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': 8192, 'do_lower_case': False}) with Transformer model: XLMRobertaModel
|
40 |
-
(1): Pooling({'word_embedding_dimension': 1024, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, '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 |
-
(2): Normalize()
|
42 |
-
)
|
43 |
-
```
|
44 |
|
45 |
## Usage
|
46 |
|
47 |
-
### Direct Usage (Sentence Transformers)
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
|
|
52 |
pip install -U sentence-transformers
|
53 |
```
|
54 |
|
55 |
-
|
|
|
|
|
|
|
56 |
```python
|
57 |
from sentence_transformers import SentenceTransformer
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
model = SentenceTransformer("deepvk/USER-bge-m3")
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
]
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
```
|
76 |
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
<details><summary>Click to see the direct usage in Transformers</summary>
|
81 |
|
82 |
-
|
83 |
-
-->
|
84 |
|
85 |
-
<!--
|
86 |
-
### Downstream Usage (Sentence Transformers)
|
87 |
|
88 |
-
|
|
|
|
|
89 |
|
90 |
-
<details><summary>Click to expand</summary>
|
91 |
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
<!--
|
96 |
-
### Out-of-Scope Use
|
97 |
|
98 |
-
*List how the model may foreseeably be misused and address what users ought not to do with the model.*
|
99 |
-
-->
|
100 |
|
101 |
-
<!--
|
102 |
-
## Bias, Risks and Limitations
|
103 |
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
<!--
|
108 |
-
### Recommendations
|
109 |
|
110 |
-
|
111 |
-
|
112 |
|
113 |
-
## Training Details
|
114 |
|
115 |
-
|
116 |
-
- Python: 3.10.12
|
117 |
-
- Sentence Transformers: 3.0.1
|
118 |
-
- Transformers: 4.38.2
|
119 |
-
- PyTorch: 2.2.0a0+81ea7a4
|
120 |
-
- Accelerate: 0.28.0
|
121 |
-
- Datasets: 2.20.0
|
122 |
-
- Tokenizers: 0.15.2
|
123 |
|
124 |
-
## Citation
|
125 |
|
126 |
-
|
127 |
|
128 |
-
<!--
|
129 |
-
## Glossary
|
130 |
|
131 |
-
|
132 |
-
|
|
|
133 |
|
134 |
-
<!--
|
135 |
-
## Model Card Authors
|
136 |
|
137 |
-
|
138 |
-
|
|
|
|
|
|
|
139 |
|
140 |
-
<!--
|
141 |
-
## Model Card Contact
|
142 |
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language:
|
3 |
+
- ru
|
4 |
library_name: sentence-transformers
|
5 |
tags:
|
6 |
- sentence-transformers
|
7 |
- sentence-similarity
|
8 |
- feature-extraction
|
|
|
9 |
widget: []
|
10 |
pipeline_tag: sentence-similarity
|
11 |
+
license: apache-2.0
|
12 |
+
datasets:
|
13 |
+
- deepvk/ru-HNP
|
14 |
+
- deepvk/ru-WANLI
|
15 |
+
- Shitao/bge-m3-data
|
16 |
+
- RussianNLP/russian_super_glue
|
17 |
+
- reciTAL/mlsum
|
18 |
+
- Milana/russian_keywords
|
19 |
+
- IlyaGusev/gazeta
|
20 |
+
- d0rj/gsm8k-ru
|
21 |
+
- bragovo/dsum_ru
|
22 |
+
- CarlBrendt/Summ_Dialog_News
|
23 |
---
|
24 |
|
25 |
+
# USER-bge-m3
|
26 |
|
|
|
27 |
|
28 |
+
**U**niversal **S**entence **E**ncoder for **R**ussian (USER) is a [sentence-transformer](https://www.SBERT.net) model for extracting embeddings exclusively for Russian language.
|
29 |
+
It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
This model is initialized from [`TatonkaHF/bge-m3_en_ru`](https://huggingface.co/TatonkaHF/bge-m3_en_ru) which is shrinked version of [`baai/bge-m3`](https://huggingface.co/BAAI/bge-m3) model and trained to work mainly with the Russian language. Its quality on other languages was not evaluated.
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
## Usage
|
36 |
|
|
|
37 |
|
38 |
+
Using this model becomes easy when you have [`sentence-transformers`](https://www.SBERT.net) installed:
|
39 |
|
40 |
+
|
41 |
+
```
|
42 |
pip install -U sentence-transformers
|
43 |
```
|
44 |
|
45 |
+
|
46 |
+
Then you can use the model like this:
|
47 |
+
|
48 |
+
|
49 |
```python
|
50 |
from sentence_transformers import SentenceTransformer
|
51 |
|
52 |
+
|
53 |
+
input_texts = [
|
54 |
+
"Когда был спущен на воду первый миноносец «Спокойный»?",
|
55 |
+
"Есть ли нефть в Удмуртии?",
|
56 |
+
"Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",
|
57 |
+
"Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."
|
58 |
+
]
|
59 |
+
|
60 |
+
|
61 |
model = SentenceTransformer("deepvk/USER-bge-m3")
|
62 |
+
embeddings = model.encode(input_texts, normalize_embeddings=True)
|
63 |
+
```
|
64 |
+
|
65 |
+
|
66 |
+
However, you can use model directly with [`transformers`](https://huggingface.co/docs/transformers/en/index)
|
67 |
+
|
68 |
+
|
69 |
+
```python
|
70 |
+
import torch.nn.functional as F
|
71 |
+
from torch import Tensor, inference_mode
|
72 |
+
from transformers import AutoTokenizer, AutoModel
|
73 |
+
|
74 |
+
|
75 |
+
input_texts = [
|
76 |
+
"Когда был спущен на воду первый миноносец «Спокойный»?",
|
77 |
+
"Есть ли нефть в Удмуртии?",
|
78 |
+
"Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",
|
79 |
+
"Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."
|
80 |
]
|
81 |
+
|
82 |
+
|
83 |
+
tokenizer = AutoTokenizer.from_pretrained("deepvk/USER-bge-m3")
|
84 |
+
model = AutoModel.from_pretrained("deepvk/USER-bge-m3")
|
85 |
+
model.eval()
|
86 |
+
|
87 |
+
|
88 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
89 |
+
with torch.no_grad():
|
90 |
+
model_output = model(**encoded_input)
|
91 |
+
# Perform pooling. In this case, cls pooling.
|
92 |
+
sentence_embeddings = model_output[0][:, 0]
|
93 |
+
|
94 |
+
|
95 |
+
# normalize embeddings
|
96 |
+
sentence_embeddings = torch.nn.functional.normalize(sentence_embeddings, p=2, dim=1) print("Sentence embeddings:", sentence_embeddings)
|
97 |
+
# [[0.5566 0.3013]
|
98 |
+
# [0.1703 0.7124]]
|
99 |
```
|
100 |
|
101 |
+
Also, you can use native [FlagEmbedding](https://github.com/FlagOpen/FlagEmbedding) library for evaluation. Usage is described in [`bge-m3` model card](https://huggingface.co/BAAI/bge-m3).
|
102 |
+
|
103 |
+
|
104 |
+
# Training Details
|
105 |
+
|
106 |
+
|
107 |
+
We follow the [`USER-base`](https://huggingface.co/deepvk/USER-base) model training algorithm, with several changes as we use different backbone.
|
108 |
+
|
109 |
+
|
110 |
+
**Initialization:** [`TatonkaHF/bge-m3_en_eu`](https://huggingface.co/TatonkaHF/bge-m3_en_ru) – shrinked version of [`baai/bge-m3`](https://huggingface.co/BAAI/bge-m3) to support only Russian and English tokens.
|
111 |
+
|
112 |
+
|
113 |
+
**Fine-tuning:** Supervised fine-tuning two different models based on data symmetry and then merging via [`LM-Cocktail`](https://arxiv.org/abs/2311.13534):
|
114 |
+
|
115 |
+
|
116 |
+
1. Since we split the data, we could additionally apply the [AnglE loss](https://arxiv.org/abs/2309.12871) to the symmetric model, which enhances performance on symmetric tasks.
|
117 |
+
|
118 |
+
|
119 |
+
2. Finally, we added the original `bge-m3` model to the two obtained models to prevent catastrophic forgetting, tuning the weights for the merger using `LM-Cocktail` to produce the final model, **USER-bge-m3**.
|
120 |
|
|
|
121 |
|
122 |
+
### Dataset
|
|
|
123 |
|
|
|
|
|
124 |
|
125 |
+
During model development, we additional collect 2 datasets:
|
126 |
+
[`deepvk/ru-HNP`](https://huggingface.co/datasets/deepvk/ru-HNP) and
|
127 |
+
[`deepvk/ru-WANLI`](https://huggingface.co/datasets/deepvk/ru-WANLI).
|
128 |
|
|
|
129 |
|
130 |
+
| Symmetric Dataset | Size | Asymmetric Dataset | Size |
|
131 |
+
|-------------------|-------|--------------------|------|
|
132 |
+
| **AllNLI** | 282 644 | [**MIRACL**](https://huggingface.co/datasets/Shitao/bge-m3-data/tree/main) | 10 000 |
|
133 |
+
| [MedNLI](https://github.com/jgc128/mednli) | 3 699 | [MLDR](https://huggingface.co/datasets/Shitao/bge-m3-data/tree/main) | 1 864 |
|
134 |
+
| [RCB](https://huggingface.co/datasets/RussianNLP/russian_super_glue) | 392 | [Lenta](https://github.com/yutkin/Lenta.Ru-News-Dataset) | 185 972 |
|
135 |
+
| [Terra](https://huggingface.co/datasets/RussianNLP/russian_super_glue) | 1 359 | [Mlsum](https://huggingface.co/datasets/reciTAL/mlsum) | 51 112 |
|
136 |
+
| [Tapaco](https://huggingface.co/datasets/tapaco) | 91 240 | [Mr-TyDi](https://huggingface.co/datasets/Shitao/bge-m3-data/tree/main) | 536 600 |
|
137 |
+
| [**deepvk/ru-WANLI**](https://huggingface.co/datasets/deepvk/ru-WANLI) | 35 455 | [Panorama](https://huggingface.co/datasets/its5Q/panorama) | 11 024 |
|
138 |
+
| [**deepvk/ru-HNP**](https://huggingface.co/datasets/deepvk/ru-HNP) | 500 000 | [PravoIsrael](https://huggingface.co/datasets/TarasHu/pravoIsrael) | 26 364 |
|
139 |
+
| | | [Xlsum](https://huggingface.co/datasets/csebuetnlp/xlsum) | 124 486 |
|
140 |
+
| | | [Fialka-v1](https://huggingface.co/datasets/0x7o/fialka-v1) | 130 000 |
|
141 |
+
| | | [RussianKeywords](https://huggingface.co/datasets/Milana/russian_keywords) | 16 461 |
|
142 |
+
| | | [Gazeta](https://huggingface.co/datasets/IlyaGusev/gazeta) | 121 928 |
|
143 |
+
| | | [Gsm8k-ru](https://huggingface.co/datasets/d0rj/gsm8k-ru) | 7 470 |
|
144 |
+
| | | [DSumRu](https://huggingface.co/datasets/bragovo/dsum_ru) | 27 191 |
|
145 |
+
| | | [SummDialogNews](https://huggingface.co/datasets/CarlBrendt/Summ_Dialog_News) | 75 700 |
|
146 |
|
|
|
|
|
147 |
|
|
|
|
|
148 |
|
|
|
|
|
149 |
|
150 |
+
**Total positive pairs:** 2,240,961
|
151 |
+
**Total negative pairs:** 792,644 (negative pairs from AIINLI, MIRACL, deepvk/ru-WANLI, deepvk/ru-HNP)
|
152 |
|
|
|
|
|
153 |
|
154 |
+
For all labeled datasets, we only use its training set for fine-tuning.
|
155 |
+
For datasets Gazeta, Mlsum, Xlsum: pairs (title/text) and (title/summary) are combined and used as asymmetric data.
|
156 |
|
|
|
157 |
|
158 |
+
`AllNLI` is an translated to Russian combination of SNLI, MNLI and ANLI.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
|
|
|
160 |
|
161 |
+
## Experiments
|
162 |
|
|
|
|
|
163 |
|
164 |
+
We compare our mode with the basic [`baai/bge-m3`](https://huggingface.co/BAAI/bge-m3) on the [`encodechka`](https://github.com/avidale/encodechka) benchmark.
|
165 |
+
In addition, we evaluate model on the russian subset of [`MTEB`](https://github.com/embeddings-benchmark/mteb) on Classification, Reranking, Multilabel Classification, STS, Retrieval, and PairClassification tasks.
|
166 |
+
We use validation scripts from the official repositories for each of the tasks.
|
167 |
|
|
|
|
|
168 |
|
169 |
+
Results on encodechka:
|
170 |
+
| Model | Mean S | Mean S+W | STS | PI | NLI | SA | TI | IA | IC | ICX | NE1 | NE2 |
|
171 |
+
|-------------|--------|----------|------|------|------|------|------|------|------|------|------|------|
|
172 |
+
| [`baai/bge-m3`](https://huggingface.co/BAAI/bge-m3) | 0.787 | 0.696 | 0.86 | 0.75 | 0.51 | 0.82 | 0.97 | 0.79 | 0.81 | 0.78 | 0.24 | 0.42 |
|
173 |
+
| `USER-bge-m3` | **0.799** | **0.709** | **0.87** | **0.76** | **0.58** | 0.82 | 0.97 | 0.79 | 0.81 | 0.78 | **0.28** | **0.43** |
|
174 |
|
|
|
|
|
175 |
|
176 |
+
Results on MTEB:
|
177 |
+
|
178 |
+
|
179 |
+
| Type | [`baai/bge-m3`](https://huggingface.co/BAAI/bge-m3) | `USER-bge-m3` |
|
180 |
+
|---------------------------|--------|-------------|
|
181 |
+
| Average (30 datasets) | 0.689 | **0.706** |
|
182 |
+
| Classification Average (12 datasets) | 0.571 | **0.594** |
|
183 |
+
| Reranking Average (2 datasets) | **0.698** | 0.688 |
|
184 |
+
| MultilabelClassification (2 datasets) | 0.343 | **0.359** |
|
185 |
+
| STS Average (4 datasets) | 0.735 | **0.753** |
|
186 |
+
| Retrieval Average (6 datasets) | **0.945** | 0.934 |
|
187 |
+
| PairClassification Average (4 datasets) | 0.784 | **0.833** |
|
188 |
+
|
189 |
+
|
190 |
+
## Limitations
|
191 |
+
|
192 |
+
|
193 |
+
We did not thoroughly evaluate the model's ability for sparse and multi-vec encoding.
|
194 |
+
|
195 |
+
|
196 |
+
## Citations
|
197 |
+
|
198 |
+
|
199 |
+
```
|
200 |
+
@misc{deepvk2024user,
|
201 |
+
title={USER: Universal Sentence Encoder for Russian},
|
202 |
+
author={Malashenko, Boris and Zemerov, Anton and Spirin, Egor},
|
203 |
+
url={https://huggingface.co/datasets/deepvk/USER-base},
|
204 |
+
publisher={Hugging Face}
|
205 |
+
year={2024},
|
206 |
+
}
|
207 |
+
```
|