“The results are pretty remarkable. Check out the hallucinated Napoleonic-history wikipedia article at the bottom of Transformer-XL”
Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
用段级循环和新位置编码突破 Transformer 的固定上下文长度
Transformer 能学习更长期依赖,但在语言建模中受限于固定长度上下文。论文提出 Transformer-XL,由段级循环机制和新的位置编码方案组成,使模型能在不破坏时间连贯性的前提下学习超出固定长度的依赖,同时解决上下文碎片化问题。它学到的依赖比 RNN 长 80%、比原始 Transformer 长 450%,评估速度最高快 1800 多倍,并刷新了 enwiki8、text8、WikiText-103、One Billion Word 和 Penn Treebank 上的最佳结果。仅用 WikiText-103 训练,它就能生成数千 token、较为连贯的新文章。
HN 上的人称赞它生成的长篇维基风格文章结果惊人和附录里的表格,也把它当作解决 Transformer 上下文长度限制的早期研究以及 XLNet 的基础。
学习路径
读这篇之前,按顺序读书架上的 4 篇 · 参考文献来自 OpenAlex,顺序和要点由 Claude Code 排出先看 LSTM 语言模型的基线和评测,再读 Transformer 及其固定长度上下文的字符级应用,才能明白 Transformer-XL 的段级循环在补什么缺陷。
- 1
它给出大规模 LSTM 语言模型和十亿词基准上的结果,是 Transformer-XL 要对比的循环网络基线。
读语言模型的困惑度指标与大规模 LSTM 的设置,了解当时的最好水平。
- 2
AWD-LSTM 是目标论文在小型语料上对比的强 RNN 基线。
读权重绑定、DropConnect 等正则化技巧,只需知道它为何是强基线。
- 3
Transformer-XL 在原始 Transformer 的基础上改造,需要先懂自注意力和位置编码。
读自注意力、多头结构与正弦位置编码,位置编码正是目标论文要改的部分。
- 4
它把固定长度上下文的 Transformer 用于字符级语言模型,暴露了上下文被切段而割裂的问题。
读固定长度片段训练的做法,以及辅助损失,体会上下文碎片化的含义。
- 5Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context
在前面几篇的基础上,看用段级循环和相对位置编码突破固定上下文。
读段级循环机制中缓存上一段隐状态的做法,以及相对位置编码的推导。
HN 书评
推荐在前,同类按时间 · 每篇最多保留 20 条,统计用全部提及“Have you seen the tables in Appendix E (starts p. 16) of the Transformer-XL paper? I think they're pretty good.”
“See the last section of this paper:”
“XLnet, and the underlying TransformerXL technology, did have Google researchers involved:”
“There's already research that tries to fix this problem with transformers in general, like Transformer-XL [1].”
“I posted a list of papers on twitter, and will be posting a summary for each of them as well.”