语言人工智能指南

XLNet 和排列语言建模

XLNet 是卡内基梅隆大学和 Google Brain 推出的 2019 年语言模型,无需 BERT 的 [MASK] 令牌即可学习双向上下文。

听听这个指南AI叙述 · ~7 min

在本页阅读需 8 分钟
  1. 概述
  2. 主要要点
  3. 深入探讨
  4. 追踪一个四词句子的一个排列
  5. 现实世界的实施
  6. XLNet 与排列语言建模的未来
  7. 付诸实践
  8. 资料来源与延伸阅读
  9. 不断探索
  10. 常见问题

概述

它通过预测许多随机打乱顺序的单词来进行训练,这种方法被称为排列语言建模,并且在它 NeurIPS 2019 年的论文中,它在 20 项基准测试任务上表现优于 BERT。

主要要点

  1. XLNet 由卡内基梅隆大学和 Google Brain 的研究人员于 NeurIPS 2019 年发表,通过预测随机采样排列顺序中的标记来进行训练。
  2. 排列语言建模为每个标记提供了双向上下文,同时保持自回归特性,并且从不在输入中插入 [MASK] 标记。
  3. 双流自注意力机制将能够看到每个标记的内容流与仅知道目标位置的查询流分离开来。
  4. XLNet 在 RACE 上报告了 85.4% 的准确率,而 BERT 为 72.0%,并且在可比设置下在 20 项任务中击败了 BERT。
  5. RoBERTa 在几周内缩小了差距,表明 BERT 的大部分不足源于训练不足,而不仅仅是其掩码目标本身。

深入探讨

XLNet is a pretrained transformer language model introduced in June 2019 by Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell and Ruslan Salakhutdinov of Carnegie Mellon University and Quoc V. Le of the Google Brain team, and published at NeurIPS 2019. Its key contribution is a training objective called permutation language modeling. The goal was to combine the strengths of two earlier families of models: autoregressive models such as GPT, which predict each word from the words before it, and autoencoding models such as BERT, which hide some words and predict them from both sides.

The problem XLNet set out to fix is worth stating plainly. An autoregressive model only sees context on one side, which limits understanding tasks where both sides matter. BERT sees both sides by replacing a share of input tokens with a special [MASK] symbol and predicting the originals. The XLNet authors identified two weaknesses in that design. First, the [MASK] symbol appears in pretraining but never in real downstream text, a mismatch they call the pretrain-finetune discrepancy. Second, BERT predicts the masked tokens independently of one another, so if both words of a name like New York are masked, it cannot use one guess to inform the other.

Permutation language modeling works like this. Take a sentence of T tokens and pick a random factorization order, a shuffled sequence of positions such as 3, 1, 4, 2. The model then predicts the tokens one at a time in that order, so token 3 is predicted from nothing, token 1 from token 3, token 4 from tokens 3 and 1, and so on. Crucially, the words themselves are never reordered in the input; their original positions are kept, and only the attention mask changes so that each token can see exactly the tokens that come earlier in the sampled order. Over many training steps, with a fresh order each time, every token ends up being predicted from many different combinations of left and right neighbors. The model is still autoregressive, multiplying conditional probabilities, but in expectation it learns from bidirectional context, and no [MASK] token is ever inserted.

This creates a technical puzzle that the paper solves with two-stream self-attention. To predict the token at a given position, the model must know which position it is predicting, or it would give the same answer for every target, but it must not see that token's own content, or the task would be trivial. XLNet therefore keeps two representations per position. The content stream works like a normal transformer and includes the token itself. The query stream knows the target position but not its word, and is the one used to make the prediction. Because predicting from very short contexts early in an order is hard and slows training, XLNet also uses partial prediction, predicting only the last part of each order, roughly one token in K, with K set to 6 for the large model.

XLNet also borrowed two components from Transformer-XL, a model the same group published at ACL 2019 that learned dependencies 450% longer than vanilla transformers. These were relative positional encodings, which describe how far apart two tokens are rather than their absolute index, and segment-level recurrence, which caches hidden states from a previous text segment as memory for the next. The large model used BERT-Large's architecture, 24 layers with a hidden size of 1,024 and 16 attention heads, and was pretrained on 32.89 billion subword pieces drawn from BooksCorpus, English Wikipedia, Giga5, ClueWeb 2012-B and Common Crawl. Training used 512 TPU v3 chips for 500,000 steps with a batch size of 8,192 and sequence length of 512, about 5.5 days.

The headline results were strong for mid-2019. The abstract reports XLNet beating BERT on 20 tasks under comparable settings. On RACE, a reading comprehension test drawn from English exams, it scored 85.4% against BERT's 72.0%. On SQuAD 2.0 it reached 90.6 F1 on the dev set against 81.77 for BERT. The paper also ran a fair comparison, training XLNet on the same Wikipedia and books data with BERT's hyperparameters, and XLNet still came out ahead on every dataset in that table. Its ablations showed that both the permutation objective and the Transformer-XL memory contributed, though some gaps were small: removing memory cut the base model's RACE score from 66.66 to 65.55.

Compared with the alternatives, the picture became more nuanced within weeks. RoBERTa, posted by Yinhan Liu and colleagues in July 2019, argued that the original BERT was significantly undertrained and showed that a better-tuned masked language model with more data could match or exceed later models. XLNet's own updated paper compares against RoBERTa and reports generally better scores, for example 90.8% versus 90.2% on MNLI, but the margins were far smaller than over the original BERT. This made it harder to say how much of XLNet's gain came from the permutation objective and how much from more data, longer training and Transformer-XL components.

XLNet's practical limitations were mostly about cost and complexity. Two-stream attention and permutation masks make the model harder to implement and slower to train than a standard masked model. The official repository warns that fine-tuning XLNet-Large on a 16 GB GPU fits only a single 512-token sequence per batch, and that reproducing many paper results would take roughly 32 to 128 GPUs. Partial prediction means each sequence trains on only a fraction of its tokens. XLNet is now studied mainly as a reference point: it remains a clear demonstration that an autoregressive model can learn bidirectional context without corrupting its input.

04工作示例

追踪一个四词句子的一个排列

  1. Write the sentence 'cats chase small mice' with positions 1 to 4.

  2. Sample a factorization order, for example 3, 1, 4, 2.

  3. Predict position 3, 'small', with no visible tokens, using only the query stream's knowledge that position 3 is the target.

  4. Predict position 1, 'cats', seeing only 'small' at position 3.

  5. Predict position 4, 'mice', seeing 'small' and 'cats', both of which sit to its left in the text.

  6. Predict position 2, 'chase', seeing positions 1, 3 and 4, so it uses context from both its left and right.

  7. 使用部分预测和 K = 2,只保留最后两步的损失,即位置 4 和 2。

它显示了什么

位置 2 是从两侧的词预测出来的,没有任何 [MASK] 令牌,这是排列语言建模的核心。通过构建 4×4 的注意力掩码来检查轨迹:第 2 行应允许列 1、3 和 4,而第 3 行则不允许任何列。

现实世界的实施

阅读理解:在 RACE 考试题基准上,XLNet 论文报告 85.4% 的准确率,而 BERT 为 72.0%,RoBERTa 为 83.2%。

在 SQuAD 2.0 的抽取式问答中,论文报告单模型的开发集 F1 分数为 90.6,与 BERT 的 81.77 和 RoBERTa 的 89.4 相比。

微调发布的检查点:作者的 Apache-2.0 仓库在 2019 年 6 月 19 日发布了 XLNet-Large,在 2019 年 7 月 16 日发布了 XLNet-Base,用于分类、问答和排序任务。

关于预训练目标的教学与研究,XLNet 是获取双向上下文同时保持自回归、从左到右概率模型的标准示例。

自然语言推断:在 GLUE 的 MNLI 任务上,论文报告 90.8% 的开发集准确率,领先于 RoBERTa 的 90.2% 和 BERT 的 86.6%。

XLNet 与排列语言建模的未来

XLNet's direct line of development did not continue at large scale, but the questions it raised remain open. The rapid arrival of RoBERTa in July 2019, which matched or beat later models with a tuned masked objective, showed how hard it is to separate the effect of a pretraining objective from the effect of data, compute and training length. That lesson shaped how later papers report ablations and fair comparisons. The idea of learning from many orderings, rather than a single left-to-right order, continues to appear in research on non-autoregressive generation, infilling, and models that can generate tokens in flexible order. The XLNet paper itself, dated 2019 and revised in January 2020, framed permutation modeling as a general bridge between autoregressive and autoencoding pretraining. Whether flexible-order objectives offer advantages over plain next-token prediction at the scale of current large language models is an open research question, and claims either way depend on carefully controlled comparisons of the kind the XLNet and RoBERTa papers attempted.

付诸实践

为什么这很重要

  • 速度与规模. 语言工作流程可以在不牺牲一致性的情况下更快地移动。
  • 交通与覆盖范围. 它扩展了跨语言和沟通方式的访问。
  • 更清晰的判决. 团队可以花更多时间进行判断,而自动化则可以处理重复。

留意

  • 幻觉的事实可以悄悄地进入报告、支持流程或研究成果。
  • 及时的敏感性可能会在类似的请求中产生不一致的结果。
  • 如果访问控制薄弱,敏感文本数据可能会暴露。

后续步骤

  1. 在推出之前定义输出格式、语气和质量标准。
  2. 当准确性很重要时,请使用可信来源进行地面响应。
  3. 为高风险输出保留人工审查检查点。
  4. 跟踪故障模式并定期重新训练提示或工作流程。

资料来源与延伸阅读

  1. arXiv (Yang et al.)XLNet: Generalized Autoregressive Pretraining for Language Understanding
  2. NeurIPS 2019 ProceedingsXLNet: Generalized Autoregressive Pretraining for Language Understanding
  3. arXiv / ACL 2019 (Dai et al.)Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
  4. arXiv (Liu et al.)RoBERTa: A Robustly Optimized BERT Pretraining Approach
  5. GitHub (XLNet authors)zihangdai/xlnet

不断探索

免费通讯

获取每日AI简报

每个工作日早晨提供三条经过验证的AI故事,使用简明英文撰写。永久免费,无广告。

每个工作日发送一封邮件。一键退订。我们永不出售或分享您的地址。

测试一下自己

Take the XLNet and Permutation Language Modeling quiz

每个答案即时反馈,课程通过后可获得可验证ID的可分享证书。

开始测验

支持免费AI教育。AI Understanding是一家501(c)(3)非营利组织——无广告,无付费墙,永不收费。 捐款

常见问题

What is XLNet and Permutation Language Modeling?

XLNet 是 2019 年卡内基梅隆大学和 Google Brain 开发的语言模型,它在没有 BERT 的 [MASK] 令牌的情况下学习双向上下文。它通过在多种随机打乱顺序中预测单词来训练,这种方法称为排列语言建模,并在其 NeurIPS 2019 论文中在 20 个基准任务上超过了 BERT。

XLNet 使用什么预训练目标?

XLNet 最大化令牌分解顺序的所有排列的预期对数似然,称为排列语言建模。

XLNet 是专门为了解决哪些 BERT 弱点而设计的?

BERT 的人工 [MASK] 符号在微调期间不会出现,并且它将屏蔽预测视为独立的; XLNet 避免了这两个问题。

XLNet的两流self-attention分离了什么?

内容流对令牌和上下文进行编码,而查询流知道目标的位置但不知道其内容,从而实现无泄漏的预测。

XLNet 是否会物理地打乱句子中的单词?

XLNet 通过注意力掩码排列预测(分解)顺序;原始标记位置通过位置编码保留。

哪种架构作为 XLNet 的远程上下文骨干网?

XLNet 建立在 Transformer-XL 的基础上,它添加了分段循环和相对位置编码来处理长序列。