LLM(4) | Attention Is All You Need 论文粗读

LLM(4) | Attention Is All You Need 论文粗读

1. 目的

LLM 模型都是 transformer 模型, “Attention Is All You Need” 是提出 transformer 的论文。 使用李沐的论文精读法, 记录第一次阅读(“海选”) transformer 的笔记。

2. 回顾论文精读的第一遍的步骤

海选(通常用10+分钟)

  1. title √[1]
  2. abstract √[2]
  3. intro
  4. method √(5)
  5. exp √(4)
  6. conclusion √[3]

先标题,再摘要; 摘要可能有1、2个问题没说清楚, 看结论里的答案,比如数字、实际的结论; 感兴趣那么稍微看下实验部分的关键图表, 再稍微看一下方法里的图表。

其中 [] 必选, () 可选。

在这里插入图片描述

3. 标题

Attention Is All You Need

标题分成两部分:

  1. attention: 注意力

  2. all you need: 你只需要

意思是说, attention 是有用的, 并且你不需要用其他方法了, 就只用 attention 方法就足够了。

4. 摘要

以下是翻译, 括号里是个人粗浅想法的记录:

The dominant sequence transduction models are based on complex recurrent or
convolutional neural networks that include an encoder and a decoder.
The best performing models also connect the encoder and decoder through an attention
mechanism.

主流的序列转换模型,是基于复杂的 RNN 或 CNN, 包括一个 encoder 和一个 decoder。 性能最佳的模型还通过 注意力机制(attention mechanism) 连接编码器和解码器。
(以前的序列转换模型里, 既用 RNN, 也用 CNN, 并且也有人用了注意力机制。 encoder 是啥? decoder 又是啥?)

We propose a new simple network architecture, the Transformer,
based solely on attention mechanisms, dispensing with recurrence and convolutions
entirely.

我们提出了一种新的简单网络架构, 即 Transformer, 它完全基于注意力机制, 彻底摈弃了 RNN 和 CNN。
(本文作者提出的网络架构, 完全是基于 attention。 对, 只用 attention。 这和标题呼应了: 不用 RNN, 也不用 CNN。 那么, encoder 和 decoder 是可以不用 RNN、 不用 CNN 实现的? 还是说连 encoder 和 decoder 都不用了?)。

Experiments on two machine translation tasks show these models to
be superior in quality while being more parallelizable and requiring significantly
less time to train.

在两个机器翻译任务上的实验显示, 这些模型在质量上更为优越, 同时具有更好的并行性, 并且所需要的训练时间显著减少。
(实验结果挺好的, transformer 的精度高、 训练快。 并行性是什么鬼? 是因为更好的并行性, 才让训练变快的吗? 那么并行性是怎么做到的? )

Our model achieves 28.4 BLEU on the WMT 2014 Englishto-German
translation task, improving over the existing best results, including
ensembles, by over 2 BLEU.

我们的模型在 WMT 2014 英语到德语翻译任务上达到了 28.4 BLEU, 比现有的最佳结果 (包括集成模型) 提高了2个以上的 BLEU。
(这是提到的第一个机器翻译任务, 英语-德语 的翻译。 2个 BLEU, 看起来确实明显好于以前的结果。 虽然不知道 BLEU 的意思)

On the WMT 2014 English-to-French translation task,
our model establishes a new single-model state-of-the-art BLEU score of 41.8 after
training for 3.5 days on eight GPUs, a small fraction of the training costs of the
best models from the literature.

在 WMT 2014 英语到法语翻译任务上, 我们的模型在使用8个GPU训练3.5天之后, 以 41.8 的 BLEU 分数建立了新的单模型最先进水平, 这只是文献中最佳模型训练成本的一小部分。
(第二个任务, 英语-法语 翻译, 精度也是世界最高, 41.8 的 BLEU。 这么高的得分, 对应的训练时间是 8个GPU连续训练 3.5 天, 这个训练耗时, 比我们当前(2017年)在论文里找到的的最佳性能模型的训练时间相比, 是非常少的了)

We show that the Transformer generalizes well to
other tasks by applying it successfully to English constituency parsing both with
large and limited training data.

我们展示了 transformer 在其他任务上有良好的泛化能力, 通过将其成功应用于英语成分句法分析, 无论是在大量还是有限的数据训练上都取得了成功。
(这里是摘要, 没有详细说其他任务, 只说用到了方法, 是把 transformer 用于句法分析。 说明泛化性挺好的。 不管数据多还是少, 都能训练出来。 说明适合的场景挺多的。)

3. 结论

直接跳到结论, 看一些和摘要里相呼应、 但是摘要里没有给出量化描述的结论等。 以下是翻译, 中文括号里是个人粗浅的理解。

In this work, we presented the Transformer, the first sequence transduction model based entirely on
attention, replacing the recurrent layers most commonly used in encoder-decoder architectures with
multi-headed self-attention.

在这项工作中, 我们介绍了 transformer, 这是第一个完全基于 attention 的序列转换模型。 它使用多头注意力机制替换了在 encoder-decoder 架构中最常用的循环层。
(开创性的: 第一个, 完全用 attention, 在序列转换模型方面。 完全: 是说替换掉了 encode-decoder 架构中的循环层, 使用 attention 连接 encoder-decoder? 使用 attention 的时候, 作者是使用了 multi-headed self-attention 多头自注意力。 这个貌似就是后世称为 MHA (multi-head attention) 的结构?)
(这里的疑问: encoder-decoder 架构是啥? transformer 里还在用吗? 怎样体现 multi-head 而不是 single-head 的 attention? )

For translation tasks, the Transformer can be trained significantly faster than architectures based
on recurrent or convolutional layers. On both WMT 2014 English-to-German and WMT 2014
English-to-French translation tasks, we achieve a new state of the art. In the former task our best
model outperforms even all previously reported ensembles.

对于翻译任务来说, Transformer 的训练速度显著快于基于 RNN 或 CNN 的架构。 在 WMT 2014 英语到德语和 WMT 2014 英语到法语翻译任务上, 我们都达到了新的最先进水平。 在前者任务中, 我们最好的模型甚至超过了之前报告的所有集成模型。
(在机器翻译任务上, transformer 训练速度快。 在 WMT 翻译任务上, transformer 精度高。 快和高, 都是明显好于以往的。)

We are excited about the future of attention-based models and plan to apply them to other tasks. We
plan to extend the Transformer to problems involving input and output modalities other than text and
to investigate local, restricted attention mechanisms to efficiently handle large inputs and outputs
such as images, audio and video. Making generation less sequential is another research goals of ours.

我们对基于注意力的模型的未来感到兴奋, 并计划将它们应用到其他任务上。 我们计划将 transformer 扩展到涉及输入和输出模态不仅仅是文本的问题,
并且要研究局部的、 受限的注意力机制, 以高效处理大型输入和输出, 如图像、 音频和视频。 使生成过程变得不那么顺序, 是我们的另一个研究目标。
(论文作者们展望了一下未来基于 transformer 的研究: 一个是任务扩展, 一个是让生成过程不那么序列化。 任务扩展, 考虑的是输入可以不仅仅是文本, 要包括图像、音频和视频; 考虑的是 attention 是局部的、 受限情况下的处理。)

The code we used to train and evaluate our models is available at https://github.com/
tensorflow/tensor2tensor.

我们用来训练和评估我们模型的代码可以在 https://github.com/tensorflow/tensor2tensor 上找到。

结论的总结

方法新颖: 第一个完全用 attention 做序列转换的模型, 替换了 RNN。
已有成果: 应用 transformer 到了机器翻译任务上。
展望: 提到了多模态输入, 局部和受限的 attention。

4. 稍微看一下实验的图表

略。 不太看的懂。

5. 稍微看一下方法里的图表

在这里插入图片描述

图1: transformer 的模型结构。

图2: 左图是 dot-product attention。 右图是 multi-head attention。

dot-product attention 是 multi-head attention 的组成部分。

multi-head attention 是 transformer 的组成部分。

在这里插入图片描述

从图上看起来,一些猜测:

  • Scaled Dot-Product 是最简单的 Attention
  • MatMul 是矩阵乘法
  • Scaled Dot-Poroduct Attention 里带有了 softmax, 而 softmax 以前我在 CNN 里只在网络最后一层看到过

这里的疑问是:

  • Q, K, V 是什么?
  • Position Encoding 是在干啥
  • Feed Forward 是在干啥
  • Add & Norm 是在干啥
  • Nx 是啥意思?
  • Masked MHA 和 MHA 有啥区别?

Reference

  • 8
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值