Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 23 min read Announcement mediumAdept

Finally, a Replacement for BERT: Introducing ModernBERT

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.

Assumes: transformer encoder modelsBERT fine-tuningembeddings for retrieval

Related posts

  • Ettin Suite: SoTA Paired Encoders and Decoders

    Hugging Face hardMaster

    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). The encoders beat ModernBERT and the decoders match or beat Llama 3.2 1B and SmolLM2. The controlled comparison shows encoders dominate classification and retrieval (a 150M encoder beats a 400M decoder on MNLI) while decoders win at generation. Continued training with the opposite objective for 50B tokens fails to close the gap, so architecture choice matters beyond the objective. Usage and fine-tuning code for Sentence Transformers and PyLate ColBERT embeddings is included.

  • mmBERT: ModernBERT goes Multilingual

    Hugging Face hardMaster

    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. It is the first model to clearly beat XLM-R on XTREME, GLUE and MTEB v2 retrieval, and it runs 2-4x faster with an 8,192-token context. The training recipe has three phases that add languages progressively (60 → 110 → 1,833), anneal the sampling temperature (0.7 → 0.5 → 0.3) and lower the mask ratio (30% → 15% → 5%), then combines decay-phase variants with TIES merging. Low-resource languages added only in the final 100B-token decay phase are still learned effectively, and on Faroese QA the model outperforms Gemini 2.5 Pro and o3.

  • Introducing the Ettin Reranker Family

    Hugging Face mediumAdept

    Six Sentence Transformers CrossEncoder rerankers (17M to 1B parameters) built on the Ettin ModernBERT encoders are released with their data and full training recipe. They were distilled with pointwise MSE on mxbai-rerank-large-v2 scores. On MTEB(eng, v2) Retrieval, top-100 reranked across six embedders, the 1B model matches its 1.54B teacher (0.6114 vs 0.6115 NDCG@10). The 17M beats the legacy ms-marco-MiniLM-L12-v2 by +0.051, and the 150M edges out Qwen3-Reranker-0.6B. The architecture uses a plain AutoModel with CLS pooling, which ablations found beat mean pooling, plus a small dense head, enabling unpadded Flash Attention 2 for 1.7x-8.3x speedups over fp32+SDPA with 8K context.

  • Pre-Train BERT with Hugging Face Transformers and Habana Gaudi

    Hugging Face mediumAdept

    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. The workflow merges BookCorpus and Wikipedia, trains a 32k-vocab tokenizer, and packs the text into 512-token chunks on a CPU instance. Training then runs data-parallel across 8 HPUs by swapping Trainer for GaudiTrainer, launched remotely with EC2 Remote Runner. 100k steps at global batch 256 took about 12.5 hours, which projects a full 1M-step pre-training to roughly $1,650. That is about 25% cheaper than a DeepSpeed V100 baseline estimated at around $2,075.

  • Code Llama: Llama 2 learns to code

    Hugging Face mediumAdept

    Code Llama is a family of 7B, 13B and 34B Llama 2 derivatives trained on 500B tokens of code. It comes in base, Python-specialized and instruction-tuned variants, has a 16k training context that extrapolates to 100k via RoPE frequency scaling, and supports fill-in-the-middle infilling in the 7B and 13B models. Hugging Face integration starts at transformers 4.33, with code for completion, infilling with the <FILL_ME> token, the Llama 2 chat prompt template, and 4-bit bitsandbytes loading. Recommended setup is float16 for inference and bfloat16 for fine-tuning, plus GPU sizing guidance for TGI/Inference Endpoints and HumanEval/MultiPL-E evaluation.

The quest for software engineering knowledge.

Look:
Layout: