AI State of the Art
Fundamentals/NLP: From Classical to Modern/31 min
Section 42

BERT Variants: RoBERTa, ALBERT, DeBERTa, DistilBERT

Listen as a podcast →

After BERT: the rush of variants

BERT (Bidirectional Encoder Representations from Transformers) arrived in October 2018 and upended NLP, Natural Language Processing, the automatic handling of human language. How it works is covered in the BERT lesson; this page is about what its successors did with it.

Suddenly everyone wanted their own version of BERT. Four of them taught four genuinely different lessons.

RoBERTa: the secret recipe (or: BERT was poorly trained)

The humbling discovery

RoBERTa (Robustly Optimized BERT Pretraining Approach, Facebook, 2019) does something odd: it changes nothing about BERT's architecture. Zero modifications. Same number of layers, same dimensions, everything identical.

And yet: it breaks BERT's records.

Why? Because BERT was under-optimized. The training choices were suboptimal. With a better recipe, same architecture = much better.

The 4 changes (and why)

1. NSP disappears

BERT had two training objectives. MLM (masked language modeling): hide some words in a sentence and make the model recover them. NSP (next sentence prediction): show the model two sentences and ask whether the second really followed the first in the source text. The RoBERTa authors showed that NSP contributed nothing, worse, it introduced noise that degraded the representations. Removing it improved performance.

2. Dynamic rather than static masking

BERT masked its tokens (the word fragments produced by tokenization) once at the start of training, then reused that same masking at every epoch (one epoch = one full pass over the corpus). RoBERTa redraws the mask every time a sentence is fed to the model: same sentences, different hidden words on each pass. The model therefore sees far more learning situations from the same corpus, which yields more robust representations.

Comparison of BERT static masking and RoBERTa dynamic masking. On the left, the same initial sequence is masked 10 times and each masking is then reused 4 times identically. On the right, a new masking is drawn every time the sequence is passed to the model, giving 40 masked sequences that are all different.
Left, BERT: ten maskings are frozen once and for all, each seen four times identically. Right, RoBERTa: a fresh draw of masked tokens on every pass, so forty all-different variants of the same sentence. Same corpus, but ten times more learning situations.Source : Zilliz, RoBERTa blog post

3. Much more data

BERT trained on 16 GB of text (BookCorpus + Wikipedia). RoBERTa gets to 160 GB, ten times more, by stacking four corpora whose sizes the paper lists: BERT's original 16 GB, CC-News (76 GB of news articles), OpenWebText (38 GB of pages linked from Reddit) and Stories (31 GB filtered out of Common Crawl). Add them up: 16 + 76 + 38 + 31 = 161 GB.

4. More aggressive training

BERT trained on batches of 256 sequences; RoBERTa's final configuration uses 8,000 sequences per batch, 32 times more. A larger batch gives a less noisy gradient, which permits a larger learning step and keeps multiple graphics cards usefully busy in parallel. RoBERTa also trains for more steps.

The lesson

It's humbling: the best improvements don't come from new ideas. They come from doing the basics better. Be suspicious of papers that open with "we changed one small thing and it works", often the real story is that the baseline was undertrained.

The numbers: on GLUE (General Language Understanding Evaluation, a battery of nine English comprehension tasks, see benchmark limits), the RoBERTa paper reports a test-set average of 88.5, against the 80.5 that the original BERT paper reported for BERT-large. Roughly eight points, with no architectural change at all.

The importance of ablations

RoBERTa tests each change separately: data, masking, batch size. That is an ablation study, you remove or alter one ingredient at a time to measure what it actually contributes. It is tedious work, but it is how you learn what matters. Too many papers change ten things at once and credit the gain to whichever one they find interesting.

ALBERT: intelligent compression

The problem: BERT is bulky

BERT-large has 334 million parameters (the figure from the ALBERT paper, which recounts both BERTs so the comparison is fair). Each parameter is a decimal number stored on 4 bytes, so: 334 million x 4 bytes ≈ 1.3 GB for the weights alone. That is awkward:

  • on a phone, where an app rarely gets more than one or two gigabytes of working memory;
  • on a small GPU (Graphics Processing Unit, the graphics chip these models run on), whose dedicated memory (VRAM, for Video RAM) fills up fast as soon as you want to train rather than merely query the model;
  • on embedded devices (sensors, watches, controllers), where it is simply out of reach.

ALBERT (A Lite BERT, Google; paper from September 2019, published at the ICLR 2020 conference) says: we can go much smaller.

Technique 1: the factorized embedding table

In BERT, the embedding table (the dictionary mapping each token to its starting vector) is as wide as the network's internal layers: 30,000 entries x 768 numbers = 23 million learned parameters.

But that table sees no context whatsoever. It is a pure lookup, consulted before the model starts working. Giving it the same width as the internal layers, which do have to represent rich contextual meanings, is waste.

ALBERT decouples the two widths:

  • a narrow table: 30,000 entries x 128 numbers;
  • then a learned linear projection widening 128 -> 768.

The arithmetic: 30,000 x 128 = 3.84 million, plus 128 x 768 ≈ 0.1 million for the projection, so about 4 million instead of 23. Over 80% saved on that part, with no measurable performance loss.

Technique 2: parameter sharing

Here ALBERT does something counter-intuitive: all layers share one single set of weights.

Do not conflate the two kinds of object involved. The weights are learned parameters, frozen once training ends: those are what get shared, and only one copy sits in memory. The activations (what each layer computes on the text at hand) still differ at every level: layer 5 receives layer 4's output, which is not what layer 1 received. It is like applying the same recipe twelve times to a dish that changes with each round of cooking.

The direct consequence: computational depth is untouched, but there is only a twelfth as many block weights to store.

ModelLayersParameters (ALBERT paper)
BERT-base12 layers, each with its own weights108M
BERT-large24 layers, each with its own weights334M
ALBERT-base12 layers, one shared set of weights12M
ALBERT-large24 layers, one shared set of weights18M
Hand-drawn diagram comparing two stacks of 12 Transformer blocks. On the left, each block has a different color: its weights are its own. On the right, all 12 blocks share the same color and an arrow labelled REUSE feeds the output of block 1 back into every higher level: a single set of weights is reused at each layer.
Left, BERT: twelve differently colored blocks, so twelve distinct sets of weights to store. Right, ALBERT: a single block, reused twelve times in a row. The computational depth is identical, but only a twelfth of the parameters has to be kept in memory.Source : Amit Chaudhary, A Visual Guide to ALBERT

The paper's strongest variant, ALBERT-xxlarge, comes back up to 235 million parameters, but spends them differently: only 12 layers, each very wide (4,096 numbers per internal vector, against 1,024 for BERT-large). It reaches a GLUE average of 89.4, beating BERT-large with fewer parameters.

The compromise to remember: inference does not get faster (there are just as many layers to traverse), but storage and memory shrink dramatically. Useful when you need the model loaded on many machines, or on a memory-constrained device; useless if your problem is latency.

SOP: learning where NSP failed

ALBERT swaps NSP (which, as RoBERTa showed, does not work well) for SOP (Sentence Order Prediction).

Instead of asking "are these two sentences consecutive?", it asks "are these two sentences in the right order?" The difference is decisive. In NSP, the negative second sentence came from a different document, so spotting a change of topic was enough to answer, an easy shortcut that teaches nothing about language structure. In SOP, both sentences always come from the same passage and only the order changes. The topic shortcut is gone; the model has to understand how one clause follows another.

Parameters and compute are two separate budgets

ALBERT sharply reduces parameter count (hence storage and resident memory) but does not reduce computation, hence not response time. These are different constraints, and a compression technique does not necessarily act on both. Compare with distillation and quantization, which make different trades.

DeBERTa: attention becomes surgical

The observation

DeBERTa (Decoding-enhanced BERT with Disentangled Attention, Microsoft, paper from June 2020, published at ICLR 2021) notices a detail: in standard BERT, content (what a word means) and position (where it sits in the sentence) are added together and then blended inside the attention computation. Why not keep them apart?

It's subtle, but logical. "Cat" has a meaning ("feline"), independent of its position. "At distance 3" is a distance concept, independent of the word. Why add them together and mix them?

Disentangled attention: the solution

Instead of one vector per token carried everywhere, DeBERTa keeps two:

  • a content vector: the word's meaning, computed from the token itself ("cat" -> felinity, smallness, domesticity);
  • a relative position vector: "this word sits 3 slots to my left". This second vector is a learned parameter, pulled from a small table indexed by distance rather than by absolute position.

In the attention computation, DeBERTa then decomposes the score:

Score(i→j)=Ci⋅Cj⏟meaning vs meaning+Ci⋅Pj∣i⏟meaning vs distance+Pi∣j⋅Cj⏟distance vs meaning\text{Score}(i \to j) = \underbrace{C_i \cdot C_j}_{\text{meaning vs meaning}} + \underbrace{C_i \cdot P_{j|i}}_{\text{meaning vs distance}} + \underbrace{P_{i|j} \cdot C_j}_{\text{distance vs meaning}}

Reading the formula symbol by symbol. ii is the word doing the looking, jj the word being looked at. CiC_i and CjC_j are their content vectors. Pj∣iP_{j|i} is the relative position vector of jj as seen from ii, the gap between the two, not jj's place in the sentence. The dot "⋅\cdot" is the dot product: it measures how far two vectors point the same way, hence how much they agree. In one sentence: the attention i pays to j is the sum of three agreements, their meanings with each other, i's meaning with the distance separating them, and that distance with j's meaning.

BERT, by contrast, computes a single product over the sum of content and position:

Score=(Ci+Pi)⋅(Cj+Pj)\text{Score} = (C_i + P_i) \cdot (C_j + P_j)

Expanding that product yields four terms: meaning-meaning, meaning-position, position-meaning, and position-position. DeBERTa keeps three and deliberately drops the fourth, position against position: knowing that "word 4 is looking at word 7" with no reference to any content teaches nothing useful. That is where the count of three comes from, not from an arbitrary choice.

Diagram of DeBERTa disentangled attention. At the bottom, two separate sources: a content embedding (pink) and a relative position embedding (blue). Content produces three linear projections V_c, K_c and Q_c; relative position produces two, Q_r and K_r. Three dot products are computed and summed before the Scale, Mask, softmax and MatMul with V_c steps.
The key part is the bottom of the diagram: two separate inputs, content (pink) and relative position (blue), instead of a single sum as in BERT. The three dot products meeting at the plus sign are exactly the three terms of the formula above: meaning against meaning, meaning against distance, distance against meaning.Source : Diagram after DeBERTa (He et al., 2021), via the velog blog of aqaqsubin

Why is it better?

Example: "The [token_j] sleeps far away". [token_j] is 3 positions away.

  • Token_j attracts attention through meaning (it's an animal, as "sleeps" attracts animals)
  • Token_j attracts attention through distance (close, within the "local window" of the sentence)

Both signals are important but different. Modeling them separately allows DeBERTa to precisely weigh "I'm interested in meaning" vs. "I'm interested in proximity." BERT blurs the two.

The result

Two numbers, both from the paper. On GLUE, DeBERTa-large (24 layers) reaches an average of 90.0, against 88.8 for RoBERTa-large measured under the same conditions.

More strikingly: on SuperGLUE (the hardened version of GLUE, built in 2019 precisely because models were saturating GLUE) the largest DeBERTa (1.5 billion parameters, 48 layers) scores 89.9, crossing the human baseline of 89.8 for the first time; an ensemble of several DeBERTas reaches 90.3. Note what that does and does not mean: the human baseline is the score of paid annotators on those specific tasks, not "human ability" in general. The benchmark limits lesson explains why such crossings should be read carefully.

Model design was not settled

Even after BERT, real headroom remained in the architecture itself. Disentangling content from position, rethinking positional encoding: these refinements produced measured gains, not just training-recipe effects. Worth remembering whenever a paper claims a family of architectures has hit its ceiling.

DistilBERT: shining in deployment

The realistic problem

BERT-base has roughly 110 million parameters, so 110 million x 4 bytes ≈ 440 MB of weights to load. That is heavy for:

  • mobile apps, where the file has to be downloaded first;
  • embedded devices (routers, watches, cars);
  • servers answering very large request volumes, where every millisecond of compute is paid for in machines.

The solution: distillation (learning from the best)

DistilBERT (Hugging Face, 2019) uses knowledge distillation, often abbreviated KD, covered in depth in the distillation lesson.

The idea: take a large model (the teacher, here BERT) and train a small one (the student) to imitate it.

The trick: the student does not copy the hard answers (the class finally predicted). It learns the teacher's full probability distribution. Example, on a binary classification (spam / legitimate):

SourcePrediction
BERT (teacher)78% spam, 22% legitimate
Hard answer (the maximum)SPAM
DistilBERT (student) learns"BERT is not certain: it says 78%."

These softened probabilities carry information that the hard answer throws away. If BERT hesitates between "cat" and "dog", that hesitation encodes how close those concepts are, a far richer signal than a single label.

Concretely, DistilBERT is distilled during pre-training, with a loss made of three pieces (see loss functions): the usual MLM term, a distillation term pulling the student's distribution toward the teacher's, and a cosine-distance term that also aligns the two models' internal vectors. The distillation term is written with the KL divergence (Kullback-Leibler, a measure of how far apart two probability distributions are, detailed in KL divergence).

The numbers the paper actually claims

The DistilBERT abstract gives three figures, and they are the only ones to carry away: the model is 40% smaller, 60% faster, and retains 97% of BERT's language-understanding capabilities. That last figure concerns GLUE-style comprehension tasks, it is not a guarantee on arbitrary tasks.

Translated into architecture: 6 layers instead of 12, roughly 66 million parameters instead of 110. Checking the "40% smaller": 66 / 110 = 0.6, so 60% of the model remains and 40% is gone. In memory, 66 million x 4 bytes ≈ 264 MB instead of 440.

The "60% faster" is a ratio of times, not an absolute latency: if BERT takes 100 ms on a given machine, DistilBERT will take about 40 ms on that same machine. The absolute figure depends entirely on hardware and text length, and does not transfer from one setting to another.

That is the right balance point for industrial deployment.

Distillation: a universal technique

The principle applies to any model. TinyBERT pushes compression further still (a 4-layer variant), and distilling a large model into a small one is now routine model compression, generative models included.

When to use distillation

A distilled model earns its place when latency or memory is the binding constraint: phone, embedded device, very high-volume service. In exchange you accept some quality loss, a few points on comprehension tasks, per the paper. On a task where two points of accuracy change the decision (diagnostic support, say), keep the full model. There is no right answer in the abstract: there is the cost of an error, weighed against the cost of compute.

Summary table

ModelInnovationSizeReported GLUE average
RoBERTa-largeTraining recipe355M88.5 (test)
ALBERT-xxlargeFactorization + weight sharing235M89.4
DeBERTa-largeDisentangled attention~350M90.0
DistilBERTDistillation66M97% of BERT-base's capabilities

Why this matters

Each variant teaches a different lesson:

  • RoBERTa: training better (recipe, data, duration) can beat architectural innovation.
  • ALBERT: parameter count can be cut hard through factorization and weight sharing, but compute time cannot.
  • DeBERTa: a fine refinement of attention, here separating meaning from position, genuinely pays.
  • DistilBERT: a smaller model trained to imitate a larger one keeps most of its comprehension ability.

These four lessons are the standard toolkit for deploying a model: how to train it well, can weights be shared, can the architecture be refined, can it be distilled. The same questions recur, transposed, in more recent methods such as LoRA (Low-Rank Adaptation) and quantization.

A word on dating, as of July 2026. For generating text, these models have been thoroughly superseded by today's large instruction-tuned decoder-only models. But for targeted comprehension (classifying, extracting, scoring a similarity, feeding a semantic search) BERT-family encoders are still widely in production: they are small, fast and cheap, which is exactly the job description. RoBERTa and DeBERTa are no longer the state of the art among encoders, having been displaced by encoders trained with more recent recipes, but the role they play inside a system has not changed.

Check your understanding0 / 4

1. What did RoBERTa change in BERT's architecture to beat it by about 8 points on GLUE?

2. ALBERT shares a single set of weights across its 12 layers. What does that improve, and not improve?

3. How does ALBERT's SOP fix the flaw of BERT's NSP?

4. In DistilBERT's distillation, what exactly does the student learn from the teacher?