---
title: "Finally, a Replacement for BERT: Introducing ModernBERT"
description: "ModernBERT is a family of encoder-only models (149M base, 395M large) that ports recent LLM architecture and training advances back to the BERT style, raising context length to 8,192 tokens and including large amounts of code in pretraining."
url: "https://swe.quest/articles/finally-a-replacement-for-bert-introducing-modernbert-95bd85fcbbb49537"
canonical: "https://huggingface.co/blog/modernbert"
source: "Hugging Face"
published: "2024-12-19"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 23
tags: ["machine-learning","model-training","inference","rag","llms"]
---

# Finally, a Replacement for BERT: Introducing ModernBERT

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-12-19, 23 min read, Announcement. Original: [https://huggingface.co/blog/modernbert](https://huggingface.co/blog/modernbert)

## Summary

ModernBERT is a family of encoder-only models (149M base, 395M large) that ports recent LLM architecture and training advances back to the BERT style, raising context length to 8,192 tokens and including large amounts of code in pretraining. It is the first base-size model to beat DeBERTaV3 on GLUE while using under 1/5th of its memory, and it runs 2-4x faster, especially on mixed-length inputs. It also leads long-context ColBERT retrieval and code retrieval tasks such as StackOverflow-QA. It works as a drop-in BERT replacement in transformers, without token type IDs and with Flash Attention 2 recommended, and must be fine-tuned for downstream tasks.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [RAG & retrieval](https://swe.quest/tags/rag.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- transformer encoder models
- BERT fine-tuning ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- embeddings for retrieval ([easy posts on RAG & retrieval](https://swe.quest/tags/rag.md?difficulty=easy))

## Keywords

ModernBERT, BERT, DeBERTaV3, Hugging Face Transformers, Flash Attention 2, ColBERT, Answer.AI, LightOn

## Related posts

- [Ettin Suite: SoTA Paired Encoders and Decoders](https://swe.quest/articles/ettin-suite-sota-paired-encoders-and-decoders-285a76b68aebed62.md): Hugging Face · 2025-07-16 · Hard · 15 min read · LLMs, Model training, Evaluation, Search
  Ettin is a suite of paired encoder-only and decoder-only models (17M–1B parameters) trained on identical open data (2T tokens), architecture and three-phase recipe derived from ModernBERT, differing only in attention pattern and objective (MLM vs CLM).
- [mmBERT: ModernBERT goes Multilingual](https://swe.quest/articles/mmbert-modernbert-goes-multilingual-ef8a6ca2e930c6ea.md): Hugging Face · 2025-09-09 · Hard · 15 min read · Model training, LLMs, Search
  mmBERT is a massively multilingual encoder built on the ModernBERT architecture with the Gemma 2 tokenizer, trained on over 3T tokens covering 1,833 languages.
- [Introducing the Ettin Reranker Family](https://swe.quest/articles/introducing-the-ettin-reranker-family-7e39cb92c1c0a726.md): Hugging Face · 2026-05-19 · Medium · 30 min read · Search, Model training, Inference & serving, Evaluation, Python
  Six Sentence Transformers CrossEncoder rerankers (17M to 1B parameters) built on the Ettin ModernBERT encoders are released with their data and full training recipe.
- [Pre-Train BERT with Hugging Face Transformers and Habana Gaudi](https://swe.quest/articles/pre-train-bert-with-hugging-face-transformers-and-habana-gaudi-81eabeeaee082cc4.md): Hugging Face · 2022-08-22 · Medium · 10 min read · Model training, LLMs, Hardware, Cost optimization, Python
  BERT-base can be pre-trained from scratch with masked-language modeling on an AWS DL1 instance (Habana Gaudi), using Hugging Face Transformers, Datasets and Optimum Habana.
- [Code Llama: Llama 2 learns to code](https://swe.quest/articles/code-llama-llama-2-learns-to-code-bbc6e9367fb26138.md): Hugging Face · 2023-08-25 · Medium · 12 min read · LLMs, AI for coding, Inference & serving, Python, Evaluation
  Code Llama is a family of 7B, 13B and 34B Llama 2 derivatives trained on 500B tokens of code.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
