Views
No views yet
deepvk/deberta-v1-base and trained to work exclusively with the Russian language. Its quality on other languages was not evaluated.sentence-transformers installed:pip install -U sentence-transformers1from sentence_transformers import SentenceTransformer
2
3queries = [
4 "Когда был спущен на воду первый миноносец «Спокойный»?",
5 "Есть ли нефть в Удмуртии?"
6]
7passages = [
8 "Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",
9 "Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."
10]
11
12model = SentenceTransformer("deepvk/USER-base")
13# Prompt should be specified according to the task (either 'query' or 'passage').
14passage_embeddings = model.encode(passages, normalize_embeddings=True, prompt_name='passage')
15# For tasks other than retrieval, you can simply use the `query` prompt, which is set by default.
16query_embeddings = model.encode(queries, normalize_embeddings=True)transformers1import torch.nn.functional as F
2from torch import Tensor, inference_mode
3from transformers import AutoTokenizer, AutoModel
4
5def average_pool(
6 last_hidden_states: Tensor,
7 attention_mask: Tensor
8) -> Tensor:
9 last_hidden = last_hidden_states.masked_fill(
10 ~attention_mask[..., None].bool(), 0.0
11 )
12 return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
13
14# You should manually add prompts when using the model directly. Each input text should start with "query: " or "passage: ".
15# For tasks other than retrieval, you can simply use the "query: " prefix.
16input_texts = [
17 "query: Когда был спущен на воду первый миноносец «Спокойный»?",
18 "query: Есть ли нефть в Удмуртии?",
19 "passage: Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",
20 "passage: Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."
21]
22
23tokenizer = AutoTokenizer.from_pretrained("deepvk/USER-base")
24model = AutoModel.from_pretrained("deepvk/USER-base")
25
26batch_dict = tokenizer(
27 input_texts, padding=True, truncation=True, return_tensors="pt"
28)
29with inference_mode():
30 outputs = model(**batch_dict)
31 embeddings = average_pool(
32 outputs.last_hidden_state, batch_dict["attention_mask"]
33 )
34 embeddings = F.normalize(embeddings, p=2, dim=1)
35
36# Scores for query-passage
37scores = (embeddings[:2] @ embeddings[2:].T) * 100
38# [[55.86, 30.95],
39# [22.82, 59.46]]
40print(scores.round(decimals=2))bge-base-en model training algorithm, but we made several improvements along the way.deepvk/deberta-v1-baseLM-Cocktail:(S1, S2), we used the instructions: "query: S1" and "query: S2", and for asymmetric data, we used "query: S1" with "passage: S2".LM-Cocktail to produce the final model, USER.deepvk/ru-HNP and
deepvk/ru-WANLI.| Symmetric Dataset | Size | Asymmetric Dataset | Size |
|---|---|---|---|
| AllNLI | 282 644 | MIRACL | 10 000 |
| MedNLI | 3 699 | MLDR | 1 864 |
| RCB | 392 | Lenta | 185 972 |
| Terra | 1 359 | Mlsum | 51 112 |
| Tapaco | 91 240 | Mr-TyDi | 536 600 |
| Opus100 | 1 000 000 | Panorama | 11 024 |
| BiblePar | 62 195 | PravoIsrael | 26 364 |
| RudetoxifierDataDetox | 31 407 | Xlsum | 124 486 |
| RuParadetox | 11 090 | Fialka-v1 | 130 000 |
| deepvk/ru-WANLI | 35 455 | RussianKeywords | 16 461 |
| deepvk/ru-HNP | 500 000 | Gazeta | 121 928 |
| Gsm8k-ru | 7 470 | ||
| DSumRu | 27 191 | ||
| SummDialogNews | 75 700 |
AllNLI is an translated to Russian combination of SNLI, MNLI, and ANLI.encodechka leaderboard table. In addition, we evaluate model on the russian subset of MTEB, which include 10 tasks. Unfortunately, we could not validate the bge-m3 on some MTEB tasks, specifically clustering, due to excessive computational resources. Besides these two benchmarks, we also evaluated the models on the MIRACL. All experiments were conducted using NVIDIA TESLA A100 40 GB GPU. We use validation scripts from the official repositories for each of the tasks.| Model | Size (w/o Embeddings) | Encodechka (Mean S) | MTEB (Mean Ru) | Miracl (Recall@100) |
|---|---|---|---|---|
bge-m3 | 303 | 0.786 | 0.694 | 0.959 |
multilingual-e5-large | 303 | 0.78 | 0.665 | 0.927 |
USER (this model) | 85 | 0.772 | 0.666 | 0.763 |
paraphrase-multilingual-mpnet-base-v2 | 85 | 0.76 | 0.625 | 0.149 |
multilingual-e5-base | 85 | 0.756 | 0.645 | 0.915 |
LaBSE-en-ru | 85 | 0.74 | 0.599 | 0.327 |
sn-xlm-roberta-base-snli-mnli-anli-xnli | 85 | 0.74 | 0.593 | 0.08 |
"query: " and "passage: " correspondingly for asymmetric tasks such as passage retrieval in open QA, ad-hoc information retrieval."query: " prefix for symmetric tasks such as semantic similarity, bitext mining, paraphrase retrieval."query: " prefix if you want to use embeddings as features, such as linear probing classification, clustering.@misc{deepvk2024user,
title={USER: Universal Sentence Encoder for Russian},
author={Malashenko, Boris and Zemerov, Anton and Spirin, Egor},
url={https://huggingface.co/datasets/deepvk/USER-base},
publisher={Hugging Face}
year={2024},
}