Paper commentary
XLNet: Generalized Autoregressive Pretraining for Language Understanding
XLNet pretrains language models on random word orders to capture bidirectional context
- Problem Autoregressive pretraining reads text in one direction only, and BERT's masking ignores dependencies between masked tokens and causes a pretrain-finetune mismatch. Both limit how well models understand language.
- Method XLNet keeps the autoregressive objective but samples a random factorization order for each sequence. Each token is predicted from the tokens before it in that order, so context comes from both sides.
- Results XLNet scored 85.4 on the RACE test set, compared to 83.2 for RoBERTa.

Figure 6 : A detailed illustration of the query stream of the proposed objective with both the joint view and split views based on a length-4 sequence under the factorization order [3, 2, 4, 1]. The dash arrows indicate that the query stream cannot access the token (content) at the same position, but only the location information.
Original paper · CC BY 4.0 · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · Original paper figure · Extracted the figure area from page 18 of the original PDF.Why autoregressive and masked pretraining each fall short
Pretraining a network on unlabeled text and then fine-tuning it has become the default route to strong language understanding. Two objectives have led this line of work: autoregressive (AR) language modeling and autoencoding (AE). AR modeling turns the likelihood of a sequence into a chain of conditionals, read either left to right or right to left.
Each conditional sees only one side of the sentence, so the model struggles with the deep bidirectional context that understanding tasks often need.
AE pretraining takes a different route and skips explicit density estimation. BERT replaces about 15% of the input tokens with a [MASK] symbol and learns to recover the original tokens. The cost is that [MASK] never appears in real text at fine-tuning time, which creates a pretrain-finetune discrepancy. BERT also treats the masked tokens as independent of each other given the visible ones, which misses dependencies such as the link between New and York.
Permutation language modeling: AR training over random orders
The core idea is to keep the autoregressive factorization but draw a random order for each training sequence, so each token can condition on tokens from both its left and its right. Averaged over sampled orders, every position eventually conditions on every other position, and that is how the objective captures bidirectional context.
With z as a permutation of the index sequence 1 to T, the training objective is \( \max_\theta \mathbb{E}_{z\sim Z_T}[\sum_{t=1}^{T}\log p_\theta(x_{z_t}\mid x_{z_{<t}})] \). Here z_t is the position predicted at step t, and z_{<t} holds the first t minus 1 positions, so each term predicts one token from the tokens earlier in the sampled order.
The same parameters are shared across all orders, so the model learns from every factorization it sees during training.
The sequence itself is never reshuffled, and positional encodings still follow the original word positions. A proper attention mask inside the Transformer enforces the sampled order instead. This matters because fine-tuning only sees text in natural order, so training on shuffled text would create a mismatch. Figure 4 shows how the same input gives different visible context for predicting x3 under different factorization orders.
Because the objective stays autoregressive, the product rule supplies the joint probability of the predicted tokens without an independence assumption.
Two streams for target-aware prediction
Plugging the objective into a standard Transformer exposes a flaw. A standard Softmax head reads a hidden state that depends only on the context before the target, so every target position gets the same distribution. The authors fix this by making the next-token distribution aware of the target position.
The output scores each vocabulary embedding against a representation g that also takes the target position z_t as input. Building g is the hard part, because two requirements pull in opposite directions. To predict the token at z_t, g may use the position but not the token's content, otherwise the objective becomes trivial. To predict later tokens, however, g has to encode the content at z_t so that those tokens get the full context.
The solution is two sets of hidden states, a content representation h and a query representation g. The content representation encodes both the context and the token at the current position, while the query representation sees the context and the position only. The first query stream starts from a trainable vector, and the content stream starts from the word embeddings.
At each self-attention layer m, the query stream attends to the content states of earlier positions, \( g_{z_t}^{(m)} \leftarrow \mathrm{Attention}(Q = g_{z_t}^{(m-1)}, KV = h_{z_{<t}}^{(m-1)}) \), and the content stream attends to positions up to z_t.
After pretraining, the query stream is dropped, so fine-tuning uses the content stream as an ordinary Transformer-XL. The last-layer query representation feeds the target-aware output distribution used in the pretraining loss.
Predicting only the tail and reusing memory
Optimizing over all random orders is slow, and preliminary runs converged slowly. To ease this, the authors predict only the last tokens of each factorization order.
The sequence is split at a cutting point c into a non-target part z_{<=c} and a target part z_{>c}, and the objective maximizes the likelihood of the target part given the non-target part. A hyperparameter K keeps about 1/K of the tokens as targets, so the ratio of the sequence length to the number of non-target tokens is about K. Query representations are skipped for unselected tokens, which saves time and memory.
For XLNet-Large, K is set to 6. Fine-tuning follows BERT, except that the authors use span-based prediction, sampling a span length L between 1 and 5.
Segment recurrence borrows the Transformer-XL idea of reusing earlier states. The content representations of the previous segment are cached for each layer, and the next segment attends over them concatenated with its own states. Because positional encodings depend only on the original positions, the cached memory doesn't depend on the sampled order of the previous segment.
Same data and recipe as BERT
The authors train XLNet-Large-wikibooks on BooksCorpus and Wikipedia only, reusing the original BERT hyperparameters. This removes the extra data from the comparison, so the remaining difference reflects the training recipe.
Table 1 compares this model with the best of three BERT variants: the original, whole word masking, and no next sentence prediction. On SQuAD1.1, XLNet-Large-wikibooks scored 88.2/94.0 (EM/F1), compared to 86.7/92.8 for BERT-Large, and on RTE it scored 81.2, compared to 74.0.
XLNet-Large-wikibooks is higher than the best BERT variant in every column of Table 1. The authors use this to separate the effect of more data from the effect of the new objective.
Scaling up against RoBERTa and other baselines
The full run uses 32.89B subword pieces and 512 TPU v3 chips for 500K steps, with batch size 8192, taking about 5.5 days. Table 2 places XLNet beside RoBERTa, BERT and other systems, with all of them using a 24-layer architecture of similar size to BERT-Large.
On the RACE test set, XLNet scored 85.4 overall, compared to 83.2 for RoBERTa. The authors observe that gains are usually larger on reasoning tasks with longer context, such as SQuAD and RACE.
On ClueWeb09-B document ranking, XLNet scored 31.10 NDCG@20 and 20.28 ERR@20. The BERT row there is the authors' own implementation, which scored 30.53 and 18.67.
On the SQuAD2.0 dev set as a single model, XLNet scored an F1 of 90.6. That is compared to 89.4 for RoBERTa and 81.77 for BERT.
Which design choices carry the gains on XLNet-Base
The ablation uses a 12-layer XLNet-Base with BERT-Base hyperparameters, trained on Wikipedia and BooksCorpus only. Each reported result is the median of 5 runs.
Row 2 keeps the BERT denoising objective and adds Transformer-XL, while row 4 keeps that backbone and switches to the permutation objective. On RACE, the BERT-Base value of 64.3 comes from prior work, the Transformer-XL with denoising baseline scored 65.03, and XLNet-Base with K = 6 scored 66.66.
Removing the memory caching lowers RACE from 66.66 to 65.55, and RACE has the longest context of the four tasks. The gains are not uniform, since without memory SST-2 stays at 92.78, the same as BERT-Base.
Removing span-based prediction or the bidirectional input pipeline lowers both RACE and SQuAD2.0 F1, so the authors treat both as important. Adding next sentence prediction raises RACE from 66.66 to 66.76 but lowers SQuAD2.0 F1 from 80.98 to 79.83. Because of that trade-off, the authors leave next sentence prediction out of XLNet.
Limits of the evidence
XLNet-Large still underfits the data when training ends at 500K steps, according to the authors.
The ablations use a 12-layer XLNet-Base trained on Wikipedia and BooksCorpus, so their magnitudes come from a smaller setting than the full-data headline results.
ALBERT is left out of the comparison because its larger hidden size makes results hard to compare. The RoBERTa comparison reuses RoBERTa's hyperparameters on full data, so it is a comparison under that recipe only.
The authors suggest that larger gains on long-context tasks could come from the Transformer-XL backbone, which they present as a possibility.
Paper info
- Authors
- Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le
- Venue
- arXiv · Preprint
- First published
- 2019-6-19
- Added
- 2026-10-20
- Updated
- 2020-1-2
- Version
- v2
- arXiv
- 1906.08237
- Category
- cs.CL · cs.LG
- Original paper terms
- CC BY 4.0
- What we show
- Paper info, commentary and permitted figures from the original paper
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.
Abstract
With the capability of modeling bidirectional contexts, denoising autoencoding based pretraining like BERT achieves better performance than pretraining approaches based on autoregressive language modeling. However, relying on corrupting the input with masks, BERT neglects dependency between the masked positions and suffers from a pretrain-finetune discrepancy. In light of these pros and cons, we propose XLNet, a generalized autoregressive pretraining method that (1) enables learning bidirectional contexts by maximizing the expected likelihood over all permutations of the factorization order and (2) overcomes the limitations of BERT thanks to its autoregressive formulation. Furthermore, XLNet integrates ideas from Transformer-XL, the state-of-the-art autoregressive model, into pretraining. Empirically, under comparable experiment settings, XLNet outperforms BERT on 20 tasks, often by a large margin, including question answering, natural language inference, sentiment analysis, and document ranking.
Quote from the paper
Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le (2019). XLNet: Generalized Autoregressive Pretraining for Language Understanding. arXiv:1906.08237v2. https://arxiv.org/abs/1906.08237v2
BibTeX
@misc{yang2019xlnet,
title = {{XLNet: Generalized Autoregressive Pretraining for Language Understanding}},
author = {Zhilin Yang and Zihang Dai and Yiming Yang and Jaime Carbonell and Ruslan Salakhutdinov and Quoc V. Le},
year = {2019},
eprint = {1906.08237},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1906.08237v2}
}