XLNet: Generalized Autoregressive Pretraining for Language Understanding
- Publication
- NeurIPS 2019Conference
- First submitted to arXiv
- arXiv:1906.08237
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{transformersxlnet2019,
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.08237}
}
BERT’s success provided a lot of inspiration for further research in language models.
Earlier in 2019, the authors of this paper had already published Transformer-XL, a novel Transformer architecture that was capable of capturing long-range dependencies.
But apparently that still was not enough for the authors: Transformer-XL used a fixed prediction direction in pretraining, so a position could not learn from both its left and right context in the same factorization. XLNet changes the prediction order.
Defining the Problem
The paper compares two main pretraining objectives: autoregressive (AR) modeling and denoising autoencoding (AE).
BERT is a representative of autoencoding models, while GPT is an example of autoregressive models. Each has its pros and cons.
-
Autoregressive Models
Autoregressive models use a self-supervised training method that involves predicting the next word in a sequence, similar to a “language completion” task.
Given a sequence of words , an autoregressive language model maximizes the likelihood by a forward autoregressive factorization:
where is a contextual representation generated by a neural network, and represents the embedding of a word.
Left-to-right factorization restricts each position to its left context during pretraining. That limits bidirectional token representations.
-
Autoencoding Models
BERT uses masked language modeling (MLM) for denoising pretraining: it reconstructs selected target words from a corrupted sequence . The paper simplifies the corruption as
[MASK]; in actual BERT training only some selected positions receive that symbol. Its objective is written as:In the paper's simplified notation, marks a prediction target, and is the Transformer's representation at position for the corrupted input. The marks the approximation that predicts selected targets separately.
MLM uses the retained context on both sides. XLNet highlights two limitations: ordinary downstream fine-tuning does not use
[MASK], and targets in the same masking pattern are predicted separately rather than linked by an autoregressive factorization. This concerns the objective, not an inherent inability of Transformer architecture to model a joint distribution.
The authors therefore kept autoregressive factorization while letting each position learn from words on both sides across different sampled orders:
This model is XLNet!
Solving the Problem
Permutation Language Modeling
Permutation language modeling trains the same sentence under different factorization orders. Each prediction sees only positions preceding it in the sampled order; across orders, those positions can come from either side of the original sentence.
For a simplified six-position sentence such as “The cat sat on the mat,” there are theoretically orders in which to factorize its probability. The sentence itself remains in its original input order:
Original positions: 1 2 3 4 5 6
Factorization order 1: 3 → 5 → 4 → 6 → 2 → 1
Factorization order 2: 4 → 1 → 6 → 5 → 2 → 3
The permutation determines the order of conditional predictions. Training samples an order and uses an attention mask to control the positions visible to each target. It does not shuffle the sentence into a new, ungrammatical input.
Let represent the set of all possible permutations of an index sequence of length . The objective of permutation language modeling can be written as:
Two-Stream Self-Attention
In the paper's Figure 1(c), the four input positions stay in order 1, 2, 3, 4 while the sampled factorization order is 3 → 2 → 4 → 1. The two matrices on the right control the content and query streams; they are not two shuffled sentences.
To implement permutation language modeling, the authors introduce a Two-Stream Self-Attention mechanism.
This is also why relative positions still refer to the original sentence. Only the factorization order changes; masks control visible content, while fine-tuning continues to use natural word order.
For example, given a sequence , the prediction order might be .
The factorization defines each conditional probability, while masks let the model compute positions in parallel instead of sampling its own answers one at a time.
Why two streams? If a representation contains only the visible context, identical context with two different target positions would produce the same prediction distribution. The model must know which original position it is predicting without seeing that position's word.
The two streams in this mechanism refer to two types of hidden states:
-
Content Stream
The content stream uses content up to step in the chosen factorization, , including itself. It cannot access arbitrary later tokens in that order.
Self-attention updates are constrained by the permutation mask. The content stream supplies context for later predictions; its representation containing the answer is not used directly to predict itself.
In the figure, position 1 is last in the factorization, so its content-stream Q is and its K/V can include positions 1, 2, 3, 4. For A, B, C, D with factorization C → B → D → A, C's content state sees C, while B's sees C and B.
-
Query Stream
The query stream knows which position to predict but cannot access its token content. The target position is necessary information; the answer is what must remain hidden.
The query stream uses preceding content and target position , excluding . Thus the figure's takes K/V from , not . Its initial state is a learned vector . The final query state predicts the word; for fine-tuning, the query stream can be discarded and the content stream used as a regular Transformer.
Predicting every position converged slowly in preliminary experiments. Partial prediction selects the last part of the sampled order, giving targets longer visible context. The fraction is about ; the large model uses . Query states for unselected positions need not be computed, saving some memory and computation.
XLNet also takes Transformer-XL's relative positional encoding and segment-level recurrence. It caches content-stream states from the previous segment; both streams in the next segment can attend to those states as additional K/V. Positions still refer to the original sequence, so the previous segment's sampled factorization need not be reconstructed to use its cache. For multi-segment input, relative segment encoding indicates whether two positions belong to the same segment. Pretraining can use [CLS, A, SEP, B, SEP], but the large model does not use a next-sentence prediction objective.
Revisiting Partial Prediction Mechanism
The toy equations below omit masks and position markers; actual BERT inputs still identify the masked positions.
Selecting only some targets sounds like BERT. The key question is whether those targets can condition one another.
If BERT hid every word, little useful context would remain. XLNet instead selects the end of a factorization to ease optimization. Both predict only some positions, but they differ in whether one selected target can condition a later selected target in the same objective.
For instance, in the sentence "New York is a city," the model might predict only "New" and "York".
-
BERT’s Problem: Independence Assumption
For one MLM corruption, target losses are summed as conditionally independent predictions given the corrupted input. Other masking patterns expose one word in “New York” as context for the other, allowing BERT to learn their relationship.
In this example, BERT's simplified objective is:
For this one corruption selecting both words, each loss sees only “is a city.” Under other masks, BERT can still use one word as context for the other.
-
XLNet’s Advantage: Capturing Dependencies
XLNet conditions later targets on earlier ones in the factorization. Training uses ground-truth tokens (teacher forcing), not sampled predictions fed back into the model, and attention masks allow positions to be computed in parallel.
Suppose the sampled factorization order is “is → a → city → New → York”:
XLNet’s objective can be written as:
In this factorization, the prediction of “York” can use the earlier ground-truth “New.” XLNet therefore explicitly conditions one selected target on another within the same factorization.
The paper calls this a “denser” effective training signal for a fixed target set. That describes the conditional dependency in the objective, not a guaranteed improvement in tokens per step or quality on every task.
Discussion
Fair Comparison with BERT
The paper's Table 1 keeps BooksCorpus/Wikipedia and BERT pretraining hyperparameters fixed so extra pretraining data does not explain this comparison. The BERT row reports the best result for each task among three variants; it is not one model's score across the row.
XLNet-Large-wikibooks exceeds those per-task BERT best scores in all eleven columns: RACE 75.1→77.4 and RTE 74.0→81.2, for example, while SST-2 changes only 94.0→94.4. The table supports gains in these tasks but does not isolate the causal contribution of each architecture component.
Comparison with RoBERTa
Following the release of this paper, other pretraining models like RoBERTa and ALBERT emerged.
The authors scale up pretraining data and reuse some RoBERTa hyperparameters for closer comparison, although the corpora differ. Table 2 reports RACE test accuracy 85.4 for XLNet versus RoBERTa's 83.2; for document ranking, XLNet has 31.10 NDCG@20 versus the listed BERT's 30.53, with no RoBERTa score. In Table 3, SQuAD 2.0 dev F1 is 90.6 versus 89.4; the SQuAD 1.1 XLNet test entry is from an older model. Table 4 reports error rates, such as IMDB 3.20 versus the listed BERT 4.51, and has no RoBERTa row. In the upper, single-model dev half of Table 5, XLNet's RTE 85.9 and MRPC 90.8 trail RoBERTa's 86.6 and 90.9. The lower half reports test leaderboard ensembles, with † marking XLNet single-task exceptions; it should be read separately.
Two key observations stand out:
- The authors observe larger gains on longer-context tasks such as SQuAD and RACE and suggest that the Transformer-XL backbone may contribute. Cross-model tables alone do not isolate that cause.
- They also report gains for MNLI (over 390K supervised examples), Yelp (over 560K), and Amazon (over 3M). Table 4 reports classification error rates, whose direction is opposite to GLUE scores.
Ablation Study
The paper's Table 6 tests the objective, backbone, and several training choices with matched model size and data.
The table above compares six different variants of XLNet-Base (rows 3 to 8), the original BERT-Base (row 1), and a Transformer-XL-based model using BERT’s denoising autoencoding objective but with bidirectional input (row 2).
All models use the same 12-layer architecture and hyperparameters as BERT-Base and are trained on Wikipedia and BooksCorpus datasets, with results being the median of five runs.
-
The Advantage of Permutation Language Modeling and Transformer-XL (comparing rows 1 to 4):
Rows 1–4 support contributions from both the permutation objective and the Transformer-XL backbone, but not a gain in every configuration and metric. SST-2 is 92.66 for , slightly below BERT’s 92.78; reaches 93.35.
-
The Importance of Memory Caching (row 5):
Against the baseline in row 4, removing memory changes RACE 66.66→65.55 and SQuAD 2.0 F1 80.98→80.15. It helps in these longer-context settings.
-
The Role of Contiguous-Token-Span Prediction and Bidirectional Input (rows 6 and 7):
Span-based prediction selects a consecutive span of tokens as targets. Removing it changes RACE 66.66→65.95; removing bidirectional data input gives 66.34. Most other reported metrics also fall, under this specific training setup.
-
The Impact of Next Sentence Prediction (row 8):
Adding next-sentence prediction changes RACE 66.66→66.76, but SQuAD 2.0 F1 80.98→79.83 and SST-2 93.35→92.89. Its benefits are inconsistent, so the final large model omits it; it does not worsen every measure.
Conclusion
XLNet carries forward the strengths of Transformer-XL and introduces a permutation language modeling objective. It retains autoregressive conditioning while learning from context on both sides across sampled orders. Under the matched conditions of Table 1, it beats the listed BERT variants; it also fares well against the later models across many reported tasks, especially some longer-context ones. Those broader comparisons still depend on their data and evaluation settings.
It became a strong choice for many language tasks and gave researchers another way to think about pretraining. Looking back at 2019, XLNet felt like the strongest LM architecture around.