第11章注意機構とTransformer
11. Attention Mechanisms and Transformers11 注意機構とTransformer
The earliest years of the deep learning boom were driven primarily by results produced using the multilayer perceptron, convolutional network, and recurrent network architectures. Remarkably, the model architectures that underpinned many of deep learning’s breakthroughs in the 2010s had changed remarkably little relative to their antecedents despite the lapse of nearly 30 years. While plenty of new methodological innovations made their way into most practitioner’s toolkits—ReLU activations, residual layers, batch normalization, dropout, and adaptive learning rate schedules come to mind—the core underlying architectures were clearly recognizable as scaled-up implementations of classic ideas. Despite thousands of papers proposing alternative ideas, models resembling classical convolutional neural networks (Section 7) retained state-of-the-art status in computer vision and models resembling Sepp Hochreiter’s original design for the LSTM recurrent neural network (Section 10.1), dominated most applications in natural language processing. Arguably, to that point, the rapid emergence of deep learning appeared to be primarily attributable to shifts in the available computational resources (thanks to innovations in parallel computing with GPUs) and the availability of massive data resources (thanks to cheap storage and Internet services). While these factors may indeed remain the primary drivers behind this technology’s increasing power we are also witnessing, at long last, a sea change in the landscape of dominant architectures.
英語のヒント
深層学習ブームの最初の数年は、主に多層パーセプトロン、畳み込みネットワーク、リカレントネットワークの構造で得られた結果によって推し進められた。驚くべきことに、2010年代の深層学習の突破口の多くを支えたモデルの構造は、30年近い歳月が経ったにもかかわらず、その先祖と比べてほとんど変わっていなかった。ReLU活性化、残差層、バッチ正規化、ドロップアウト、適応的な学習率のスケジュールなど、新しい方法論上の革新の多くがほとんどの実践者の道具箱に入ったが、根底にある中核の構造は、古典的な考えを規模を大きくして実装したものだと明らかに見てとれた。別の考えを提案する何千もの論文にもかかわらず、古典的な畳み込みニューラルネットワーク(第7章)に似たモデルがコンピュータビジョンで最先端の地位を保ち、Sepp HochreiterによるLSTMリカレントニューラルネットワークの元の設計(10.1節)に似たモデルが、自然言語処理のほとんどの応用を支配していた。おそらく、その時点までは、深層学習の急速な台頭は、主に、利用できる計算資源の変化(GPUによる並列計算の革新のおかげ)と、膨大なデータ資源が使えるようになったこと(安価な記憶装置とインターネットのサービスのおかげ)によるものだったように見える。これらの要因は、この技術の力が増していく主な原動力であり続けているのかもしれないが、私たちはついに、支配的な構造の地形の大変動も目撃している。
At the present moment, the dominant models for nearly all natural language processing tasks are based on the Transformer architecture. Given any new task in natural language processing, the default first-pass approach is to grab a large Transformer-based pretrained model, (e.g., BERT (Devlin et al., 2018), ELECTRA (Clark et al., 2020), RoBERTa (Liu et al., 2019), or Longformer (Beltagy et al., 2020)) adapting the output layers as necessary, and fine-tuning the model on the available data for the downstream task. If you have been paying attention to the last few years of breathless news coverage centered on OpenAI’s large language models, then you have been tracking a conversation centered on the GPT-2 and GPT-3 Transformer-based models (Brown et al., 2020, Radford et al., 2019). Meanwhile, the vision Transformer has emerged as a default model for diverse vision tasks, including image recognition, object detection, semantic segmentation, and superresolution (Dosovitskiy et al., 2021, Liu et al., 2021). Transformers also showed up as competitive methods for speech recognition (Gulati et al., 2020), reinforcement learning (Chen et al., 2021), and graph neural networks (Dwivedi and Bresson, 2020).
英語のヒント
現時点では、ほぼすべての自然言語処理の課題で支配的なモデルは、Transformerの構造にもとづいている。自然言語処理の新しい課題が与えられたとき、まず試す既定のやり方は、Transformerにもとづく大きな事前学習済みモデル(たとえばBERT(Devlin et al., 2018)、ELECTRA(Clark et al., 2020)、RoBERTa(Liu et al., 2019)、Longformer(Beltagy et al., 2020))を手に取り、必要に応じて出力層を合わせ、下流の課題で使えるデータでモデルを微調整することである。ここ数年の、OpenAIの大規模言語モデルを中心にした息もつかせぬ報道に注目してきたなら、Transformerにもとづくモデルである GPT-2とGPT-3(Brown et al., 2020、Radford et al., 2019)を中心にした話題を追ってきたことになる。一方、視覚のTransformerは、画像認識、物体検出、セマンティックセグメンテーション、超解像を含む多様な視覚の課題の既定のモデルとして台頭してきた(Dosovitskiy et al., 2021、Liu et al., 2021)。Transformerは、音声認識(Gulati et al., 2020)、強化学習(Chen et al., 2021)、グラフニューラルネットワーク(Dwivedi and Bresson, 2020)でも互角の手法として現れた。
The core idea behind the Transformer model is the attention mechanism, an innovation that was originally envisioned as an enhancement for encoder–decoder RNNs applied to sequence-to-sequence applications, such as machine translations (Bahdanau et al., 2014). You might recall that in the first sequence-to-sequence models for machine translation (Sutskever et al., 2014), the entire input was compressed by the encoder into a single fixed-length vector to be fed into the decoder. The intuition behind attention is that rather than compressing the input, it might be better for the decoder to revisit the input sequence at every step. Moreover, rather than always seeing the same representation of the input, one might imagine that the decoder should selectively focus on particular parts of the input sequence at particular decoding steps. Bahdanau’s attention mechanism provided a simple means by which the decoder could dynamically attend to different parts of the input at each decoding step. The high-level idea is that the encoder could produce a representation of length equal to the original input sequence. Then, at decoding time, the decoder can (via some control mechanism) receive as input a context vector consisting of a weighted sum of the representations on the input at each time step. Intuitively, the weights determine the extent to which each step’s context “focuses” on each input token, and the key is to make this process for assigning the weights differentiable so that it can be learned along with all of the other neural network parameters.
英語のヒント
Transformerのモデルの背後にある中核の考えは注意機構である。これは、もともと、機械翻訳のような系列から系列への応用に当てはめるエンコーダ・デコーダRNNの強化として構想された革新だった(Bahdanau et al., 2014)。機械翻訳の最初の系列から系列へのモデル(Sutskever et al., 2014)では、入力全体がエンコーダによって一つの固定長のベクトルに圧縮され、デコーダに入れられたことを覚えているかもしれない。注意の背後にある直観は、入力を圧縮するのではなく、デコーダが各ステップで入力系列を見直すほうがよいかもしれない、ということである。さらに、いつも入力の同じ表現を見るのではなく、デコーダは特定の復号ステップで入力系列の特定の部分に選択的に焦点を当てるべきだ、と想像できるかもしれない。Bahdanauの注意機構は、デコーダが各復号ステップで入力の異なる部分に動的に注意を向けられる、単純な手段を与えた。大まかな考えは、エンコーダが元の入力系列と同じ長さの表現を生み出せる、ということである。そして、復号のときには、デコーダは(何らかの制御の仕組みを通じて)、各時間ステップの入力の表現の重みつきの和からなる文脈ベクトルを入力として受け取れる。直観的には、重みは、各ステップの文脈が各入力トークンにどの程度「焦点を当てる」かを決める。鍵は、この重みを割り当てる過程を微分可能にして、ほかのすべてのニューラルネットワークのパラメータとともに学習できるようにすることである。
Initially, the idea was a remarkably successful enhancement to the recurrent neural networks that already dominated machine translation applications. The models performed better than the original encoder–decoder sequence-to-sequence architectures. Furthermore, researchers noted that some nice qualitative insights sometimes emerged from inspecting the pattern of attention weights. In translation tasks, attention models often assigned high attention weights to cross-lingual synonyms when generating the corresponding words in the target language. For example, when translating the sentence “my feet hurt” to “j’ai mal au pieds”, the neural network might assign high attention weights to the representation of “feet” when generating the corresponding French word “pieds”. These insights spurred claims that attention models confer “interpretability” although what precisely the attention weights mean—i.e., how, if at all, they should be interpreted remains a hazy research topic.
英語のヒント
当初、この考えは、すでに機械翻訳の応用を支配していたリカレントニューラルネットワークへの、驚くほど成功した強化だった。モデルは、元のエンコーダ・デコーダの系列から系列への構造より性能がよかった。さらに、研究者たちは、注意の重みのパターンを調べると、ときどき質的によい洞察が浮かび上がることに気づいた。翻訳の課題では、注意のモデルは、目標言語で対応する単語を生成するとき、言語をまたぐ同義語にしばしば高い注意の重みを割り当てた。たとえば、「my feet hurt(足が痛い)」という文を「j’ai mal au pieds」に翻訳するとき、ニューラルネットワークは、対応するフランス語の単語「pieds」を生成する際に、「feet」の表現に高い注意の重みを割り当てるかもしれない。こうした洞察から、注意のモデルは「解釈可能性」をもたらすという主張が生まれたが、注意の重みが正確に何を意味するのか、つまり、そもそもどう解釈すべきなのかは、いまだぼんやりした研究課題のままである。
However, attention mechanisms soon emerged as more significant concerns, beyond their usefulness as an enhancement for encoder–decoder recurrent neural networks and their putative usefulness for picking out salient inputs. Vaswani et al. (2017) proposed the Transformer architecture for machine translation, dispensing with recurrent connections altogether, and instead relying on cleverly arranged attention mechanisms to capture all relationships among input and output tokens. The architecture performed remarkably well, and by 2018 the Transformer began showing up in the majority of state-of-the-art natural language processing systems. Moreover, at the same time, the dominant practice in natural language processing became to pretrain large-scale models on enormous generic background corpora to optimize some self-supervised pretraining objective, and then to fine-tune these models using the available downstream data. The gap between Transformers and traditional architectures grew especially wide when applied in this pretraining paradigm, and thus the ascendance of Transformers coincided with the ascendence of such large-scale pretrained models, now sometimes called foundation models (Bommasani et al., 2021).
英語のヒント
しかし、注意機構はやがて、エンコーダ・デコーダのリカレントニューラルネットワークの強化としての有用さや、目立つ入力を選び出すのに役立つとされる点を超えて、もっと重要なものとして浮上した。Vaswani et al. (2017)は、再帰的な接続をまったく使わず、代わりに巧みに配置した注意機構に頼って入力と出力のトークンのあいだのすべての関係をとらえる、機械翻訳のためのTransformerの構造を提案した。この構造は目覚ましい性能を出し、2018年までには、最先端の自然言語処理のシステムの大多数にTransformerが現れ始めた。さらに同時に、自然言語処理で支配的なやり方は、何らかの自己教師ありの事前学習の目的を最適化するように、膨大な汎用の背景コーパスで大規模なモデルを事前学習し、それから使える下流のデータでこれらのモデルを微調整する、というものになった。Transformerと伝統的な構造との差は、この事前学習のパラダイムで当てはめたときに特に広がり、そのため、Transformerの台頭は、今では基盤モデルと呼ばれることもある、こうした大規模な事前学習済みモデルの台頭と重なった(Bommasani et al., 2021)。
In this chapter, we introduce attention models, starting with the most basic intuitions and the simplest instantiations of the idea. We then work our way up to the Transformer architecture, the vision Transformer, and the landscape of modern Transformer-based pretrained models.
英語のヒント
この章では、最も基本的な直観とこの考えの最も単純な具体化から始めて、注意のモデルを紹介する。それから、Transformerの構造、視覚のTransformer、そして現代のTransformerにもとづく事前学習済みモデルの全体像へと進んでいく。