XLNet is a pretrained language model that can use both left and right context by training an autoregressive language model over randomly permuted orders of predicting the words in a sentence. It was proposed in 2019 by Yang et al. of Carnegie Mellon University and Google. Its architecture is Transformer-XL, which can handle long contexts.
XLNet aims to combine the strengths of the two earlier kinds of pretraining:
- Autoregressive language models (GPT and others): predict the next word from the preceding words, one by one. They correctly learn dependencies between words in the form of a product of probabilities, but each word sees only one side (the left) of the context.
- Denoising autoencoders (BERT and others): replace some words with
[MASK]and restore them. They can use both left and right context, but they predict the masked words as if they were independent of each other, and they use[MASK], which never appears in real input, during pretraining, so the input looks different between pretraining and fine-tuning.
XLNet trains a permutation language model that makes autoregressive predictions in a permuted order of the words. It uses no [MASK] and can still learn dependencies among the predicted words. On top of that, it incorporates two-stream attention, which tells the model which position to predict, and Transformer-XL's segment memory and relative positional encoding.
In the paper, even when trained on the same data with the same settings as BERT, XLNet outperformed BERT on all 11 tasks from SQuAD, RACE, and GLUE. With more data, it outperformed BERT on 20 tasks, including 85.4% accuracy on the RACE reading comprehension task (RoBERTa: 83.2%).

