Dissecting AI
From the paper: UltraBERT: Beyond the Limit of BERT Pre-Training

UltraBERT: Dual Heads for Contrasting Masking Regimes

Mixing lightly and heavily masked sequences creates competing prediction geometries; UltraBERT gives each masking ratio its own language-model head to reduce that interference.

Read the paper ↗
The short version

What it is

  • Mixed masking Train on lightly and heavily masked text in the same batch so one encoder learns from both kinds of prediction task.
  • Decoupled prediction heads Give each masking level its own final word-prediction layer, rather than making both kinds of examples use one shared layer.

Why it matters

Different masking levels favor different downstream tasks and produce differently shaped prediction heads. Mixing examples can serve both regimes, while separate heads reduce the conflict that a shared prediction layer can create.

Before getting into the mechanics, the idea is straightforward: put lightly and heavily masked examples in the same training batch, but let each kind use its own word-prediction head. That way one encoder can learn from both regimes without forcing one final prediction layer to fit both. The paper’s concrete setup combines 5% and 50% masking, with four times as many lightly masked sequences.

  1. Different task preferences: In the reported comparisons, lower masking favors classification and higher masking favors retrieval. One masking choice therefore leaves a real tradeoff; the point here is not to explain how those preferences arise, but how to train across them.
  2. Mixed examples can interfere: Think of the two masking regimes as two jobs sharing a workshop. They can share tools, but if they need differently shaped jigs, a single jig may get in the way. That analogy is limited: the actual issue is gradient interaction through model parameters, not a literal physical obstruction.
  3. The output layer is a plausible place to separate them: The canonical example is the LM head. The reported input embedding geometries for low and high masking are almost identical, while the heads look different; the lower-mask head has more concentrated singular values and occupies a lower-dimensional subspace. The encoder gets gradients through that head, so one shared head could make the tasks tug against each other.

So the real question is whether just mixing the examples is enough. In the reported comparison, sampling uniformly across masking ratios behaves much like using a single middle ratio. Combining the two extremes is more directly aimed at both regimes, but the shared-head version still underperforms the separate-head version on the classification side. Decoupling means routing each ratio through its own head; it does not mean training separate encoders. What does that separation buy, and what does it leave shared?

The reported mixed setup with separate heads reaches the best single-ratio GLUE and BEIR scores in the 150M comparison. That is evidence for this particular recipe, not a general guarantee. The encoder still carries both tasks, and the approach adds a head and requires ratio-aware routing. I find the key engineering idea appealing because it isolates a specific suspected conflict rather than duplicating the whole model. How much remaining interference comes from the shared encoder is still the open question.

Read the deep dive

Why People Wanted It

A single masking ratio pushes an encoder toward one kind of representation. The reported comparisons show the tension: lower masking favors classification, while higher masking favors retrieval. Mixing ratios in one batch sounds like a way to serve both, but it also asks shared parameters to satisfy two different prediction tasks. The real question is not merely how to put both kinds of examples in a batch; it is whether they should also share the same prediction head.

The Core Move

Mix lightly and heavily masked sequences in each batch, but give each masking ratio its own language-model head. The stated setup combines 5% and 50% masking at a 4:1 sequence ratio; the paper gives no update equation for this method, so the mechanism can be shown without adding one.

Quiz
What is the key architectural change when mixing low- and high-masking examples?
Use one shared head and sample ratios uniformly.
Replace masked-language-model training with retrieval loss.
Train a separate encoder for every masking ratio.
Use a separate language-model head for each masking ratio.

Why Mixing Ratios Is a Multitask Problem

Now the version for readers who want more of the machinery: each masking ratio defines a distinct training task, and the shared encoder is optimized against both tasks' losses. The reported setup places 5%-masked and 50%-masked sequences in the same batch, with four times as many 5%-masked sequences because their gradients are sparser and converge more slowly. This is not a claim that every task gets equal weight: the sequence counts are deliberately unequal.

A uniform sweep across masking ratios is a different choice. In the reported comparison, sampling uniformly from 5% to 50% behaves much like using a single 30% ratio; mixing only the two extremes is the more targeted way to retain both regimes. Why might even that targeted mixture still interfere?

Why the LM Heads Need Different Geometries

Here is the part that gets technical: the input embedding matrices for models trained at 6% and 50% masking are described as almost identical, while their LM heads take clearly different shapes. The 6% head has more concentrated singular values, indicating that it occupies a lower-dimensional subspace. The encoder receives gradients through its LM head, so sharing a head across these different prediction geometries may create gradient-level interference.

Decoupling means using one LM head for each masking ratio while continuing to train the mixed batch. The reported 5% and 50% decoupled heads have distinct geometries. In the 150M comparison, the mixed setup without decoupling improves retrieval relative to the single 15% result but does not recover the low-mask classification result; with decoupling, the reported GLUE and BEIR scores reach the respective best single-ratio scores. Those are results for that comparison, not a guarantee for every model or training setup. What is gained by separating the heads, and what shared capacity remains a possible source of conflict?

Minimal Causal Code

This plain loop makes the routing visible: each example's masking ratio selects its own prediction head. It omits the paper's full encoder, masking, and loss implementation.

import torch
import torch.nn.functional as F

# encoder, head_5, and head_50 are ordinary PyTorch modules.
# Each batch item carries a ratio label: "5" or "50".
def train_step(batch, optimizer):
    tokens, labels, ratio = batch
    hidden = encoder(tokens)
    loss = torch.zeros((), device=tokens.device)

    for name, head in [("5", head_5), ("50", head_50)]:
        selected = ratio == name
        if selected.any():
            logits = head(hidden[selected])
            loss = loss + F.cross_entropy(logits, labels[selected])

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    return loss

What You Gain, and What You Lose

Separate heads let the two masking regimes fit different output geometries instead of forcing one LM head to serve both. The reported mixed-and-decoupled setup reaches the best single-ratio GLUE and BEIR scores in the comparison, while the shared-head mixture falls short on classification.

The cost is another prediction head and a more structured training batch; the encoder is still shared, so decoupling does not remove every possible source of task conflict. The result is a targeted compromise, not proof that arbitrary masking mixtures will work equally well. A separate module covers how masking choices relate to downstream task preferences.

Quiz
Why can separate heads help when both masking regimes are trained together?
Separate heads eliminate the need to share an encoder.
Separate heads guarantee that every downstream task improves.
The input embedding matrices are reported to have completely different geometries.
The regimes can have different prediction-head geometries, so one shared head may cause interference.
Core Takeaway

Share the encoder across masking regimes; separate the prediction heads when their output geometries pull in different directions.