Universal Sentence Encoder for Russian (USER) is a sentence-transformer model for extracting embeddings exclusively for Russian language.
It maps sentences & paragraphs to a 1024 dimensional dense vector space and can be used for tasks like clustering or semantic search.
This model is initialized from TatonkaHF/bge-m3_en_ru which is shrinked version of baai/bge-m3 model and trained to work mainly with the Russian language. Its quality on other languages was not evaluated.
1from sentence_transformers import SentenceTransformer
234input_texts =[5"Когда был спущен на воду первый миноносец «Спокойный»?",6"Есть ли нефть в Удмуртии?",7"Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",8"Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."9]101112model = SentenceTransformer("deepvk/USER-bge-m3")13embeddings = model.encode(input_texts, normalize_embeddings=True)
However, you can use model directly with transformers
python
1import torch.nn.functional as F
2from torch import Tensor, inference_mode
3from transformers import AutoTokenizer, AutoModel
456input_texts =[7"Когда был спущен на воду первый миноносец «Спокойный»?",8"Есть ли нефть в Удмуртии?",9"Спокойный (эсминец)\nЗачислен в списки ВМФ СССР 19 августа 1952 года.",10"Нефтепоисковые работы в Удмуртии были начаты сразу после Второй мировой войны в 1945 году и продолжаются по сей день. Добыча нефти началась в 1967 году."11]121314tokenizer = AutoTokenizer.from_pretrained("deepvk/USER-bge-m3")15model = AutoModel.from_pretrained("deepvk/USER-bge-m3")16model.eval()171819encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')20with torch.no_grad():21 model_output = model(**encoded_input)22# Perform pooling. In this case, cls pooling.23 sentence_embeddings = model_output[0][:,0]2425# normalize embeddings26sentence_embeddings = torch.nn.functional.normalize(sentence_embeddings, p=2, dim=1)2728# [[0.5567, 0.3014],29# [0.1701, 0.7122]]30scores =(sentence_embeddings[:2] @ sentence_embeddings[2:].T)
Fine-tuning: Supervised fine-tuning two different models based on data symmetry and then merging via LM-Cocktail:
Since we split the data, we could additionally apply the AnglE loss to the symmetric model, which enhances performance on symmetric tasks.
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.
Total positive pairs: 2,240,961
Total negative pairs: 792,644 (negative pairs from AIINLI, MIRACL, deepvk/ru-WANLI, deepvk/ru-HNP)
For all labeled datasets, we only use its training set for fine-tuning.
For datasets Gazeta, Mlsum, Xlsum: pairs (title/text) and (title/summary) are combined and used as asymmetric data.
AllNLI is an translated to Russian combination of SNLI, MNLI and ANLI.
Experiments
We compare our mode with the basic baai/bge-m3 on the encodechka benchmark.
In addition, we evaluate model on the russian subset of MTEB on Classification, Reranking, Multilabel Classification, STS, Retrieval, and PairClassification tasks.
We use validation scripts from the official repositories for each of the tasks.
We did not thoroughly evaluate the model's ability for sparse and multi-vec encoding.
Citations
@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},
}