Abstract
We present a simple way to merge masked language modeling with causal language modeling. This hybrid training objective results in a model that combines the strengths of both modeling paradigms within a single transformer stack: GPT-BERT can be transparently used like any standard causal or masked language model. We test the pretraining process that enables this flexible behavior on the BabyLM Challenge 2024. The results show that the hybrid pretraining outperforms masked-only or causal-only models. We openly release the models, training corpora and code.
Introduction
In modern Natural Language Processing, researchers typically choose between two architectural paradigms. Causal Language Models (CLMs), such as GPT, utilize left-to-right attention to excel at text generation. Conversely, Masked Language Models (MLMs), such as BERT, employ bidirectional attention to build deep contextual representations, making them superior for understanding tasks but poor at generation.
This dichotomy forces a trade-off between a model that is effective at "talking" and one that is effective at "understanding." GPT-BERT addresses this by unifying both objectives into a single, flexible transformer stack without increasing parameter count or architectural complexity.
The GPT-BERT Architecture
The core innovation of this work is Masked Next-Token Prediction (MNTP). In standard BERT training, if a token at position $k$ is masked, the model predicts it at position $k$. In GPT training, the model at position $k$ predicts the token at $k+1$. To unify these, the authors shift the BERT objective: when a token at position $k+1$ is masked, the model is tasked with predicting it at position $k$.
This "one-token shift" aligns the output patterns of both objectives. The resulting model can be used as a standard GPT (with a causal mask) or a standard BERT (without a mask) by simply toggling the attention mechanism at inference time. Additional improvements include gated linear units (GLU) for attention modulation and layer weighting to allow each layer to learn from a combination of all previous outputs.
Experimental Setup
The models were evaluated as part of the BabyLM Challenge 2024, which emphasizes sample-efficient learning from human-scale data (10M to 100M words). The training data consisted of a balanced mix of the BabyLM corpus, FineWeb-Edu, and Cosmopedia. Benchmarks included BLiMP for syntax, GLUE/SuperGLUE for NLU, and LAMBADA for long-range word prediction.
Key Results and Synergy
GPT-BERT set new performance benchmarks for the BabyLM challenge. In the STRICT-SMALL (10M words) track, it achieved a GLUE score of 76.5 and a BLiMP score of 81.2. In the STRICT (100M words) track, scores reached 81.5 and 86.1, respectively.
A critical finding was the synergy between the two objectives. Rather than sacrificing performance to achieve flexibility, the hybrid approach showed that adding even a small amount of the "other" objective significantly boosted results. For instance, a 15:1 causal-to-masked ratio (adding only 6.25% MNTP to a causal model) resulted in a massive performance jump on the LAMBADA benchmark.
Furthermore, GPT-BERT demonstrated emergent in-context learning (ICL) capabilities at scales as small as 30M parameters, suggesting that the hybrid objective helps the model "punch above its weight" compared to single-objective baselines.
Discussion and Conclusion
GPT-BERT proves that the gap between masked and causal modeling is merely a "target shift" away. By unifying these paradigms, researchers can deploy a single "Swiss Army knife" model capable of both high-quality generation and robust natural language understanding. While this study focused on the BabyLM scale (up to 119M parameters), future work will explore whether these benefits persist at the scale of billions of parameters. The authors have released their code and models to encourage further exploration of unified language modeling.
Summary updated