File size: 14,713 Bytes
7b6c98b 1185224 7b6c98b 1185224 7b6c98b |
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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
---
language:
- tr
- en
license: apache-2.0
tags:
- fill-mask
- turkish
- legal
- turkish-legal
- mecellem
- modernbert
- TRUBA
- MN5
base_model: ModernBERT-large
pipeline_tag: fill-mask
---
# Mursit-Large
[](https://github.com/newmindai/mecellem-models) [](https://huggingface.co/spaces/newmindai/Mizan) [](https://opensource.org/licenses/Apache-2.0)
## Model Description
Mursit-Large is a large-scale Turkish Masked Language Model pre-trained entirely from scratch on Turkish-dominant corpora. The model is based on ModernBERT-large architecture (403M parameters) and serves as a foundation model for downstream tasks. Unlike domain-adaptive approaches that continue training from existing checkpoints, this model is initialized randomly and trained on a carefully curated dataset combining Turkish legal text with general web data.
**Key Features:**
- Pre-trained from scratch on approximately 112.7 billion tokens of Turkish-dominant corpus
- Achieves 60.76% MLM accuracy on Turkish datasets (80-10-10 masking strategy, evaluated at 15% masking rate)
- Serves as foundation for downstream embedding tasks (Mursit-Large-TR-Retrieval)
- Custom tokenizer optimized for Turkish morphological structure
- Pre-trained with 30% masking rate (ModernBERT/RoBERTa approach) but evaluated at 15% masking rate for fair comparison
**Model Type:** Masked Language Model (MLM)
**Parameters:** 403M
**Base Architecture:** ModernBERT-large
**Hidden Size:** 1,024
**Max Sequence Length:** 2,048 tokens
### Architecture Details
- **Layers:** 28 transformer layers
- **Hidden Size:** 1,024
- **FFN Size:** 2,624
- **Attention Heads:** 16 heads with 64 dimensions each
- **Activation:** GeGLU (Gated Linear Units with GELU)
- **Normalization:** RMSNorm
- **Position Embeddings:** Rotary positional embeddings (RoPE) with θ=20,000
- **Window Size:** 128
- **Vocabulary Size:** 59,008 tokens
### Training Details
**Pre-training:**
- **Dataset:** Turkish-dominant corpus totaling approximately 112.7 billion tokens
- **Legal Sources:**
- Court of Cassation (Yargıtay): 10.3M sequences, ~3.43B tokens
- Council of State (Danıştay): 151K sequences, ~0.11B tokens
- Academic theses (YÖKTEZ): 21.1M sequences, ~9.61B tokens (after DocsOCR processing)
- **General Turkish Sources:**
- FineWeb2: General Turkish web data
- CulturaX: Multilingual corpus (Turkish subset)
- Total general Turkish: 212M sequences, ~96.17B tokens
- **Data Processing:** SemHash-based semantic deduplication, FineWeb quality filtering, URL-based filtering, page-packing for YÖKTEZ documents
- **Training Method:** Masked Language Modeling (MLM) with 15% masking probability
- **Masking Strategy:** 80% [MASK], 10% random token, 10% unchanged (80-10-10 strategy)
- **Framework:** MosaicML Composer with Decoupled StableAdamW optimizer
- **Learning Rate:** 8×10⁻⁴ with warmup_stable_decay schedule
- **Precision:** BF16 mixed precision
- **Hardware:** MareNostrum 5 supercomputer (BSC), 128×H100 GPUs
**MLM Accuracy:** 67.25% (evaluated on Turkish datasets: blackerx/turkish_v2, fthbrmnby/turkish_product_reviews, hazal/Turkish-Biomedical-corpus-trM, newmindai/EuroHPC-Legal)
### MLM Accuracy Scores (80-10-10 Strategy) on Turkish Datasets
The following table presents MLM accuracy scores (averaged across the 80-10-10 strategy) for our pre-trained models and baseline MLM models evaluated on Turkish datasets. *This model's results are highlighted in italics.*
| Model | MLM Avg (%) |
|-------|-------------|
| boun-tabilab/TabiBERT | **69.57** |
| *newmindai/Mursit-Large* | *67.25* |
| ytu-ce-cosmos/turkish-large-bert-cased | 65.03 |
| dbmdz/bert-base-turkish-cased | 64.98 |
| newmindai/Mursit-Base | 64.05 |
| KocLab-Bilkent/BERTurk-Legal | 54.10 |
| ytu-ce-cosmos/turkish-base-bert-uncased | 52.69 |
*MLM accuracy averaged across the 80-10-10 masking strategy. turkish-base-bert-uncased was evaluated only on uncased datasets. Evaluation datasets: blackerx/turkish_v2, fthbrmnby/turkish_product_reviews, hazal/Turkish-Biomedical-corpus-trM, newmindai/EuroHPC-Legal. All experiments are reproducible (see Section A.2 in the paper).*
## Performance on MTEB-Turkish Benchmark
The following visualization shows the model's performance compared to other Turkish language models:

*Model Performance Comparison: Legal Score vs. MTEB Score. MLM models (blue circles) form a distinct cluster. Mursit-Large achieves competitive performance among Turkish MLM models.*
This model was evaluated on the comprehensive MTEB-Turkish benchmark for embedding tasks using mean pooling over token representations followed by L2 normalization.
### Comprehensive Benchmark Results
The following table presents comprehensive evaluation results across all models evaluated on the MTEB-Turkish benchmark. *This model's results are highlighted in italics.*
| Model | MTEB | Legal | Cls. | Clus. | Pair | Ret. | STS | Cont. | Reg. | Case | Params | Type |
|-------|------|-------|------|-------|------|------|-----|-------|------|------|--------|------|
| embeddinggemma-300m | **65.42** | 50.63 | **77.74** | **45.05** | **80.02** | **55.06** | 69.22 | 83.97 | **39.56** | 28.38 | 307M | Emb. |
| bge-m3 | 62.87 | **51.16** | 75.35 | 35.86 | 78.88 | 54.42 | **69.83** | **86.08** | 38.09 | **29.3** | 567M | Emb. |
| Mursit-Embed-Qwen3-1.7B-TR | 56.84 | 34.76 | 68.46 | 42.22 | 59.67 | 50.1 | 63.77 | 70.22 | 17.94 | 16.11 | 1.7B | CLM-E. |
| Mursit-Large-TR-Retrieval | 56.87 | 46.56 | 67.72 | 41.15 | 59.78 | 51.69 | 64.01 | 81.78 | 32.67 | 25.24 | 403M | Emb. |
| Mursit-Base-TR-Retrieval | 55.86 | 47.52 | 66.25 | 39.75 | 61.31 | 50.07 | 61.9 | 80.4 | 34.1 | 28.07 | 155M | Emb. |
| Mursit-Embed-Qwen3-4B-TR | 53.65 | 37.0 | 67.29 | 36.68 | 58.36 | 51.12 | 54.77 | 69.25 | 24.21 | 17.56 | 4B | CLM-E. |
|-------|------|-------|------|------|------|------|-----|-------|------|------|--------|------|
| bert-base-turkish-uncased | 46.23 | 24.94 | 68.05 | 33.81 | 60.44 | 32.01 | 36.85 | 52.47 | 12.05 | 10.29 | 110M | MLM |
| turkish-large-bert-cased | 45.3 | 19.12 | 67.43 | 34.24 | 60.11 | 28.68 | 36.04 | 47.57 | 5.93 | 3.85 | 337M | MLM |
| bert-base-turkish-cased | 45.17 | 24.41 | 66.39 | 35.28 | 60.05 | 30.52 | 33.62 | 54.03 | 10.13 | 9.07 | 110M | MLM |
| BERTurk-Legal | 42.02 | 32.63 | 60.61 | 26.24 | 59.51 | 25.8 | 37.94 | 61.4 | 15.51 | 20.99 | 184M | MLM |
| *Mursit-Large* | 41.75 | 23.71 | 62.95 | 25.34 | 58.04 | 27.4 | 35.01 | 42.74 | 11.29 | 17.1 | 403M | MLM |
| turkish-base-bert-uncased | 44.68 | 27.58 | 66.22 | 30.23 | 58.84 | 31.4 | 36.74 | 56.6 | 13.39 | 12.74 | 110M | MLM |
| Mursit-Base | 40.23 | 17.93 | 59.78 | 25.48 | 58.65 | 20.82 | 36.45 | 36.0 | 7.4 | 10.4 | 155M | MLM |
| mmBERT-base | 39.65 | 12.15 | 61.84 | 26.77 | 59.25 | 15.83 | 34.56 | 34.45 | 1.33 | 0.68 | 306M | MLM |
| TabiBERT | 37.77 | 11.5 | 59.63 | 25.75 | 58.19 | 14.96 | 30.32 | 32.02 | 1.86 | 0.63 | 148M | MLM |
| ModernBERT-base | 23.8 | 2.99 | 39.06 | 2.01 | 53.95 | 2.1 | 21.91 | 7.92 | 0.62 | 0.43 | 149M | MLM |
| ModernBERT-large | 23.74 | 2.44 | 39.44 | 3.9 | 53.73 | 1.8 | 19.85 | 6.12 | 0.62 | 0.59 | 394M | MLM |
**Column abbreviations:** MTEB = mean performance across task types; Legal = weighted average of Contracts, Regulation, Caselaw; Classification = accuracy on Turkish classification tasks; Clustering = V-measure on clustering tasks; Pair Classification = average precision on pair classification tasks like NLI; Retrieval = nDCG@10 on information retrieval tasks; Semantic Textual Similarity = Spearman correlation; Contracts = nDCG@10 on legal contract retrieval; Regulation = nDCG@10 on regulatory text retrieval; Caselaw = nDCG@10 on case law retrieval; Number of Parameters = number of model parameters; Model Type = model type (Embedding, CLM-Embedding, Masked Language Model). **Bold values** indicate the highest score in each column.
**Key Findings:**
- The model shows substantial improvement over ModernBERT baselines (which are monolingual English models), validating the effectiveness of Turkish-specific pre-training
- Pre-training alone without embedding-specific fine-tuning yields limited utility for retrieval tasks
- Language-specific pre-training is critical, as monolingual English models show limited cross-lingual transfer to Turkish
- The model demonstrates that improvements in MLM accuracy do not always directly translate to better downstream task performance
### MLM vs Downstream Performance Analysis
The following visualization shows the relationship between MLM validation loss and downstream retrieval performance:

*Relationship between MLM validation loss and downstream retrieval performance across ModernBERT-large versions. This analysis demonstrates how improvements in MLM accuracy correlate with downstream task performance.*
**Note:** This model is primarily designed for Masked Language Modeling tasks. Embedding performance is provided for reference using standard mean pooling. For optimal retrieval performance, consider using the post-trained retrieval variants (Mursit-Base-TR-Retrieval or Mursit-Large-TR-Retrieval).
## Reproducibility
To reproduce the MLM benchmark results for this model, please refer to:
- **MLM Benchmark Results:** [github.com/newmindai/mecellem-models/benchmark/mlm](https://github.com/newmindai/mecellem-models/tree/main/benchmark/mlm) - Contains code and evaluation configurations for reproducing MLM accuracy scores on Turkish datasets using the 80-10-10 masking strategy.
## Usage
### Installation
```bash
pip install transformers torch
```
### Masked Language Modeling
```python
from transformers import AutoTokenizer, AutoModelForMaskedLM
import torch
tokenizer = AutoTokenizer.from_pretrained("newmindai/Mursit-Large")
model = AutoModelForMaskedLM.from_pretrained("newmindai/Mursit-Large")
text = "Türkiye Cumhuriyeti'nin başkenti [MASK]'dir."
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
mask_token_index = (inputs["input_ids"] == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
predictions = torch.nn.functional.softmax(outputs.logits[0, mask_token_index], dim=-1)
top_k = 5
top_indices = torch.topk(predictions[0], top_k).indices
for idx in top_indices:
token = tokenizer.decode([idx])
score = predictions[0][idx].item()
print(f"{token}: {score:.4f}")
```
# ONNX Model Inference - Masked Language Modeling (MLM)
This script demonstrates how to use the ONNX model from Hugging Face for masked language modeling tasks.
## Exporting Model to ONNX
To export the model to ONNX format for MLM, use the `optimum-cli` command:
```bash
optimum-cli export onnx \
-m newmindai/Mursit-Large \
--task fill-mask \
onnx/MursitLarge
```
This will create the `model.onnx` file in the specified output directory.
## Installation
```bash
pip install onnxruntime-gpu transformers huggingface_hub numpy
```
## Usage
```python
import numpy as np
import onnxruntime as ort
from transformers import AutoTokenizer
from huggingface_hub import hf_hub_download
repo_id = "newmindai/Mursit-Large"
onnx_path = hf_hub_download(repo_id, "model.onnx")
tokenizer = AutoTokenizer.from_pretrained(repo_id)
sess = ort.InferenceSession(
onnx_path,
providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
)
text = f"Bu bir {tokenizer.mask_token} cümledir."
inputs = tokenizer(text, return_tensors="np")
outputs = sess.run(None, dict(inputs))
logits = outputs[0]
mask_pos = np.where(inputs["input_ids"][0] == tokenizer.mask_token_id)[0][0]
mask_logits = logits[0, mask_pos]
top_k = 5
top_k_ids = np.argsort(mask_logits)[-top_k:][::-1]
predictions = tokenizer.convert_ids_to_tokens(top_k_ids)
print("MASK predictions:")
for p in predictions:
print(p)
```
## Features
- **Automatic GPU/CPU selection**: Uses CUDA if available, otherwise falls back to CPU
- **Hugging Face integration**: Downloads model files directly from Hugging Face Hub
- **Masked token prediction**: Predicts the most likely tokens for masked positions
- **Top-K predictions**: Returns the top K most probable token predictions
## Use Cases
- Turkish language understanding tasks
- Text classification
- Named entity recognition
- Question answering
- Feature extraction for downstream tasks
## Reproducibility
To reproduce the MLM benchmark results for this model, please refer to:
- **MLM Benchmark Results:** [github.com/newmindai/mecellem-models/benchmark/mlm](https://github.com/newmindai/mecellem-models/tree/main/benchmark/mlm) - Contains code and evaluation configurations for reproducing MLM accuracy scores on Turkish datasets using the 80-10-10 masking strategy.
## Acknowledgments
This work was supported by the EuroHPC Joint Undertaking through project etur46 with access to the MareNostrum 5 supercomputer, hosted by Barcelona Supercomputing Center (BSC), Spain. MareNostrum 5 is owned by EuroHPC JU and operated by BSC. We are grateful to the BSC support team for their assistance with job scheduling, environment configuration, and technical guidance throughout the project.
The numerical calculations reported in this work were fully/partially performed at TÜBİTAK ULAKBİM, High Performance and Grid Computing Center (TRUBA resources). The authors gratefully acknowledge the know-how provided by the MINERVA Support for expert guidance and collaboration opportunities in HPC-AI integration.
## References
If you use this model, please cite our paper:
```bibtex
@article{mecellem2026,
title={Mecellem Models: Turkish Models Trained from Scratch and Continually Pre-trained for the Legal Domain},
author={Uğur, Özgür and Göksu, Mahmut and Çimen, Mahmut and Yılmaz, Musa and Şavirdi, Esra and Demir, Alp Talha and Güllüce, Rumeysa and Çetin, İclal and Sağbaş, Ömer Can},
journal={arXiv preprint arXiv:2601.16018},
year={2026},
month={January},
url={https://arxiv.org/abs/2601.16018},
doi={10.48550/arXiv.2601.16018},
eprint={2601.16018},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
```
### Base Model References
```bibtex
@inproceedings{modernbert2025,
title={ModernBERT: A Modern Bidirectional Encoder Transformer},
author={Answer.AI and LightOn},
booktitle={Proceedings of the 2025 Conference on Language Models},
year={2025}
}
```
<!-- Updated: 2026-01-15 09:38:24 -->
|