Paper commentary
ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators
- Problem Masked language model pre-training trains only on the roughly 15% of tokens that are masked, so each example gives a weak learning signal.
- Method Replaces some tokens with plausible samples from a small generator and trains a discriminator to flag each replaced position, so every token contributes to the loss.
- Results ELECTRA-Small reached a 79.9 GLUE dev score after 4 days on one V100 GPU, 5 points above a comparable BERT model.
Why masked prediction is expensive
Masked language modeling, as used by BERT, hides a small subset of the input tokens, typically about 15%, and trains the network to recover them. Only the hidden positions produce a direct training target, so the rest of the sequence serves mainly as context for those predictions. Because most tokens give no direct signal, this family of methods needs a large amount of compute before it works well.
The authors also point to a train-test mismatch: BERT's artificial mask tokens appear during pre-training but not when the model is fine-tuned, a problem they say XLNet does not share.
Replaced token detection with a generator and a discriminator
The approach trains two networks, a generator and a discriminator, and each is built from an encoder such as a Transformer that maps the token sequence to contextual vectors. The generator uses a softmax over the vocabulary at each position, so its output for a token is a probability, written as \\( p_G(x_t \\mid x) \\) in the paper's notation.
The discriminator uses a sigmoid output at each position, giving \\( D(x,t)=\\mathrm{sigmoid}(w^{T}h_D(x)_t) \\), which is its estimated probability that the token is original.
The generator first masks a set of positions \\( m \\), with the number of masked positions set to about 15% of the sequence length, and fills those positions with tokens it samples. The discriminator then receives this corrupted sequence and must decide, at every position, whether the token matches the original input. A sampled token that happens to equal the original is counted as real, and the authors found this choice moderately improves downstream results.
The generator is trained with the masked language modeling loss, while the discriminator uses a binary log loss summed over all positions of the input. The two losses are minimized together over the corpus, as \\( \\min_{\\theta_G,\\theta_D} \\sum_{x\\in X} L_{MLM}(x,\\theta_G) + \\lambda L_{Disc}(x,\\theta_D) \\), and the discriminator loss is not backpropagated into the generator because the sampling step blocks that path.
Although the setup resembles a GAN, the generator is trained by maximum likelihood rather than adversarially, and it receives no noise vector.
After pre-training, the generator is discarded and only the discriminator, which is the ELECTRA model, is fine-tuned on downstream tasks.
Benchmarks and pre-training data
GLUE covers entailment, paraphrase, question paraphrase, textual similarity, sentiment and linguistic acceptability tasks. Spearman correlation is used for STS, Matthews correlation for CoLA, and accuracy for the other GLUE tasks, with the average taken over all tasks. SQuAD is evaluated in version 1.1, where the model selects an answer span, and version 2.0, where some questions cannot be answered, using Exact-Match and F1.
Most experiments pre-train on the BERT corpus of 3.3 Billion tokens from Wikipedia and BooksCorpus. The Large model is pre-trained on the XLNet data, which extends the BERT corpus to 33B tokens with ClueWeb, CommonCrawl and Gigaword, and all pre-training and evaluation is on English data.
For GLUE the authors add simple linear classifiers on top of ELECTRA, and for SQuAD they add the XLNet question answering module, which predicts start and end positions jointly and includes an answerability classifier for SQuAD 2.0. Because some evaluation sets are small, each dev result is the median of 10 fine-tuning runs from the same pre-trained checkpoint, since accuracy can vary with the random seed.
Generator size and weight sharing
Tying every transformer weight requires the generator and discriminator to be the same size, so the authors preferred a smaller generator that shares only its embeddings with the discriminator. The generator's token embeddings are tied to its output softmax as in BERT, and those embeddings are sized to the discriminator's hidden states.
With generator and discriminator at equal size, trained for 500k steps, GLUE scores were 83.6 with no weight tying, 84.3 with tied token embeddings and 84.4 with all weights tied. The authors reason that masked language modeling densely updates every token embedding through the generator softmax, while the discriminator only updates tokens that appear in the input or were sampled.
Tying all encoder weights gave little extra gain and forced equal sizes, so tied embeddings were used in the later experiments.
In the generator size study, the discriminator size was held fixed and the generator's layer sizes were reduced, with all models trained for 500k steps. A simple unigram generator, which samples tokens by their frequency in the training corpus, was also tested. Models worked best with generators 1/4-1/2 the size of the discriminator, and the authors suggest that a stronger generator makes the discriminator's task too hard.
The left panel of Figure 3 plots GLUE score against generator size for several discriminator sizes.
Joint, two-stage and adversarial training
The two-stage variant first trains the generator alone with the masked language modeling loss, then copies its weights into the discriminator and trains the discriminator with the generator frozen. The copy step needs the two networks to have the same size.
Without the weight copy, the discriminator sometimes failed to learn beyond the majority class, which the authors link to the generator getting far ahead of it. Joint training gives a natural curriculum because the generator starts weak and improves throughout training.
Two-stage training notably improved downstream performance after the switch to the discriminative objective, but it did not end up outscoring joint training.
The adversarial variant trains the generator with reinforcement learning, because sampling is discrete and gradients cannot pass through it. Its generator reached 58% accuracy on masked language modeling, against 65% for the maximum-likelihood generator, and the authors attribute the gap mainly to the poor sample efficiency of reinforcement learning in a large action space.
The adversarial generator also produced a low-entropy distribution that concentrates most probability mass on one token, which gives little diversity in its samples.
Small-model GLUE results
ELECTRA-Small starts from BERT-Base hyperparameters with a shorter sequence length of 128 instead of 512, a batch size of 128 instead of 256, a hidden size of 256 instead of 768 and token embeddings of 128 instead of 768. The BERT-Small comparison model uses the same hyperparameters and is trained for 1.5M steps, which gives it the same training FLOPs as ELECTRA-Small trained for 1M steps.
BERT-Small, with the same compute, scored 75.1, and ELMo, which the table lists with a larger training FLOP count of 3.3e18, scored 71.2. The table also shows that shorter runs still gave reasonable scores, with 74.1 after 6 hours and 76.0 after 12 hours on one V100 GPU. Table 1 lists these small-model comparisons on the GLUE dev set, with inference FLOPs assumed for a single length-128 input.
The base-sized ELECTRA reached 85.1 on GLUE dev after 4 days on 16 TPUv3s, against 82.2 for BERT-Base trained under the same conditions. The authors also note that ELECTRA-Base outperforms BERT-Large, which gets an 84.0 GLUE score.
Large-model GLUE dev results
ELECTRA-Large has the same size as BERT-Large and was trained with a batch size of 2048 on the XLNet data, for 400k steps in ELECTRA-400K and for 1.75M steps in ELECTRA-1.75M. The authors also trained their own BERT-Large with the same hyperparameters and training time as ELECTRA-400K, and that baseline scored notably below RoBERTa-100K.
ELECTRA-400K averaged 89.0 on GLUE dev, close to RoBERTa-500K at 88.9 and XLNet at 89.1, and RoBERTa-100K scored 87.9. ELECTRA-400K took less than 1/4 of the compute of RoBERTa and XLNet, which the authors present as evidence that the sample-efficiency gains hold at large scale.
ELECTRA-1.75M averaged 89.5, above RoBERTa-500K at 88.9 and XLNet at 89.1, and used less pre-training compute than either of them. Table 2 shows the per-task scores, and ELECTRA-1.75M outscores the two baselines on most GLUE tasks.
GLUE test-set results
On the GLUE test set, the fully trained ELECTRA-1.75M reached a leaderboard Score of 89.4, against 88.1 for RoBERTa-500K, and XLNet's average excluding QNLI is 89.1. These comparisons are less direct because several compared models use extra tricks such as ensembling, as Table 3 notes.
SQuAD results
Table 4 lists the non-ensemble results, and ELECTRA-1.75M is the only ELECTRA model reported for the test set.
The authors note that ELECTRA-Base also surpasses BERT-Large on most metrics, and that ELECTRA generally does better on SQuAD 2.0 than on 1.1.
The authors suggest that discriminating real tokens from plausible fakes may transfer well to the answerability classification in SQuAD 2.0, which is a hypothesis they did not test directly.
Where the efficiency gains come from
ELECTRA 15% keeps the ELECTRA setup but computes the discriminator loss only over the 15% of tokens that were masked out. Replace MLM keeps masked language modeling but fills the masked positions with generator tokens instead of [MASK]. All-Tokens MLM also uses generator replacements, but predicts the identity of every input token and uses a copy mechanism that mixes the input token with the MLM softmax output.
Restricting the discriminator loss to the masked 15% lowers the GLUE score from 85.0 for ELECTRA to 82.4. Replace MLM reached 82.4, slightly above BERT at 82.2, and All-Tokens MLM reached 84.3, closing most of the gap between BERT and ELECTRA. Table 5 summarizes these four objectives together with ELECTRA and BERT on the GLUE score.
The authors conclude that a large part of ELECTRA's improvement comes from learning over all tokens, with a smaller part from reducing the pre-train and fine-tune mismatch. Since All-Tokens MLM still trails ELECTRA, the authors argue that the gain is more than faster training.
Figure 4 compares BERT and ELECTRA across hidden sizes from 128 to 768, and the gap in GLUE score grows as the models get smaller. The right panel shows a small ELECTRA model converging to higher downstream accuracy than BERT, which the authors use to argue that the improvement is not only faster training. The authors speculate that ELECTRA is more parameter-efficient because it does not model the full token distribution at each position, though they say more analysis is needed.
Relation to GANs and contrastive learning
The discriminator idea is borrowed from GANs, but the generator is trained by maximum likelihood, and the authors note that GANs are hard to apply to text. The generator is said to resemble MaskGAN, which trains a generator to fill in deleted tokens, though ELECTRA does not use adversarial learning.
ELECTRA is closely related to noise-contrastive estimation, which also trains a binary classifier to separate real from fake data. The authors describe ELECTRA as a much larger version of CBOW with negative sampling, but CBOW uses a bag-of-vectors encoder and a proposal distribution based on unigram frequencies rather than a learned generator.
Distillation methods such as TinyBERT and MobileBERT focus on inference speed, whereas ELECTRA is aimed at pre-training speed and trains ELECTRA-Small from scratch.
Limits of the evidence
Small evaluation sets make the fine-tuned accuracy depend on the random seed, so dev results are medians over 10 runs rather than single runs. Training times in Table 1 come from different hardware and sometimes un-optimized code, so they are rough guides only.
The GLUE test comparisons use models with additional tricks such as ensembling, so they are less direct than the dev comparisons. The XLNet data is similar to the RoBERTa data, but the comparison between them is not entirely direct.
All pre-training and evaluation is on English data, and applying the method to multilingual data is left for future work. The parameter-efficiency explanation is a hypothesis that the authors state needs more analysis.
Paper info
- Authors
- Kevin Clark, Minh-Thang Luong, Quoc V. Le, Christopher D. Manning
- Venue
- arXiv · Preprint
- First published
- 2020-3-23
- Added
- 2026-10-20
- Updated
- 2020-3-23
- Version
- v1
- arXiv
- 2003.10555
- Category
- cs.CL
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Kevin Clark, Minh-Thang Luong, Quoc V. Le, Christopher D. Manning (2020). ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators. arXiv:2003.10555v1. https://arxiv.org/abs/2003.10555v1
BibTeX
@misc{clark2020electra,
title = {{ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators}},
author = {Kevin Clark and Minh-Thang Luong and Quoc V. Le and Christopher D. Manning},
year = {2020},
eprint = {2003.10555},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2003.10555v1}
}