- Year of appearance
- 2019
- Researchers
- Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le
- Organisation
- Carnegie Mellon University, Google Brain
- Architecture type
- Autoregressive Transformer-XL encoder
- Learning mechanism
- self-supervised
- Tasks
- Text classification, Question answering
An autoregressive pre-training model that maximises the expected likelihood over all permutation orders of the sequence, so it gets bidirectional context without a [MASK] token.
Architecture diagram
Displayed configuration: XLNet-base: L = 12, d = 768, 12 heads — A Transformer-XL encoder with two-stream attention.
Layer table (7 nodes)
| Layer | Type | Input | Output | Repetition | Parameters | Formula | MACs |
|---|---|---|---|---|---|---|---|
| Tokens | input | 128 | 1 | 0 | — | ||
| Token embedding 32,000 × 768 | embed | 1 | 1 × 768 | 1 | 24,576,000 | From the reference PyTorch implementation | 0 |
| Previous segment memory (Transformer-XL) | state | m × 768 | 1 | 0 | — | ||
| Two-stream relative attention | mha | 1 × 768 | 1 × 768 | 12 | 2,954,496 | From the reference PyTorch implementation | 503,316,480 |
| FFN with GELU + Add & Norm | ffn | 1 × 768 | 1 × 768 | 12 | 4,723,968 | From the reference PyTorch implementation | 603,979,776 |
| Representations / token probability in the permutation order | output | 128 × 768 | 128 × 768 | 1 | 0 | — | |
| Mask vector (mask_emb) | token | 768 | 1 | 768 | 1 × 1 × 768 | — |
Configuration figures: XLNet-base: L = 12, d = 768, 12 heads
- Input shape
- n tokens (+ memory)
- Output shape
- n × 768
- Depth
- 12 layers
- Complexity
- O(L·(n·(n+m)·d + nd²)).
- MACs note
- For a sequence n = 128 without previous memory (content stream only at inference).
MAC = a multiplication followed by an addition. The figures are for one forward pass of one sample with the stated dimensions; they are an analytical calculation, not a measurement of run time.
Scientific explanation
Historical background
Published at NeurIPS 2019; it outperformed BERT on 20 tasks at the time, and relied on Transformer-XL to handle long contexts.
The problem it addresses
BERT assumes the masked tokens are independent and uses [MASK], which is absent during fine-tuning, while autoregressive models see only one direction.
Core idea
Permutation language modelling: for each random order the token is predicted from the tokens that precede it in that order, with two-stream attention so the model knows the target position without its content.
Architecture description
Transformer-XL (relative attention and segment memory) with a content stream and a query stream that share weights.
Data flow
Tokens → embedding → 12 layers of two-stream relative attention → prediction of the last tokens in the permutation order.
Inputs
A sequence of SentencePiece tokens with optional memory.
Outputs
Contextual representations.
Training procedure
Pre-training on about 33 billion tokens, predicting the last 1/K of the tokens in each order to reduce the cost.
Loss functions
The expected log likelihood over permutations.
Computational complexity
O(L·(n(n+m)d + nd²)) with memory m.
Computational requirements
The large version was trained on 512 TPU v3 chips for about 5.5 days.
Advantages
- Bidirectional context without [MASK]
- Long contexts through memory
- Strong results in 2019
Limitations
- High implementation complexity
- Costly training
- Outperformed by RoBERTa with simpler procedures
Equations
Permutation language modelling objective Permutation language modeling
\max_\theta \; \mathbb{E}_{\mathbf{z} \sim \mathcal{Z}_T}\left[\sum_{t=1}^{T} \log p_\theta\left(x_{z_t} \mid \mathbf{x}_{\mathbf{z}_{\lt t}}\right)\right]z is a random permutation order of the sequence positions.
Symbols: Z_T: all permutations of length T
Two-stream attention Two-stream attention
\begin{aligned} g_{z_t}^{(m)} &\leftarrow \operatorname{Attention}\big(Q = g_{z_t}^{(m-1)},\, KV = \mathbf{h}_{\mathbf{z}_{\lt t}}^{(m-1)}\big) \\ h_{z_t}^{(m)} &\leftarrow \operatorname{Attention}\big(Q = h_{z_t}^{(m-1)},\, KV = \mathbf{h}_{\mathbf{z}_{\le t}}^{(m-1)}\big) \end{aligned}The query stream does not see the content of the token it predicts.
Symbols: g: query stream, h: content stream
Applications
Related models
- Built on Transformer — Built on Transformer-XL. Compare
- Alternative BERT (Bidirectional Encoder Representations from Transformers) — An alternative to MLM. Compare
- GPT (Generative Pre-trained Transformer) — Autoregressive like GPT. Compare
- Alternative RoBERTa (Robustly Optimized BERT Pretraining Approach) — The two competed in 2019. Compare
References
- Original paper Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le. (2019). XLNet: Generalized autoregressive pretraining for language understanding. NeurIPS 2019. arXiv:1906.08237 Verified
Version 1 — last updated 2026-11-15.
