File size: 5,435 Bytes
56a3fe1
 
5f85187
 
 
d3a019b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
license: apache-2.0
language:
- en
- ru
library_name: transformers
pipeline_tag: feature-extraction
tags:
- modernbert
- encoder
---

# RuModernBertSmall

**RuModernBertSmall** is a compact Russian–English ModernBERT encoder from MTS AI. It was pretrained from scratch and distilled from the MTS AI Base model in its final training stage.

## Intended use

Use the encoder as a backbone for supervised text classification, token classification, or ranking. It also exposes contextual token representations for frozen-feature experiments and as a starting point for training a retrieval model. The release contains encoder weights. Applications that require label predictions or masked-token prediction need a corresponding trained head.

## Model details

| Property | Value |
| --- | ---: |
| Architecture | `ModernBertModel` |
| Encoder parameters | 34,409,920 |
| Transformer layers | 21 |
| Hidden size | 320 |
| Intermediate size | 480 |
| Attention heads | 8 |
| Vocabulary size | 50,368 tokens |
| Configured maximum sequence length | 8,192 tokens |
| Weight format | FP32 Safetensors |

## Quick start

Install PyTorch and Transformers. The checkpoint configuration was exported with Transformers 5.24.1.

```python
import torch
from transformers import AutoModel, AutoTokenizer

model_id = "MTSAIR/RuModernBertSmall"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModel.from_pretrained(model_id).eval()

texts = ["Как изменить тариф?", "Как перейти на другой тарифный план?"]
inputs = tokenizer(texts, padding=True, truncation=True, return_tensors="pt")

with torch.inference_mode():
    token_embeddings = model(**inputs).last_hidden_state

# Mean pooling over non-padding tokens as a simple starting point.
mask = inputs["attention_mask"].unsqueeze(-1).to(token_embeddings.dtype)
text_embeddings = (token_embeddings * mask).sum(dim=1) / mask.sum(dim=1).clamp_min(1)
```

## Training

We trained Small from scratch with masked language modeling (MLM) on approximately 128B tokens from Russian FineWeb-2. In the final 12B-token stage, we trained with MLM and a KL distillation loss from the Base model with a coefficient of 0.5. The final data mix added English FineWeb, Russian and English Wikipedia, and code. We increased the training sequence length from 1,024 to 2,048 tokens and reduced the masking rate from 30% to 15% in that stage.

The tokenizer uses a 50,368-token BPE vocabulary. Its training sample contained about 10M documents, with an 80/10/10 mix of Russian FineWeb-2, English FineWeb, and code. Text preprocessing follows [ruRoberta](https://huggingface.co/ai-forever/ruRoberta-large). The distillation teacher was the [RuModernBertBase](https://huggingface.co/MTSAIR/RuModernBertBase) line.

## Evaluation

| MTS AI checkpoint | RussianSuperGLUE accuracy | Encodechka score |
| --- | ---: | ---: |
| **RuModernBertSmall** | 66.61% | 60.8 |
| [RuModernBertSmallTripleMerge](https://huggingface.co/MTSAIR/RuModernBertSmallTripleMerge) | 67.07% | 60.4 |
| [RuModernBertBase](https://huggingface.co/MTSAIR/RuModernBertBase) | 71.29% | 64.2 |
| [RuModernBertBaseTripleMerge](https://huggingface.co/MTSAIR/RuModernBertBaseTripleMerge) | 72.40% | 65.7 |

Within the Small pair, the original checkpoint scored higher on frozen representations (60.8 vs. 60.4). Its Triple-Merge counterpart averaged 0.46 percentage points higher after RussianSuperGLUE fine-tuning.

### RussianSuperGLUE

We fine-tuned the encoder and a task-specific head on each of seven [RussianSuperGLUE](https://russiansuperglue.com/tasks/) tasks. We selected hyperparameters from 27 combinations using five seeds per combination, then ran the selected configuration on ten fresh seeds. The table shows validation accuracy in percent, with standard deviation across those ten seeds. The aggregate weights all seven tasks equally.

| Task | Validation accuracy (%) |
| --- | ---: |
| RCB | 54.05 ± 1.06 |
| PARus | 55.90 ± 1.45 |
| MuSeRC | 75.86 ± 0.56 |
| TERRa | 63.36 ± 1.59 |
| RUSSE | 92.79 ± 0.59 |
| RWSD | 56.27 ± 0.69 |
| DaNetQA | 68.04 ± 2.40 |
| Mean | 66.61% |

### Encodechka

For [Encodechka](https://github.com/avidale/encodechka), we froze the encoder and evaluated its representations directly or with a lightweight classifier, depending on the task. Scores use each task's own metric, scaled by 100. The aggregate weights all ten tasks equally.

| Task | Score (0–100 scale) |
| --- | ---: |
| STS-B | 68.3 |
| Paraphraser | 57.1 |
| XNLI | 33.1 |
| Sentiment | 75.2 |
| Toxicity | 94.3 |
| Inappropr. | 75.5 |
| Intents | 74.7 |
| IntentsX | 48.2 |
| FactRu | 43.7 |
| RuDReC | 38.4 |
| Mean | 60.8 |

## Limitations

- We report evaluation results on Russian benchmarks. Training also included English data.
- The original Small model's final distillation stage used sequences of up to 2,048 tokens. The model and tokenizer configuration allow up to 8,192 tokens. Quality at the configured maximum sequence length remains to be evaluated.
- For retrieval, validate pooling and ranking quality on your own data. The mean pooling example demonstrates feature extraction.
- A data audit found three English STS-B validation pairs, with similarity labels, in the post-training corpus. Encodechka contains their Russian translations. The table reports the full 10-task aggregate.

## References

- [ModernBERT paper](https://arxiv.org/abs/2412.13663)