A vocabulary-truncated version of
jhu-clsp/mmBERT-small, optimized for
English and
Azerbaijani by removing unused tokens from the 1800+ language vocabulary.
mmBERT is a state-of-the-art multilingual encoder built on the ModernBERT architecture with a Gemma 2 tokenizer, trained on 3T+ tokens across 1800+ languages. While powerful, the full model carries a 256K token vocabulary — most of which is unnecessary if you only need English and Azerbaijani.
This model keeps only the ~72K tokens that actually appear in English and Azerbaijani text, reducing the model size by 46% while preserving identical output quality for these two languages.
All transformer layers (110M non-embedding parameters) are completely unchanged. Only the embedding matrix was trimmed.
Cosine similarity between Azerbaijani–English sentence pairs is identical or near-identical to the original model:
Tokenization output is identical for both languages.
1from transformers import AutoTokenizer, AutoModel
2
3tokenizer = AutoTokenizer.from_pretrained("LocalDoc/mmBERT-small-en-az")
4model = AutoModel.from_pretrained("LocalDoc/mmBERT-small-en-az")
5
6inputs = tokenizer("Salam, bu gün necəsiniz?", return_tensors="pt")
7outputs = model(**inputs)
1import torch
2
3def get_embeddings(texts, model, tokenizer):
4 encoded = tokenizer(texts, padding=True, truncation=True, max_length=512, return_tensors="pt")
5 with torch.no_grad():
6 output = model(**encoded)
7 mask = encoded["attention_mask"].unsqueeze(-1).expand(output.last_hidden_state.size()).float()
8 embeddings = torch.sum(output.last_hidden_state * mask, 1) / torch.clamp(mask.sum(1), min=1e-9)
9 embeddings = torch.nn.functional.normalize(embeddings)
10 return embeddings
11
12embeddings = get_embeddings(
13 ["Bakı Azərbaycanın paytaxtıdır", "Baku is the capital of Azerbaijan"],
14 model, tokenizer
15)
16similarity = embeddings[0].dot(embeddings[1])
17print(f"Similarity: {similarity:.4f}")
1@misc{marone2025mmbertmodernmultilingualencoder,
2 title={mmBERT: A Modern Multilingual Encoder with Annealed Language Learning},
3 author={Marc Marone and Orion Weller and William Fleshman and Eugene Yang and Dawn Lawrie and Benjamin Van Durme},
4 year={2025},
5 eprint={2509.06888},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2509.06888},
9}