Manuscript Offprint

arXiv:2610.06715

Domain adaptation of Russian ModernBERT for long legal documents

I. Litvak, D. Gvozdetsky, F. Lashkin, V. Kirova, S. Lagutin, V. Volf, T. Maksiyan, A. Kostin, R. Leva, I. Kiselev

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

I. Litvak1^{1}, D. Gvozdetsky2^{2}, F. Lashkin1^{1}, V. Kirova2^{2}, S. Lagutin1^{1}, V. Volf1^{1}, T. Maksiyan1^{1}, A. Kostin3^{3}, R. Leva1^{1}, I. Kiselev4^{4}

1^{1}Independent Researcher

2^{2}National Research Nuclear University MEPhI

3^{3}Moscow Center for Advanced Studies

4^{4}University of Waterloo

Abstract. We investigate whether continued pretraining on Russian legislative documents improves a Russian ModernBERT encoder on legal text. The adapted model, RuModernBERT-ruLaw, was trained on a corpus reported to contain 304,382 legislative documents and 194,425,905 corpus tokens. Corpus token counts are distinguished from positions produced by the model tokenizer. We compare the original and adapted encoders on a fixed external collection of 1,031 court-decision segments. Both models receive the same hidden positions in each of five masking realizations. At maximum input lengths of 512, 2,048, and 8,192 tokens, mean masked-token cross-entropy decreases by 0.10942, 0.07052, and 0.06604 natural-log units, respectively. The reported 95% intervals summarize sensitivity to masking on this fixed collection; they do not quantify uncertainty across document collections. A second evaluation addresses legal-entity extraction. The original and adapted models achieve entity-level F1F_{1} scores of 0.99852 and 0.99820. However, 99.95% of test spans have the same normalized surface form and class in the training split. This evaluation therefore provides limited evidence about transfer to previously unseen forms. The paper explains the masking objective, overlapping windows, averaging rules, and exact entity-boundary scoring using editable diagrams and clearly marked illustrative examples. The comparison supports lower masked-token prediction loss for the studied pair of models and collection. It does not isolate the contribution of distant context or establish practical legal utility.

Keywords: natural language processing; legal text; ModernBERT; domain adaptation; masked language modeling; long context

1. Introduction

In a long legal document, an important condition and a reference to it may be far apart. A model needs to account for words and relationships between document sections to locate relevant passages. Legal language also contains specialized terms and fixed expressions. We continue pretraining a general Russian-language model on legislative texts and evaluate changes in two tasks: predicting hidden tokens and extracting legal spans.

A bidirectional encoder transforms input text into contextual vector representations of its positions using both left and right context. Text is first split into tokens; a rare or complex word may consist of several tokens representing parts of the word. BERT-family encoders remain a practical basis for classification, retrieval, and entity extraction [1]. In masked language modeling, some tokens are hidden. The loss for one hidden token is −ln⁡p-\ln p, where p is the probability assigned by the model to its correct original value.

General pretraining does not guarantee accurate modeling of language in a particular domain. Continued pretraining on an unlabeled domain corpus, commonly called domain-adaptive pretraining, has systematically improved representations in several domains [2]. In the legal domain, LEGAL-BERT compared a general model, continued pretraining, and training from scratch across legal NLP tasks [3]. Most early legal encoders, however, support only short inputs.

This study investigates domain adaptation of RuModernBERT-base to Russian legislation while retaining the standard ModernBERT maximum input length of 8192 tokens. The main evaluation uses a court-decision collection that differs from the training corpus in source and document type. Possible content overlap or paraphrased overlap was not specifically excluded. We therefore describe this evaluation as external, rather than independent.

The study addresses three bounded questions. Does continued pretraining reduce cross-entropy at randomly masked positions in external court-decision fragments? Does the direction of the effect persist at maximum input lengths of 512, 2048, and 8192 tokens? Does the available legal-span extraction task distinguish the original and adapted encoders after exact duplicate texts are removed?

The main result is lower masked-token cross-entropy for the adapted model at every tested length and masking realization. Comparing lengths does not isolate a causal effect of distant context because the prefix composition and evaluated tokens also change. Both models achieved F1>0.998F_{1} > 0.998 in span extraction, but nearly complete coverage of test forms by training forms limits the discriminative value of this experiment. The study evaluates model losses and one entity-extraction test. It does not assess legal expertise or practical labor savings. Figure 1 separates adaptation from the two evaluation branches. External MLM evaluation tests changes in hidden-token probabilities, whereas the span experiment evaluates a separate task after fine-tuning. The result of one branch cannot substitute for that of the other.

Figure

Figure 1: Domain adaptation and two distinct evaluations. Arrows show experimental stages; masked-token prediction quality does not establish practical legal utility.

References (10)