Saltar al contenido
ModelVerificadoExterno
Descargar

ModernBERT Base

Model Summary Usage Evaluation Limitations Training License Citation

TipoEmbeddingModelo baseRoBERTaVersiónRevision 8949b90Publicador@answerdotaiBcalidad

Fuente del modelo

Tipo
Embedding, Text model
Tamaño del archivo
134–571 MB
Modelo base
RoBERTa
Versión
vRevision 8949b90
Actualizado
1 oct 2026
Publicador
@answerdotai
Descargas
4,3 M
Fuente
Hugging Face

Descripción de la fuente

ModernBERT

Table of Contents

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

Model Summary

ModernBERT is a modernized bidirectional encoder-only Transformer model (BERT-style) pre-trained on 2 trillion tokens of English and code data with a native context length of up to 8,192 tokens. ModernBERT leverages recent architectural improvements such as:

  • Rotary Positional Embeddings (RoPE) for long-context support.
  • Local-Global Alternating Attention for efficiency on long inputs.
  • Unpadding and Flash Attention for efficient inference.

ModernBERT’s native long context length makes it ideal for tasks that require processing long documents, such as retrieval, classification, and semantic search within large corpora. The model was trained on a large corpus of text and code, making it suitable for a wide range of downstream tasks, including code retrieval and hybrid (text + code) semantic search.

It is available in the following sizes:

For more information about ModernBERT, we recommend our release blog post for a high-level overview, and our arXiv pre-print for in-depth information.

ModernBERT is a collaboration between Answer.AI, LightOn, and friends.

Usage

You can use these models directly with the transformers library starting from v4.48.0:

pip install -U transformers>=4.48.0

Since ModernBERT is a Masked Language Model (MLM), you can use the fill-mask pipeline or load it via AutoModelForMaskedLM. To use ModernBERT for downstream tasks like classification, retrieval, or QA, fine-tune it following standard BERT fine-tuning recipes.

⚠️ 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:

pip install flash-attn

Using AutoModelForMaskedLM:

from transformers import AutoTokenizer, AutoModelForMaskedLM

model_id = "answerdotai/ModernBERT-base"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForMaskedLM.from_pretrained(model_id)

text = "The capital of France is [MASK]."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)

# To get predictions for the mask:
masked_index = inputs["input_ids"][0].tolist().index(tokenizer.mask_token_id)
predicted_token_id = outputs.logits[0, masked_index].argmax(axis=-1)
predicted_token = tokenizer.decode(predicted_token_id)
print("Predicted token:", predicted_token)
# Predicted token:  Paris

Using a pipeline:

import torch
from transformers import pipeline
from pprint import pprint

pipe = pipeline(
    "fill-mask",
    model="answerdotai/ModernBERT-base",
    torch_dtype=torch.bfloat16,
)

input_text = "He walked to the [MASK]."
results = pipe(input_text)
pprint(results)

Note: ModernBERT does not use token type IDs, unlike some earlier BERT models. Most downstream usage is identical to standard BERT models on the Hugging Face Hub, except you can omit the token_type_ids parameter.

Evaluation

We evaluate ModernBERT across a range of tasks, including natural language understanding (GLUE), general retrieval (BEIR), long-context retrieval (MLDR), and code retrieval (CodeSearchNet and StackQA).

Key highlights:

  • On GLUE, ModernBERT-base surpasses other similarly-sized encoder models, and ModernBERT-large is second only to Deberta-v3-large.
  • For general retrieval tasks, ModernBERT performs well on BEIR in both single-vector (DPR-style) and multi-vector (ColBERT-style) settings.
  • Thanks to the inclusion of code data in its training mixture, ModernBERT as a backbone also achieves new state-of-the-art code retrieval results on CodeSearchNet and StackQA.

Base Models

ModelIR (DPR)IR (DPR)IR (DPR)IR (ColBERT)IR (ColBERT)NLUCodeCode
BEIRMLDR_OODMLDR_IDBEIRMLDR_OODGLUECSNSQA
BERT38.923.932.249.028.184.741.259.5
RoBERTa37.722.932.848.728.286.444.359.6
DeBERTaV320.25.413.447.121.988.117.518.6
NomicBERT41.026.730.349.961.384.041.661.4
GTE-en-MLM41.434.344.448.269.385.644.971.4
ModernBERT41.627.444.051.380.288.456.473.6

Large Models

ModelIR (DPR)IR (DPR)IR (DPR)IR (ColBERT)IR (ColBERT)NLUCodeCode
BEIRMLDR_OODMLDR_IDBEIRMLDR_OODGLUECSNSQA
BERT38.923.331.749.528.585.241.660.8
RoBERTa41.422.636.149.828.888.947.368.1
DeBERTaV325.67.119.246.723.091.421.219.7
GTE-en-MLM42.536.448.950.771.387.640.566.9
ModernBERT44.034.348.652.480.490.459.583.9

Table 1: Results for all models across an overview of all tasks. CSN refers to CodeSearchNet and SQA to StackQA. MLDRID refers to in-domain (fine-tuned on the training set) evaluation, and MLDR_OOD to out-of-domain.

ModernBERT’s strong results, coupled with its efficient runtime on long-context inputs, demonstrate that encoder-only models can be significantly improved through modern architectural choices and extensive pretraining on diversified data sources.

Limitations

ModernBERT’s training data is primarily English and code, so performance may be lower for other languages. While it can handle long sequences efficiently, using the full 8,192 tokens window may be slower than short-context inference. Like any large language model, ModernBERT may produce representations that reflect biases present in its training data. Verify critical or sensitive outputs before relying on them.

Training

  • Architecture: Encoder-only, Pre-Norm Transformer with GeGLU activations.
  • Sequence Length: Pre-trained up to 1,024 tokens, then extended to 8,192 tokens.
  • Data: 2 trillion tokens of English text and code.
  • Optimizer: StableAdamW with trapezoidal LR scheduling and 1-sqrt decay.
  • Hardware: Trained on 8x H100 GPUs.

See the paper for more details.

License

We release the ModernBERT model architectures, model weights, training codebase under the Apache 2.0 license.

Citation

If you use ModernBERT in your work, please cite:

@misc{modernbert,
      title={Smarter, Better, Faster, Longer: A Modern Bidirectional Encoder for Fast, Memory Efficient, and Long Context Finetuning and Inference}, 
      author={Benjamin Warner and Antoine Chaffin and Benjamin Clavié and Orion Weller and Oskar Hallström and Said Taghadouini and Alexis Gallagher and Raja Biswas and Faisal Ladhak and Tom Aarsen and Nathan Cooper and Griffin Adams and Jeremy Howard and Iacopo Poli},
      year={2024},
      eprint={2412.13663},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2412.13663}, 
}

Fuentes

1 fuente
Hugging FacePrincipalVersión 8949b909ec900327062f0ebf497f51aef5e6f0c8
huggingface.co/answerdotai/ModernBERT-base/tree/8949b909ec900327062f0ebf497f51aef5e6f0c8

Verificado 1 oct

Artefactos del modelo

10 artefactos

model.safetensors

safetensors · 571 MB · SHA-256 340ac08b74ee…23a9 · Hugging Face

Descargar

onnx/model_bnb4.onnx

onnx · 208 MB · SHA-256 7814510559de…71a4 · Hugging Face

Descargar

onnx/model_fp16.onnx

onnx · 286 MB · SHA-256 d9e191270aaf…de32 · Hugging Face

Descargar

onnx/model_int8.onnx

onnx · 144 MB · SHA-256 fba16e64c4df…9dac · Hugging Face

Descargar

onnx/model_q4.onnx

onnx · 214 MB · SHA-256 21d1de44c781…682e · Hugging Face

Descargar

onnx/model_q4f16.onnx

onnx · 134 MB · SHA-256 97c0b382317d…c0b7 · Hugging Face

Descargar

onnx/model_quantized.onnx

onnx · 144 MB · SHA-256 fba16e64c4df…9dac · Hugging Face

Descargar

onnx/model_uint8.onnx

onnx · 144 MB · SHA-256 755b789bfd7b…13d1 · Hugging Face

Descargar

onnx/model.onnx

onnx · 571 MB · SHA-256 0f6e8bf251fb…b674 · Hugging Face

Descargar

pytorch_model.bin

bin · 571 MB · SHA-256 9a3b4d34f236…f412 · Hugging Face

Descargar

Extractos de fuentes

3 extractos

--- library_name: transformers license: apache-2.0 language: - en tags: - fill-mask - masked-lm - long-context - modernbert pipeline_tag: fill-mask inference: false --- # ModernBERT ## Table of Contents 1. [Model Summary](#model-summary) 2. [Usage](#Usage) 3. [Evaluation](#Evaluation) 4. [Limitations](#limitations) 5. [Training](#training) 6. [License](#license) 7. [Citation](#citation) ## Model Summary ModernBERT is a modernized bidirectional encoder-only Transformer model (BERT-style) pre-trained on 2 trillion tokens of English and code data with a native context length of up to 8,192 tokens. ModernBERT leverages recent architectural improvements such as: - **Rotary Positional Embeddings (RoPE)** for long-context support. - **Local-Global Alternating Attention** for efficiency on long inputs. - **Unpadding and Flash Attention** for efficient inference. ModernBERT’s native long context length makes it ideal for tasks that require processing long documents, such as retrieval, classification, and semantic search within large corpora. The model was trained on a large corpus of text and code, making it suitable for a wide range of downstream tasks, including code retrieval and hybrid (text + code) semantic search. It is available in the following sizes: - [ModernBERT-base](https://huggingface.co/answerdotai/ModernBERT-base) - 22 layers, 149 million parameters - [ModernBERT-large](https://huggingface.co/answerdotai/ModernBERT-large) - 28 layers, 395 million parameters For more information about ModernBERT, we recommend our [release blog post](https://huggingface.co/blog/modernbert) for a high-level overview, and our [arXiv pre-print](https://arxiv.org/abs/2412.13663) for in-depth information. *ModernBERT is a collaboration between [Answer.AI](https://answer.ai), [LightOn](https://lighton.ai), and friends.* ## Usage You can use these models directly with the `transformers` library starting from v4.48.0: ```sh pip install -U transformers>=4.48.0 ``` Since ModernBERT is a Masked Language Model (MLM), you can use the `fill-mask` pipeline or load it via `AutoModelForMaskedLM`. To use ModernBERT for downstream tasks like classification, retrieval, or QA, fine-tune it following standard BERT fine-tuning recipes. **⚠️ If your GPU supports it, we recommend using ModernBERT with Flash Attention 2 to reach the highest efficiency. To do so, install Flash A...

Source context: 4291907 downloads · 1115 likes · Pipeline fill-mask · Library transformers · Repo answerdotai/ModernBERT-base

Source context: 8125193 downloads · 1073 likes · Pipeline fill-mask · Library transformers · Repo answerdotai/ModernBERT-base