MEAP Cuts LLM Hallucinations and Triples Retrieval Efficiency With 15% Token Masking
A tiny tweak to next-token prediction, randomly masking 15% of tokens, dramatically boosts long-context retrieval without any architecture change or extra compute.
ProTakeaways
- MEAP randomly masks 15% of input tokens then runs standard next-token prediction on a decoder-only Transformer
- Boosts Needle-in-a-Haystack accuracy at 32K from 87.1% to 98.2% at 200B tokens on 1.1B models
- Reaches NTP's 200B-token retrieval accuracy using only 60B tokens, about 3x sample efficiency
- Fine-tuning Llama-3-8B with MEAP beats NTP by 11.77 points on multi-document QA
- Attention analysis shows masked positions get 53% less attention, sharpening focus on answer tokens
- Code released at github.com/CharlieZhuang-Code/MEAP; accepted to ICML 2025
A new pre-training paradigm called Mask-Enhanced Autoregressive Prediction (MEAP) shows that one of the oldest ideas in language modeling, BERT-style masking, still has something to offer decoder-only LLMs. The recipe is almost embarrassingly simple: randomly mask about 15% of the input tokens, then train the model with the exact same next-token prediction objective everyone already uses. No bidirectional attention, no encoder, no auxiliary loss, no extra compute. The payoff is a large jump in long-context retrieval accuracy and a measurable drop in hallucinations.
The retrieval problem hiding inside every LLM
Modern LLMs are almost universally trained with next-token prediction (NTP), where a decoder-only Transformer predicts each token from the left-to-right context. It scales beautifully and produces fluent text, but recent studies highlight the limitations of NTP-based LLMs in accurately retrieving key information from context. This is the failure mode behind the well-known lost-in-the-middle phenomenon: give an LLM a long document with a critical fact buried in the middle, and accuracy collapses.
Masked language modeling (MLM), the objective behind BERT, is naturally better at this kind of precise retrieval because it forces the model to reconstruct missing pieces from surrounding context. But MLM typically operates best within two-stack encoder-decoder architectures, and performance degrades significantly when applied to decoder-only Transformers. Prior attempts to marry the two, such as UniLM and UL2, worked by juggling multiple objectives during pre-training, which adds real complexity when you're scaling to billions of parameters.
The trick: mask the input, keep the objective
MEAP sidesteps the architecture question entirely. It first randomly masks a small fraction of the input tokens and then directly performs standard next-token prediction using a decoder-only Transformer in an autoregressive manner. Causal attention stays in place. The loss is still cross-entropy over the next token. The only change is that some input positions have been swapped for a [MASK] token before the forward pass.
For pre-training, the authors settle on a 15% mask ratio. Fine-tuning is slightly different: because supervised data often contains critical facts you don't want to blur out, MEAP duplicates the input sequence, masks 10% of the copy, and computes loss only on masked answer tokens. That doubles sequence length during training, but as we'll see, it more than pays for itself in data efficiency.
Here's the mechanical difference in a few lines of pseudo-code:
def meap_batch(tokens, mask_id, p=0.15):
mask = torch.rand_like(tokens, dtype=float) < p
corrupted = torch.where(mask, mask_id, tokens)
logits = decoder_only_transformer(corrupted) # causal attention
loss = cross_entropy(logits[:, :-1], tokens[:, 1:]) # standard NTP
return loss
Where the numbers get interesting
The team pre-trained 1.1B LLaMA-style models on 40B, 60B, and 200B tokens, then extended context to 64K. The headline result is on Needle-in-a-Haystack retrieval at 32K context. At 40B tokens, MEAP achieves 80.2% accuracy, significantly surpassing the baseline's 65.9%. The performance gap peaks at 60B tokens, with MEAP maintaining steady improvement and reaching 85.8% accuracy. By 200B tokens MEAP hits 98.2% while NTP still sits below 90%.
The data efficiency angle is arguably more important than the peak numbers. MEAP achieves 85.8% accuracy using just 60B training tokens, whereas NTP requires approximately three times as many (200B tokens) to reach a similar level. That's a roughly 3x improvement in sample efficiency on a task NTP models are known to struggle with.

The heatmaps make the story concrete. MEAP generally maintains perfect accuracy across different context lengths and depths, with errors limited to only two grid cells. In contrast, NTP begins to exhibit accuracy degradation at a context length of 24K, affecting a wide range of depths from 50% to 100%.
On multi-document QA using NaturalQuestions-Open, the improvements are similarly large. In the 20-document setting, MEAP outperforms NTP by +27.2% at position 5 in 20-doc, which is exactly the mid-context region where lost-in-the-middle usually bites hardest. In fine-tuning experiments with Llama-3-8B on Alpaca, MEAP beats NTP by an average improvement of 11.77% across all document positions, with a peak gain of 15.22 points at position 20.
Fewer hallucinations, unchanged commonsense
Because the model is being nudged toward more precise use of context, hallucinations drop too. On XSum, MultiNews, and WikiSum summarization, judged by DeepSeek-V3, Qwen-Plus, and GPT-4o, MEAP consistently produces fewer hallucinated summaries than the NTP baseline across all three judges.
Just as importantly, general capabilities don't regress. On the standard commonsense suite (ARC, BoolQ, PIQA, HellaSwag, WinoGrande, OBQA), MEAP matches or slightly beats NTP, with a 1.6-point average gain after pre-training and a 1.12-point gain after fine-tuning. This matters because plenty of clever training tricks improve one axis at the cost of another. MEAP appears not to.
Why it actually works
The authors offer a mechanistic explanation that's easier to buy than most post-hoc stories. Softmax attention normalizes scores into (0, 1), which tends to squash differences between tokens over long sequences. Combined with attention sinks, where the first few tokens hoard attention regardless of relevance, this leaves the model with a mushy, low-contrast view of its own context.
Masking pushes back on that. Because masked positions carry no useful information, the model learns to assign them near-zero attention, which sharpens the distribution over the tokens that remain. The team measured this directly. At 4K sequence length, MEAP shows a 53.34% Score Decay at masked positions and a 7.80% Var. Increase in attention variance at non-masked positions. Translated: masked tokens get ignored, and everything else becomes more distinguishable.
The downstream effect on inference is striking. On a probe example asking who designed the Eiffel Tower, MEAP puts 34.5% of its attention on the answer span versus 9.4% for NTP, while cutting attention on the pre-answer context from 73.1% to 49.1%.
What it's good for, and what it isn't
MEAP is a drop-in replacement for NTP whenever the downstream job involves finding, integrating, or reasoning over specific facts in long inputs. Concrete situations where it should help:
- Retrieval-augmented generation pipelines where the answer is hiding among distractor documents
- Long-document QA, contract analysis, and code repository reasoning
- Summarization tasks where faithfulness to source matters more than style
- Multi-hop reasoning that requires stitching together evidence from different context regions
Where MEAP is unlikely to move the needle: pure short-context generation, creative writing, and tasks that don't actually require precise attention over long inputs. The commonsense benchmarks are essentially flat, which is a feature rather than a bug, but also a reminder that this is a targeted improvement.
The fine-tuning ablation matters for practitioners: 10% masking wins for SFT, 15% wins for pre-training, and pushing the ratio higher hurts. Longer span masking (5-token and 50-token spans) performs comparably to random masking on commonsense but underperforms on multi-document QA, so the default random per-token strategy is the safe pick.
Availability
The paper is being presented at ICML 2025 and the authors have released code at github.com/CharlieZhuang-Code/MEAP. Because MEAP requires no architectural change and no inference-time modifications, dropping it into an existing training pipeline is a matter of adding a masking step to the data collator. That's a low-risk experiment for anyone currently pre-training or fine-tuning decoder-only models with long-context retrieval as a target capability.