Explainer

ModernBERT: a modern encoder for fast classification

ModernBERT is a free, open AI model, released in December 2024 by Answer.AI and LightOn, that reads English text quickly and understands it well. It is an updated version of BERT, a model long used for sorting and searching text. Laya's English version is built on top of the larger ModernBERT.

6 min readLast updated

Swiss-hosted inference. Nothing you send is ever stored.Swiss data residency

In 30 seconds

  • ModernBERT is an open (Apache-2.0) text-reading model from Answer.AI and LightOn, released in December 2024.
  • It updates the classic BERT recipe with newer techniques, longer inputs (up to 8,192 tokens) and efficient inference.
  • It comes in two sizes: base (149M parameters) and large (395M parameters).
  • It is mainly English and code; for other languages, Laya switches to mmBERT.
  • Laya adds a decision head to ModernBERT-large, for 421M parameters in total.

Code and dense tables are folded away. Open any of them on demand.

What is ModernBERT?

ModernBERT is an encoder-only transformer released in December 2024 by Answer.AI and LightOn. It brings recent architecture improvements to the BERT design, was trained on 2 trillion tokens of English text and code, reads up to 8,192 tokens natively, and comes in base (149M) and large (395M) sizes under the Apache-2.0 licence.

BERT (Devlin et al., 2018) made encoder-only transformers the default for classification, retrieval and tagging. For years the architecture barely changed while decoder-only LLMs picked up a long list of improvements. ModernBERT, described in Warner et al. (2024), "Smarter, Better, Faster, Longer", applies those improvements back to an encoder.

The authors describe it as a Pareto improvement over older encoders: better downstream quality at the same or lower inference cost. It was trained on 2 trillion tokens of English text and code, with a native context length of 8,192 tokens, and released in two sizes:

Show technical details· 2 rows × 4 columns
ModelParametersLayersContext
ModernBERT-base149M228,192
ModernBERT-large395M288,192

Both are released under Apache-2.0, which is why a derivative such as Laya can be released under the same licence.

What changed compared with BERT

The main architectural and training changes, as described in the paper:

  • Rotary positional embeddings (RoPE) instead of learned absolute positions. RoPE encodes relative position and extends to longer contexts more gracefully.
  • GeGLU activations in the feed-forward layers instead of GeLU, following results from decoder models.
  • Alternating local and global attention. Most layers use a sliding-window (local) attention; every few layers use full global attention. Long inputs therefore cost much less than full attention in every layer.
  • Unpadding. Padding tokens are removed and sequences in a batch are packed, so compute is not wasted on padding. Combined with FlashAttention, this is a large part of the speed gain on variable-length inputs.
  • No bias terms in most linear layers and an extra normalisation after embeddings, choices borrowed from recent LLM practice to stabilise training.
  • A modern BPE tokenizer with a vocabulary of roughly 50k tokens that handles code well.
  • Much more and more varied data: 2T tokens including code, versus BERT's roughly 3.3B-word corpus.

The result is an encoder designed for inference on common GPUs, with a context window long enough for whole emails and tickets.

What ModernBERT is good at, and what it is not

Good at: English classification, retrieval (single-vector and multi-vector), code-related tasks, and long English documents. Its efficiency makes it a strong default backbone when you need many predictions per second.

Not good at: languages other than English. ModernBERT's training data and tokenizer are English- and code-centric. Text in non-Latin scripts is broken into tokens the model has barely seen. The Laya model card shows how severe this is in practice. The English checkpoint, on 20-option MASSIVE intent classification, scores:

Show technical details· 7 rows × 2 columns
LanguageAccuracy (random = 0.050)
English0.783
French0.487
Spanish0.480
Hindi0.100
Korean0.103
Swahili0.103
Tamil0.113

Worse than the accuracy is the confidence: on Khmer the English checkpoint reports 0.952 confidence at 0.000 accuracy, and ECE reaches 0.855 on Hindi. The model does not know it cannot read the input. That is why Laya pairs ModernBERT with an mmBERT-based multilingual checkpoint and a script-detecting router. See mmBERT and language routing.

ModernBERT is also not a generator and not a reasoner. It produces vectors, and what you build on those vectors determines what the system can do.

How Laya builds on ModernBERT-large

Two of Laya's three checkpoints use ModernBERT-large as their backbone:

Show technical details· 3 rows × 4 columns
CheckpointBackboneTotal paramsContext used
laya (English)ModernBERT-large, fully fine-tuned421M512
laya-typed-decisionsModernBERT-large421M1,024
laya-multilingualmmBERT-base322M1,024

On top of the 395M-parameter encoder, Laya adds a decision head trained from scratch:

  • a learned type embedding added to every token, telling the model whether this is a choice, score or noul question;
  • two extra transformer layers that refine the encoder's output for the decision task;
  • an option-marker scorer, a small MLP that turns the vector at each option's [MASK] position into one logit;
  • an act head that reads the pooled vector plus summary features of the answer distribution.

The encoder is fully fine-tuned, not frozen. Training uses RLCD, a reinforcement learning scheme with a strictly proper scoring-rule reward; see RLCD.

Two implementation details from the package source are worth knowing if you self-host. First, Laya disables ModernBERT's automatic torch.compile (reference_compile = False), because compilation is a net loss for the small batches Laya runs and can hang on some platforms. Second, the English checkpoint uses only 512 of ModernBERT's 8,192-token context, split into 192 tokens for the question and options and the remainder for the state. The long-context capability is available in the backbone but not used by default.

Why ModernBERT is a good fit for typed decisions

Laya's design needs three things from its backbone, and ModernBERT supplies all of them:

  1. Bidirectional attention, so each option marker can attend to the full state and to the competing options. See option-marker scoring.
  2. A masked-token pretraining objective, so the representation at a [MASK] position is already trained to summarise surrounding context. Laya's option markers reuse that token.
  3. Fast inference at small batch sizes, so several questions per call can be answered well inside an agent's latency budget. The card reports 39.5 ms for one question and 158.6 ms for ten on a T4.

The trade-off is language coverage, which is handled by routing rather than by stretching ModernBERT beyond what it was trained for.

Using the ModernBERT-based checkpoint on Laya Studio

Laya Studio routes English text to the ModernBERT-large checkpoint automatically. You can also pin it explicitly with "model": "english":

Show technical details· bash sample
bash
curl -s https://api.laya.studio/v1/systemone \
  -H "Authorization: Bearer $LAYA_STUDIO_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "english",
    "state": {"post": "Great write-up, but the benchmark table is missing the batch size."},
    "questions": {
      "toxic": {"type": "noul", "instructions": "Is post toxic: rude, disrespectful or likely to make someone leave the discussion?"},
      "severity": {
        "type": "score",
        "instructions": "How severe is any rule-breaking in post?",
        "criteria": [
          "no rule-breaking: ordinary on-topic post",
          "mild: rude tone or off-topic, no target",
          "clear violation: insults, harassment or spam aimed at someone",
          "severe: threats, hate speech or calls for violence"
        ]
      }
    }
  }'

The routing block in the response records "model": "english" and the reason (explicit model='english' when pinned, English Latin text when auto-routed). Pin the English checkpoint only when you know the traffic is English: forcing it onto other scripts reproduces the collapse shown above. Two questions cost two credits; see /pricing and /docs.

Frequently asked questions

Is ModernBERT multilingual?
No. ModernBERT was trained mainly on English text and code. For other languages use a multilingual encoder such as mmBERT, which is what Laya's multilingual checkpoint is built on.
How large is ModernBERT-large?
395M parameters across 28 layers, with a native context of 8,192 tokens. Laya's English checkpoint adds a decision head for a total of 421M parameters.
Does Laya use ModernBERT's full 8,192-token context?
Not by default. The English checkpoint uses 512 tokens per question and the typed-decisions checkpoint 1,024. Self-hosters can raise the limits in the config, at a cost in latency and with accuracy effects that should be measured.
Can I fine-tune ModernBERT myself instead of using Laya?
Yes, and for a fixed label set with plenty of labelled data a fine-tuned ModernBERT classifier is a strong baseline. Laya's difference is that the options are supplied per request and the output is trained for calibrated probabilities, so one model serves many schemas.
Why does the English checkpoint fail on Hindi or Korean?
Its tokenizer and pretraining data barely cover those scripts, so the text is effectively unreadable to it. The model card reports near-random accuracy on those languages with high confidence, which is why Laya routes non-Latin scripts to the multilingual checkpoint.
What is ModernBERT used for?
Tasks that read text rather than write it: classification, retrieval and search, reranking and tagging. It is a backbone to fine-tune or build on, as Laya does for typed decisions, not a chatbot.
Is ModernBERT better than BERT?
Its authors describe it as a Pareto improvement over older encoders: better downstream quality at the same or lower inference cost, with a much longer native context of 8,192 tokens. As with any benchmark claim, check it on your own task.

Sources

Last updated . Laya Studio is an independent hosted service for the open-source Laya model (Apache-2.0, © Convai Innovations) and is not affiliated with Convai Innovations or TypeSafe.