目录
3.1 编码器和解码器堆叠(Encoder and Decoder Stacks)
3.2.1 缩放点积注意力(Scaled Dot-Product Attention)
3.2.2 多头注意力(Multi-Head Attention)
3.2.3 注意力机制在模型中的应用(Applications of Attention in our Model)
3.3 位置前馈网络(Position-wise Feed-forward Networks)
3.4 嵌入和Softmax(Embedding and Softmax)
5.1 训练数据和批处理(Training Data and Batching)
5.2 硬件和时间(Hardware and Schedule)
说明
本篇博客记录学习论文《Attention Is All You Need》的全过程,不做任何商业用途,如有侵权请及时联系。
- 论文链接:https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf
- 项目地址:GitHub - tensorflow/tensor2tensor: Library of deep learning models and datasets designed to make deep learning more accessible and accelerate ML research.
- 学习工具:知云文献翻译V8.4、Visual Studio Code、ChatGPT 3.5
- 学习内容:文献翻译、重点理解、写作技巧
- 学习目标:掌握transformer框架,理解模型算法过程
摘要(Abstract)
The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder.
主流序列转导模型基于复杂的递归或卷积神经网络,包括编码器和解码器。
序列转导模型(sequence transduction models):
-
输入输出序列映射:序列转导模型的核心任务是学习将一个序列映射(或转换)成另一个序列。例如,将一段中文文本翻译成英文文本,或者将语音信号转换成文本序列。
-
适用于多种任务(包括但不限于):
- 机器翻译:将一种语言的序列翻译成另一种语言的序列。
- 文本摘要:将长篇文本转换为短摘要的序列。
- 语音识别:将语音信号转换为文本序列。
- 命名实体识别:将文本序列中的命名实体标注出来。
- 对话系统:将用户的自然语言输入转换成系统回应的序列。
The best performing models also connect the encoder and decoder through an attention mechanism.
性能最好的模型还通过注意力机制连接编码器和解码器。
注意力机制(attention mechanism):
- 动态权重分配:注意力机制允许模型在处理序列中的每个元素时,根据当前的上下文动态地给予不同元素不同的权重或注意力。这样模型可以集中精力处理对当前任务最重要的部分,而忽略不相关的部分,从而提高了模型的效率和性能。
- 应用领域:注意力机制最初是为了解决机器翻译中长距离依赖问题而提出的,但后来被广泛应用于各种序列到序列的转换任务,如文本摘要、语音识别、问答系统等。
We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely.
我们提出了一种新的简单网络架构,Transformer,它完全基于注意力机制,完全省去了递归和卷积。
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.
在两个机器翻译任务上的实验表明,这些模型的质量更高,同时具有更高的并行性,并且需要更少的时间进行训练。
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以上。
On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.0 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天后建立了新的单模型最先进的BLEU分数41.0,这是文献中最佳模型训练成本的一小部分。
注:BLEU(Bilingual Evaluation Understudy)是一种用于评估机器翻译质量的指标,它通过比较机器翻译的输出与人工翻译的参考翻译之间的相似度来评分。
写作技巧
摘要简洁明了,依次介绍了现有模型的传统框架、transformer采用的的新型框架、transformer的特点(优势),以及两个体现transformer性能的例子,使用了大量数据,直观感受。
1 介绍(Introduction)
第一段:循环神经网络现状
Recurrent neural networks, long short-term memory [12] and gated recurrent [7] neural networks in particular, have been firmly established as state of the art approaches in sequence modeling and transduction problems such as language modeling and machine translation [29, 2, 5].
循环神经网络,特别是长短期记忆[12]和门控循环神经网络[7],已被确立为序列建模和转导问题(如语言建模和机器翻译[29,2,5])的最新方法。
Numerous efforts have since continued to push the boundaries of recurrent language models and encoder-decoder architectures [31, 21, 13].
此后,许多努力继续扩展循环语言模型和编码器-解码器架构的边界[31,21,13]。
第二段:循神经环网络的机制、特点、问题
Recurrent models typically factor computation along the symbol positions of the input and output sequences.
循环模型通常根据输入和输出序列的符号位置进行因子计算。
Aligning the positions to steps in computation time, they generate a sequence of hidden states ht, as a function of the previous hidden state ht−1 and the input for position t.
在计算时将位置与步骤对齐,它们会生成一系列隐藏状态ht,作为先前隐藏状态ht-1和位置t输入的函数。
This inherently sequential nature precludes parallelization within training examples, which becomes critical at longer sequence lengths, as memory constraints limit batching across examples.
这种固有的顺序性质阻止了训练示例中的并行化,这在较长的序列长度下变得至关重要,因为内存约束限制了跨示例的批处理。
并行化(parallelization)并行化是一种计算方法,它通过同时执行多个计算任务来提高程序的性能和效率。将一个大的任务分解成多个小任务,这些小任务可以同时在不同处理器或计算资源上执行。
在机器学习中,批处理(batching)是常见的优化手段,可以有效地利用GPU并行计算能力来加速训练过程。然而,对于序列数据,尤其是较长的序列,由于每个序列元素依赖于前面的元素,因此无法直接在多个序列之间实现并行化处理。这意味着,每个批次中的序列必须按顺序逐个处理,而不能同时处理多个序列。
Recent work has achieved significant improvements in computational efficiency through factorization tricks [18] and conditional computation [26], while also improving model performance in case of the latter.
最近的工作通过因子分解技巧[18]和条件计算[26]显著提高了计算效率,同时也提高了后者的模型性能。
The fundamental constraint of sequential computation, however, remains.
然而,顺序计算的基本约束仍然存在。
第三段:注意力机制的特点
Attention mechanisms have become an integral part of compelling sequence modeling and transduction models in various tasks, allowing modeling of dependencies without regard to their distance in the input or output sequences [2, 16].
注意力机制已成为各种任务(引人注目的序列建模和转导模型)的重要组成部分,允许对依赖关系进行建模,而不考虑它们在输入或输出序列中的距离[2,16]。
In all but a few cases [22], however, such attention mechanisms are used in conjunction with a recurrent network.
然而,在除少数情况外的所有情况下[22],这种注意力机制都与循环网络结合使用。
第四段:Transformer的特点
In this work we propose the Transformer, a model architecture eschewing recurrence and instead relying entirely on an attention mechanism to draw global dependencies between input and output.
在这项工作中,我们提出了Transformer,这是一种避免重复的模型架构,完全依赖于注意力机制来绘制输入和输出之间的全局依赖关系。
The Transformer allows for significantly more parallelization and can reach a new state of the art in translation quality after being trained for as little as twelve hours on eight P100 GPUs.
Transformer允许更多的并行化,并且在8个P100 GPU上训练了12个小时后,可以在翻译质量方面达到新的水平。
写作技巧:
首先提出循环神经网络是最新方法,在描述其机制时引出了并行性限制的问题,再通过介绍注意力机制不考虑输入输出序列距离的特点,从而体现transformer模型在并行性方面的优势,并且举例说明。
2 背景(Background)
第一段:依赖关系学习
The goal of reducing sequential computation also forms the foundation of the Extended Neural GPU[20], ByteNet [15] and ConvS2S [8], all of which use convolutional neural networks as basic building block, computing hidden representations in parallel for all input and output positions.
减少顺序计算的目标也构成了扩展神经GPU[20]、ByteNet[15]和ConvS2S[8]的基础,所有这些都使用卷积神经网络作为基本构建块,并行计算所有输入和输出位置的隐藏表示。
In these models, the number of operations required to relate signals from two arbitrary input or output positions grows in the distance between positions, linearly for ConvS2S and logarithmically for ByteNet.
在这些模型中,关联来自两个任意输入或输出位置的信号所需的操作数量随着位置之间的距离而增长,对于ConvS2S是线性增长的,对于ByteNet是对数增长的。
This makes it more difficult to learn dependencies between distant positions [11].
这使得学习远距离位置之间的依赖关系变得更加困难[11]。
依赖关系(dependency)指的是序列数据中各个元素之间的相互依赖或关联关系。这些依赖关系对于模型来说非常重要,因为它们决定了如何有效地理解和处理序列数据。
- 时间依赖性:序列数据通常具有时间上的依赖关系,即当前时刻的数据与之前时刻的数据相关联。例如,在语音识别中,理解当前词的语音片段可能需要考虑前面的声音上下文。
- 空间依赖性:除了时间上的依赖关系外,序列中的元素可能还存在空间上的依赖关系。例如,在自然语言处理中,一个单词的含义可能依赖于其前面几个单词的上下文。
- 长距离依赖:有些任务需要模型能够捕捉较长距离的依赖关系,即当前位置的预测可能依赖于序列中较远位置的信息。例如,机器翻译中,译文的某个词可能受源语言中较远位置的多个词影响。
In the Transformer this is reduced to a constant number of operations, albeit at the cost of reduced effective resolution due to averaging attention-weighted positions, an effect we counteract with Multi-Head Attention as described in section 3.2.
在Transformer中,这被减少到恒定数量的操作,尽管由于平均注意力加权位置而降低了有效分辨率,但我们使用第 3.2 节中描述的多头注意力来抵消这种影响。
第二段:自注意力
Self-attention, sometimes called intra-attention is an attention mechanism relating different positions of a single sequence in order to compute a representation of the sequence.
自我注意,有时也称为内部注意,是一种将单个序列的不同位置联系起来以计算序列表示的注意机制。
自注意力(Self-attention) 一种用于处理序列数据中长距离依赖关系的方法,能够有效地捕捉序列内部不同位置之间的关系,而无需依赖于序列的固定长度窗口或者固定的
- 工作原理:自注意力机制的核心在于,每个位置的输出不仅依赖于当前位置的输入,还依赖于所有其他位置的输入,且这种依赖关系是动态计算的。这使得模型能够在处理序列时,同时考虑到序列中不同位置的全局依赖关系,而不仅仅局限于固定的局部窗口。
- 在Transformer中的应用:Transformer模型中的自注意力层允许模型同时处理输入序列的所有位置,使得模型能够更好地捕捉长距离依赖关系,从而在各种序列到序列的任务中取得了显著的性能提升。
Self-attention has been used successfully in a variety of tasks including reading comprehension, abstractive summarization, textual entailment and learning task-independent sentence representations [4, 22, 23, 19].
自我注意已被成功应用于各种任务,包括阅读理解、抽象概括、文本蕴涵和独立于学习任务的句子表征[4,22,23,19]。
第三段:端到端记忆网络
End-to-end m