# XLNet: Generalized Autoregressive Pretraining for Language Understanding

XLNet: 언어 이해를 위한 일반화된 자기회귀 pre-training

Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · arXiv · 2019년 6월 19일

- **연구 문제** BERT는 양방향 문맥을 쓰지만 \[MASK\] 기호로 인한 pre-training-미세조정 불일치와 예측 토큰 간 독립 가정이라는 한계가 있고, 기존 AR 모델은 한 방향 문맥만 봅니다. XLNet은 이 둘을 함께 피하려는 pre-training 방법입니다.
- **연구 방법** 인수분해 순서의 순열에 대한 기대 로그우도를 최대화하는 순열 언어 모델링과, 목표 위치를 반영하는 두 흐름 어텐션, Transformer-XL의 상대 위치 인코딩과 세그먼트 재귀를 결합합니다.
- **주요 결과** 데이터와 하이퍼파라미터를 BERT와 맞춘 비교에서 XLNet-Large-wikibooks는 BERT-Large보다 여러 과제에서 높은 점수를 보입니다. 절제 실험에서는 순열 목적과 Transformer-XL 구성이 BERT-Base 기준선 대비 성능 향상에 기여합니다.

## 자기회귀와 자기부호화 pre-training의 간극

pre-training 언어 모델은 대규모 비라벨 텍스트에서 표현을 배운 뒤 다운스트림 과제에 미세조정하는 방식으로 널리 쓰입니다. 이 논문이 비교하는 두 목적은 자기회귀(AR) 언어 모델링과 자기부호화(AE)입니다. AR 언어 모델은 한 방향의 문맥으로만 확률을 인수분해하므로, 독해나 추론처럼 양방향 문맥이 필요한 과제에 불리합니다. 반면 BERT로 대표되는 AE 방식은 입력 토큰의 일부를 \[MASK\]로 바꾸고 원래 토큰을 복원하므로 양방향 문맥을 활용합니다.

BERT에는 두 가지 한계가 있습니다. 첫째, pre-training에만 등장하는 \[MASK\] 기호 때문에 pre-training과 미세조정 사이에 입력 분포의 차이가 생깁니다. 둘째, 예측 대상 토큰들을 서로 독립이라고 가정하므로 토큰 사이의 고차원 의존성을 직접 모델링하지 못합니다. XLNet은 이 두 한계를 피하면서 AR 목적의 장점을 유지하는 방법을 목표로 합니다.

## 순열 언어 모델링 목적

XLNet의 핵심 목적은 순열 언어 모델링입니다. 길이가 T인 시퀀스에는 T!개의 인수분해 순서가 있으며, 각 순서에서 AR 분해를 수행합니다. 모델 파라미터를 모든 순서에서 공유하고 기대 로그우도를 최대화하면, 각 위치는 기대적으로 양쪽의 모든 위치에서 정보를 얻게 됩니다. 이 목적은 다음과 같습니다.

![Figure 4: Illustration of the permutation language modeling objective for predicting x3 given the same input sequence x but with different factorization orders](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5/figures/figure-65cc0534191144b23ace10115e1bb986.png?thumb=512)

**Figure 4** : Illustration of the permutation language modeling objective for predicting x3 given the same input sequence x but with different factorization orders.

[원문](https://arxiv.org/abs/1906.08237v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · 원문 그림 인용 · 원본 PDF 16쪽에서 그림 영역을 추출했습니다.

\\\[ \\max\_\\theta \\mathbb{E}\_{z\\sim Z\_T}\\left\[\\sum\_{t=1}^{T}\\log p\_\\theta(x\_{z\_t}\\mid x\_{z\_{\<t}})\\right\] \\\]

여기서 \\(z\\)는 길이 T 인덱스 순열 집합 \\(Z\_T\\)에서 샘플링한 인수분해 순서입니다. 중요한 점은 순열이 입력 시퀀스의 순서를 바꾸지 않는다는 것입니다. 원래 순서의 위치 인코딩을 유지하고, 어텐션 마스크로만 인수분해 순서를 구현합니다. 미세조정 때 모델은 자연 순서의 입력만 보기 때문에 이 선택이 필요하다고 저자들은 설명합니다.

## 목표 위치를 반영하는 두 흐름 어텐션

순열 목적을 표준 Transformer에 그대로 적용하면 문제가 생깁니다. 다음 토큰 분포를 \\(h\_\\theta(x\_{z\_{\<t}})\\)만으로 계산하면 이 표현은 예측할 위치 \\(z\_t\\)에 의존하지 않습니다. 따라서 서로 다른 목표 위치가 같은 분포를 예측하게 됩니다. 이를 해결하기 위해 논문은 목표 위치를 반영한 표현 \\(g\_\\theta(x\_{z\_{\<t}}, z\_t)\\)을 도입합니다.

이 표현은 두 가지 요구를 동시에 만족해야 합니다. \\(x\_{z\_t}\\) 자체를 보면 예측이 자명해지므로 질의 표현은 위치 \\(z\_t\\)만 사용해야 합니다. 그러나 뒤에 오는 토큰을 예측하려면 내용 정보도 필요합니다. 두 흐름 어텐션은 내용 표현 \\(h\\)와 질의 표현 \\(g\\)를 분리해 이 모순을 해결합니다. 레이어 \\(m\\)에서 두 흐름은 다음처럼 갱신됩니다.

\\\[ g^{(m)}\_{z\_t} \\leftarrow \\mathrm{Attention}\\left(Q=g^{(m-1)}\_{z\_t},\\ KV=h^{(m-1)}\_{z\_{\<t}}\\right) \\\] \\\[ h^{(m)}\_{z\_t} \\leftarrow \\mathrm{Attention}\\left(Q=h^{(m-1)}\_{z\_t},\\ KV=h^{(m-1)}\_{z\_{\\le t}}\\right) \\\]

![Figure 5: A detailed illustration of the content stream of the proposed objective with both the joint view and split views based on a length-4 sequence under t…](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5/figures/figure-15dc1b9a2ae7887d8f085a4d5d004a9f.png?thumb=512)

**Figure 5** : A detailed illustration of the content 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\]. Note that if we ignore the query representation, the computation in this ﬁgure is simply the standard self-attention, though with a particular attention mask.

[원문](https://arxiv.org/abs/1906.08237v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · 원문 그림 인용 · 원본 PDF 17쪽에서 그림 영역을 추출했습니다.

질의 흐름은 자기 위치의 내용을 보지 못하고, 내용 흐름은 일반적인 자기 어텐션과 같습니다. 미세조정 때는 질의 흐름을 버리고 내용 흐름만 일반 Transformer처럼 사용합니다.

![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…](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5/figures/figure-d4288afb01d9590cdc90d4beeb944c9f.png?thumb=512)

**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.

[원문](https://arxiv.org/abs/1906.08237v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · 원문 그림 인용 · 원본 PDF 18쪽에서 그림 영역을 추출했습니다.

## Transformer-XL 구조와 세그먼트 처리

XLNet은 Transformer-XL의 두 기법을 가져옵니다. 첫째는 상대 위치 인코딩으로, 위치 인코딩이 원래 시퀀스의 실제 위치에 기반합니다. 둘째는 세그먼트 재귀로, 이전 세그먼트에서 계산한 내용 표현 \\(\\tilde{h}^{(m)}\\)을 캐시하고 다음 세그먼트의 어텐션 메모리로 사용합니다. 이때 메모리는 이전 세그먼트의 인수분해 순서와 독립적으로 재사용됩니다.

다중 세그먼트 입력에서는 BERT처럼 두 세그먼트를 \[CLS, A, SEP, B, SEP\] 형식으로 이어 붙입니다. 그러나 절대 세그먼트 임베딩 대신 상대 세그먼트 인코딩을 사용합니다. 두 위치가 같은 세그먼트에 있으면 \\(s\_+\\), 그렇지 않으면 \\(s\_-\\)를 사용하여 어텐션 가중치에 더합니다. 즉 모델은 두 위치가 같은 세그먼트인지 여부만 봅니다. 저자들은 이 방식이 일반화에 유리하고 두 개보다 많은 입력 세그먼트를 가진 미세조정 과제에도 확장할 수 있다고 설명합니다.

계산을 줄이기 위해 부분 예측도 사용합니다. 인수분해 순서를 비목표 부분 \\(z\_{\\le c}\\)와 목표 부분 \\(z\_{\>c}\\)로 나누고, 뒤쪽 토큰만 예측합니다. 논문은 \\(\|z\|/(\|z\|-c)\\approx K\\)가 되도록 선택하며, XLNet-Large pre-training에서는 K를 6으로 둡니다.

## BERT와의 동일 조건 비교

이 논문은 데이터와 하이퍼파라미터를 BERT와 같게 맞춘 XLNet-Large-wikibooks를 만들어 BERT-Large와 비교합니다. 기준선은 원문이 밝힌 BERT의 세 변형 가운데 최고 성능입니다. 이 설정에서 XLNet-Large-wikibooks는 SQuAD1.1 88.2/94.0, SQuAD2.0 85.1/87.8, RACE 77.4, RTE 81.2를 기록하며, BERT-Large의 86.7/92.8, 82.8/85.5, 75.1, 74.0보다 높습니다. 이 비교는 위키피디아와 BooksCorpus만 사용한 설정에 한정됩니다.

![Table 1: Fair comparison with BERT. All models are trained using the same data and hyperparameters as in BERT. We use the best of 3 BERT variants for compariso…](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5/figures/figure-ae58786e61586ecd5b63ce7b8aab688f.png?thumb=512)

**Table 1** : Fair comparison with BERT. All models are trained using the same data and hyperparameters as in BERT. We use the best of 3 BERT variants for comparison; i.e., the original BERT, BERT with whole word masking, and BERT without next sentence prediction.

[원문](https://arxiv.org/abs/1906.08237v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · 원문 그림 인용 · 원본 PDF 7쪽에서 그림 영역을 추출했습니다.

초록은 비교 가능한 실험 설정에서 질문 응답, 자연어 추론, 감성 분석, 문서 순위 등 20개 과제에서 BERT보다 우수하며 여러 경우 큰 차이를 보인다고 밝힙니다. 이 결과는 해당 실험 조건에서 얻은 것이며, 모든 데이터 규모나 모든 모델 크기에서 같은 우위가 성립하는지는 이 근거만으로 판단할 수 없습니다.

## 대규모 데이터에서 RoBERTa와 비교

대규모 설정에서는 XLNet-Large를 Giga5, ClueWeb 2012-B, Common Crawl까지 포함한 전체 데이터로 학습하고, RoBERTa의 하이퍼파라미터를 따릅니다. 같은 24층 BERT-Large 규모 설정에서 RACE 테스트 정확도는 XLNet 85.4(중등 88.6, 고등 84.0)로, RoBERTa 83.2보다 높습니다. ClueWeb09-B 문서 순위 과제에서는 XLNet의 NDCG@20이 31.10, ERR@20이 20.28입니다. 이 값은 같은 표의 BERT† 30.53/18.67과 비교한 결과이며, 문서 순위 점수는 사전학습된 XLNet의 단어 임베딩을 커널 풀링 네트워크에 넣은 설정에서 얻은 것입니다.

논문은 길고 명시적인 추론이 필요한 SQuAD와 RACE에서 XLNet의 이득이 더 크게 나타나며, 이는 Transformer-XL 기반 구조가 긴 문맥을 다루는 데 도움을 준 것일 수 있다고 해석합니다. 대량의 지도 데이터가 있는 분류 과제에서도 MNLI, Yelp, Amazon 등에서 이득이 보고됩니다.

![Table 3: Results on SQuAD, a reading comprehension dataset. † marks our runs with the ofﬁcial code. ∗ indicates ensembles.‡: We are not able to obtain the test…](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5/figures/figure-7abfa0340d21362bebf90a056704c03d.png?thumb=512)

**Table 3** : Results on SQuAD, a reading comprehension dataset. † marks our runs with the ofﬁcial code. ∗ indicates ensembles.‡: We are not able to obtain the test results of our latest model on SQuAD1.1 from the organizers after submitting our result for more than one month, and thus report the results of an older version for the SQuAD1.1 test set.

[원문](https://arxiv.org/abs/1906.08237v2) · [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) · Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le · XLNet: Generalized Autoregressive Pretraining for Language Understanding · 원문 그림 인용 · 원본 PDF 8쪽에서 그림 영역을 추출했습니다.

## 절제 실험으로 본 구성 요소의 기여

절제 실험은 XLNet-Base를 위키피디아와 BooksCorpus에서 12층 BERT-Base와 같은 모델 하이퍼파라미터로 학습하고, 각 결과를 5회 실행의 중앙값으로 보고합니다. 먼저 BERT-Base는 RACE 64.3, SQuAD2.0 F1 76.30, MNLI 84.34/84.65, SST-2 92.78입니다. BERT의 잡음 제거 자기부호화 목적을 Transformer-XL과 양방향 입력 파이프라인에 적용한 기준선은 RACE 65.03이며, 순열 언어 모델링을 적용한 XLNet-Base(K=6)는 RACE 66.66입니다. 이 비교에서 Transformer-XL과 순열 목적이 각각 성능 향상에 기여합니다.

메모리 캐시를 제거하면 RACE가 65.55로 떨어지며, 긴 문맥이 필요한 RACE에서 하락이 특히 큽니다. 스팬 기반 예측과 양방향 데이터 입력을 제거해도 성능이 낮아집니다. 다음 문장 예측을 추가한 설정은 RACE 66.76으로 일부 과제에서는 높지만 SQuAD2.0과 MNLI는 낮아집니다. 저자들은 이 결과 때문에 XLNet에서 다음 문장 예측 목적을 제외했다고 설명합니다.

## 학습 기간과 과소적합의 한계

논문은 대규모 학습을 512개의 TPU v3 칩으로 500K 스텝 동안 수행하고, 배치 크기 8192와 Adam 가중치 감쇠 옵티마이저, 선형 학습률 감소를 사용했다고 설명합니다. 이 학습은 약 5.5일이 걸렸습니다. 그러나 학습이 끝날 때까지 모델이 데이터에 아직 과소적합되어 있었다고 원문이 보고합니다. 따라서 이 설정의 성능은 더 긴 학습으로 개선될 여지가 남아 있는 상태에서 얻은 값입니다.

이 사실은 대규모 결과 수치를 해석할 때 중요합니다. 같은 학습 예산으로 얻은 값이 비교에 쓰였으므로, 학습량을 늘린 경우의 성능이나 다른 계산 예산에서의 순위는 이 논문의 근거만으로는 확정할 수 없습니다.

## 논문 정보

- **저자**: Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, Quoc V. Le
- **학회·저널**: arXiv · 프리프린트
- **최초 공개일**: 2019년 6월 19일
- **등록일**: 2026년 10월 20일
- **수정일**: 2020년 1월 2일
- **버전**: v2
- **arXiv**: 1906.08237
- **분류**: cs.CL · cs.LG
- **원문 이용 조건**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **제공 범위**: 논문 정보, 해설, 허용된 원문 그림

[논문 원문 ↗](https://arxiv.org/abs/1906.08237v2) · [원문 PDF ↗](https://arxiv.org/pdf/1906.08237v2)

AI 해설은 논문 원문과 별개의 설명이며 오류가 있을 수 있습니다. 원문과 그림은 각 출처의 이용 조건과 따로 표시된 권리를 따릅니다.

## 초록

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.

## 원문 인용

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}
}
```

## 이 논문의 용어

- [BERT](https://refivu.com/terms/45b639a1d317-bert)
- [GLUE](https://refivu.com/terms/9305114e7947-glue)
- [RoBERTa](https://refivu.com/terms/f42b278690e5-roberta)
- [SQuAD](https://refivu.com/terms/097ea97dc6b6-squad)
- [Transformer-XL](https://refivu.com/terms/f0cf4fd109e4-transformer-xl)
- [XLNet](https://refivu.com/terms/b2194e0b0811-xlnet)
- [RACE](https://refivu.com/terms/0dc449cd7f20-race)
- [permutation language modeling](https://refivu.com/terms/1dc5b3bda132-permutation-language-modeling)

## 다른 논문 해설

- [Distributed Representations of Words and Phrases and their Compositionality](https://refivu.com/papers/3b76539e-2654-42d7-9073-06bc84af912a-distributed-representations-of-words-and-phrases-and-their.md)
- [Neural Machine Translation by Jointly Learning to Align and Translate](https://refivu.com/papers/d3733cd4-18bb-4ef7-881b-d6d27baee015-neural-machine-translation-by-jointly-learning-to-align.md)
- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://refivu.com/papers/037751cf-a504-48c3-b08a-868e3ab40b26-bert-pre-training-of-deep-bidirectional-transformers-for.md)
- [Looped Models are Fast Multi-Token Predictors](https://refivu.com/papers/753aee4a-f281-45ed-9e03-84eb93c47b6d-looped-models-are-fast-multi-token-predictors.md)
- [FIDEL: Abugida-Aware Pre-tokenization for Ethiopic Languages](https://refivu.com/papers/ddcebe56-3d04-41f8-b252-f5f305a78bc1-fidel-abugida-aware-pre-tokenization-for-ethiopic-languages.md)
- [Meaning Reaches Object Choice but Not Completion: Where Is a VLA Vulnerable to Landmark Synonyms?](https://refivu.com/papers/defc7d50-8eb3-4076-bf41-f9d85534ab4c-meaning-reaches-object-choice-but-not-completion-where.md)
- [Deep Residual Learning for Image Recognition](https://refivu.com/papers/19d6446d-fd9a-4e80-b535-a4e333cad216-deep-residual-learning-for-image-recognition.md)
- [Adam: A Method for Stochastic Optimization](https://refivu.com/papers/1e4ce3cf-c297-4440-9078-a86a09a9caca-adam-a-method-for-stochastic-optimization.md)
- [Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift](https://refivu.com/papers/bd3e1105-da91-407a-8b28-4217cd2afedf-batch-normalization-accelerating-deep-network-training-by.md)
- [Attention Is All You Need](https://refivu.com/papers/9645c9a1-cc92-404a-bc65-1ec437b1deab-attention-is-all-you-need.md)
- [SmolWAM: A Latent World-Action Model for Robotic Manipulation on Edge Devices](https://refivu.com/papers/0fcff0f4-e626-4624-88df-147586408ac6-smolwam-a-latent-world-action-model-for-robotic.md)

---

AI 해설에는 오류가 있을 수 있습니다. [Refivu](https://refivu.com/papers/b3e5ce04-f8db-4e06-9f54-1aba7291fad5-xlnet-generalized-autoregressive-pretraining-for-language)
