CoolFace
Modelpublic

answerdotai/ModernBERT-Large-Instruct

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
34likes1.7kdownloads
Model Card

ModernBERT-Large-Instruct

Table of Contents

  1. 1.Model Summary
  2. 2.Usage
  3. 3.Evaluation
  4. 4.Limitations
  5. 5.Training
  6. 6.License
  7. 7.Citation

Model Summary

ModernBERT-Instruct-Large is a lightly instruction-tuned version of ModernBERT-large, trained using a mixed-objective (Answer Token Prediction & Dummy MLM) on 20M examples sampled from the FLAN collection.

Despite a very straightforward pre-training and inference pipeline, this model proves to be a very strong model in a variety of contexts, in both zero-shot and fully-finetuned settings.

For more details, we recommend checking out the [TIL Blog Post](), the mini cookbook GitHub repository or the Technical Report.

Usage

In order to use ModernBERT-Large-Instruct, you need to install a version of transformers which natively supports ModernBERT (4.48+):

sh
pip install -U transformers>=4.48.0

⚠️ If your GPU supports it, we recommend using ModernBERT with Flash Attention 2 to reach the highest efficiency. To do so, install Flash Attention as follows, then use the model as normal:

bash
pip install flash-attn

All tasks are then performed using the Model's Masked Language Modelling head, load via AutoModelForMaskedLM. Here is an example to answer an MMLU question:

python
import torch
from transformers import AutoTokenizer, AutoModelForMaskedLM

# Load model and tokenizer
model_name = "answerdotai/ModernBERT-Large-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
device = 'cuda' if torch.cuda.is_available() else 'cpu'
if device == 'cuda':
    model = AutoModelForMaskedLM.from_pretrained(model_name, attn_implementation="flash_attention_2")
else:
    model = AutoModelForMaskedLM.from_pretrained(model_name)

model.to(device)

# Format input for classification or multiple choice. This is a random example from MMLU.
text = """You will be given a question and options. Select the right answer.
QUESTION: If (G, .) is a group such that (ab)^-1 = a^-1b^-1, for all a, b in G, then G is a/an
CHOICES:
- A: commutative semi group
- B: abelian group
- C: non-abelian group
- D: None of these
ANSWER: [unused0] [MASK]"""

# Get prediction
inputs = tokenizer(text, return_tensors="pt").to(device)
outputs = model(**inputs)
mask_idx = (inputs.input_ids == tokenizer.mask_token_id).nonzero()[0, 1]
pred_id = outputs.logits[0, mask_idx].argmax()
answer = tokenizer.decode(pred_id)
print(f"Predicted answer: {answer}")  # Outputs: B

Evaluation

Results are taken from the technical report. Results for MMLU and MMLU-Pro are taken from SmolLM2 (†) and the MMLU-Pro leaderboard (‡) whenever possible.

Zero-Shot

ModelMMLUMMLU-ProADEv2NISOSEAverage
0.3-0.5B
Tasksource-NLI36.0816.5465.1758.7221.1139.52
RoBERTa-Large-SST31.3013.6343.6175.0040.6740.84
UniMC38.4818.8323.2973.9636.8838.29
ModernBERT-Large-Instruct43.0617.1653.3185.5320.6243.94
SmoLM2-360M35.8†11.38‡----
Qwen2-0.5B33.7†15.93‡----
1B+
Llama3.2-1B45.8322.6----
SmoLM2-1.7B48.4418.31‡----
Qwen2.5-1.5B*59.67**32.1‡*----

Fine-Tuned

ModelMNLIYahoo!20ngAGNewsSST-2IMDBSST-5Average
ModernBERT (cls head)90.8†77.7573.9695.3497.1†96.5259.2884.39
ModernBERT-Large-Instruct91.0377.8873.9695.2496.2297.261.1384.67

Limitations

ModernBERT’s training data is primarily English and code, so performance is best on these languages. ModernBERT-Large-Instruct is a first version, demonstrating the strong potential of using the MLM head for downstream tasks without complex pipelines. However, it is very likely to have failure cases and it could be improved further.

License

Apache 2.0

Citation

If you use ModernBERT-Large-Instruct in your work, please cite:

@misc{clavié2025itsmasksimpleinstructiontuning,
      title={It's All in The [MASK]: Simple Instruction-Tuning Enables BERT-like Masked Language Models As Generative Classifiers}, 
      author={Benjamin Clavié and Nathan Cooper and Benjamin Warner},
      year={2025},
      eprint={2502.03793},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2502.03793}, 
}