第11章注意機構とTransformer
11.9.2. Encoder–Decoder11.9.2 エンコーダ・デコーダ
Since a Transformer encoder converts a sequence of input tokens into the same number of output representations, the encoder-only mode cannot generate a sequence of arbitrary length as in machine translation. As originally proposed for machine translation, the Transformer architecture can be outfitted with a decoder that autoregressively predicts the target sequence of arbitrary length, token by token, conditional on both encoder output and decoder output: (i) for conditioning on encoder output, encoder–decoder cross-attention (multi-head attention of decoder in Fig. 11.7.1) allows target tokens to attend to all input tokens; (ii) conditioning on decoder output is achieved by a so-called causal attention (this name is common in the literature but is misleading as it has little connection to the proper study of causality) pattern (masked multi-head attention of decoder in Fig. 11.7.1), where any target token can only attend to past and present tokens in the target sequence.
英語のヒント
Transformerのエンコーダは入力トークンの系列を同じ数の出力表現に変換するので、エンコーダのみのモードでは、機械翻訳のように任意の長さの系列を生成できない。もともと機械翻訳のために提案されたとおり、Transformerの構造には、エンコーダの出力とデコーダの出力の両方を条件として、任意の長さの目標系列をトークンごとに自己回帰的に予測するデコーダを備えられる。(i)エンコーダの出力を条件とするために、エンコーダ・デコーダのクロス注意(図11.7.1のデコーダのマルチヘッド注意)によって、目標のトークンはすべての入力トークンに注意を向けられる。(ii)デコーダの出力を条件とすることは、いわゆる因果的注意(この名前は文献ではよく使われるが、因果性の本来の研究とはほとんど関係がないので誤解を招く)のパターン(図11.7.1のデコーダのマスクつきマルチヘッド注意)によって実現される。そこでは、どの目標トークンも、目標系列の過去と現在のトークンにだけ注意を向けられる。
To pretrain encoder–decoder Transformers beyond human-labeled machine translation data, BART (Lewis et al., 2019) and T5 (Raffel et al., 2020) are two concurrently proposed encoder–decoder Transformers pretrained on large-scale text corpora. Both attempt to reconstruct original text in their pretraining objectives, while the former emphasizes noising input (e.g., masking, deletion, permutation, and rotation) and the latter highlights multitask unification with comprehensive ablation studies.
英語のヒント
人間がラベルをつけた機械翻訳のデータを超えてエンコーダ・デコーダのTransformerを事前学習するため、BART(Lewis et al., 2019)とT5(Raffel et al., 2020)という、大規模なテキストコーパスで事前学習した二つのエンコーダ・デコーダのTransformerが同時期に提案された。どちらも事前学習の目的で元のテキストを再構成しようとするが、前者は入力にノイズを加えること(たとえばマスク、削除、並べ替え、回転)を重視し、後者は包括的なアブレーション研究によるマルチタスクの統一を前面に出している。
11.9.2.1. Pretraining T511.9.2.1 T5の事前学習
As an example of the pretrained Transformer encoder–decoder, T5 (Text-to-Text Transfer Transformer) unifies many tasks as the same text-to-text problem: for any task, the input of the encoder is a task description (e.g., “Summarize”, “:”) followed by task input (e.g., a sequence of tokens from an article), and the decoder predicts the task output (e.g., a sequence of tokens summarizing the input article). To perform as text-to-text, T5 is trained to generate some target text conditional on input text.
英語のヒント
事前学習したTransformerのエンコーダ・デコーダの例として、T5(Text-to-Text Transfer Transformer)は、多くの課題を同じテキストからテキストへの問題として統一する。どの課題でも、エンコーダの入力は課題の説明(たとえば「Summarize」「:」)とその後に続く課題の入力(たとえば記事のトークンの系列)であり、デコーダは課題の出力(たとえば入力の記事を要約するトークンの系列)を予測する。テキストからテキストとしてふるまうため、T5は入力テキストを条件として何らかの目標テキストを生成するよう訓練される。
Fig. 11.9.3図11.9.3
Left: Pretraining T5 by predicting consecutive spans. The original sentence is “I”, “love”, “this”, “red”, “car”, where “love” is replaced by a special “<X>” token, and consecutive “red”, “car” are replaced by a special “<Y>” token. The target sequence ends with a special “<Z>” token. Right: Attention pattern in the Transformer encoder–decoder. In the encoder self-attention (lower square), all input tokens attend to each other; In the encoder–decoder cross-attention (upper rectangle), each target token attends to all input tokens; In the decoder self-attention (upper triangle), each target token attends to present and past target tokens only (causal).
英語のヒント
左:連続する区間を予測することによるT5の事前学習。元の文は「I」「love」「this」「red」「car」であり、「love」は特別な「<X>」トークンに、連続する「red」「car」は特別な「<Y>」トークンに置き換えられる。目標系列は特別な「<Z>」トークンで終わる。右:Transformerのエンコーダ・デコーダの注意のパターン。エンコーダの自己注意(下の正方形)では、すべての入力トークンが互いに注意を向け合う。エンコーダ・デコーダのクロス注意(上の長方形)では、各目標トークンがすべての入力トークンに注意を向ける。デコーダの自己注意(上の三角形)では、各目標トークンは現在と過去の目標トークンにだけ注意を向ける(因果的)。
To obtain input and output from any original text, T5 is pretrained to predict consecutive spans. Specifically, tokens from text are randomly replaced by special tokens where each consecutive span is replaced by the same special token. Consider the example in Fig. 11.9.3, where the original text is “I”, “love”, “this”, “red”, “car”. Tokens “love”, “red”, “car” are randomly replaced by special tokens. Since “red” and “car” are a consecutive span, they are replaced by the same special token. As a result, the input sequence is “I”, “<X>”, “this”, “<Y>”, and the target sequence is “<X>”, “love”, “<Y>”, “red”, “car”, “<Z>”, where “<Z>” is another special token marking the end. As shown in Fig. 11.9.3, the decoder has a causal attention pattern to prevent itself from attending to future tokens during sequence prediction.
英語のヒント
任意の元のテキストから入力と出力を得るため、T5は連続する区間を予測するよう事前学習される。具体的には、テキストのトークンがランダムに特別なトークンに置き換えられ、連続する各区間は同じ特別なトークンに置き換えられる。図11.9.3の例を考えよう。元のテキストは「I」「love」「this」「red」「car」である。トークン「love」「red」「car」がランダムに特別なトークンに置き換えられる。「red」と「car」は連続する区間なので、同じ特別なトークンに置き換えられる。その結果、入力系列は「I」「<X>」「this」「<Y>」となり、目標系列は「<X>」「love」「<Y>」「red」「car」「<Z>」となる。ここで、「<Z>」は終わりを示す別の特別なトークンである。図11.9.3に示すように、デコーダは、系列の予測のあいだに未来のトークンに注意を向けないよう、因果的注意のパターンをもつ。
In T5, predicting consecutive span is also referred to as reconstructing corrupted text. With this objective, T5 is pretrained with 1000 billion tokens from the C4 (Colossal Clean Crawled Corpus) data, which consists of clean English text from the web (Raffel et al., 2020).
英語のヒント
T5では、連続する区間を予測することは、壊れたテキストを再構成することとも呼ばれる。この目的で、T5は、ウェブからのきれいな英語のテキストからなるC4(Colossal Clean Crawled Corpus)のデータから、1兆トークンで事前学習される(Raffel et al., 2020)。
11.9.2.2. Fine-Tuning T511.9.2.2 T5の微調整
Similar to BERT, T5 needs to be fine-tuned (updating T5 parameters) on task-specific training data to perform this task. Major differences from BERT fine-tuning include: (i) T5 input includes task descriptions; (ii) T5 can generate sequences with arbitrary length with its Transformer decoder; (iii) No additional layers are required.
英語のヒント
BERTと同じように、T5もこの課題をこなすには、課題に特化した訓練データで微調整(T5のパラメータを更新すること)する必要がある。BERTの微調整との主な違いは次のとおりである。(i)T5の入力は課題の説明を含む。(ii)T5はTransformerのデコーダで任意の長さの系列を生成できる。(iii)追加の層は要らない。
Fig. 11.9.4図11.9.4
Fine-tuning T5 for text summarization. Both the task description and article tokens are fed into the Transformer encoder for predicting the summary.
英語のヒント
テキスト要約のためのT5の微調整。課題の説明と記事のトークンの両方がTransformerのエンコーダに入れられ、要約を予測する。
Fig. 11.9.4 explains fine-tuning T5 using text summarization as an example. In this downstream task, the task description tokens “Summarize”, “:” followed by the article tokens are input to the encoder.
英語のヒント
図11.9.4は、テキスト要約を例にT5の微調整を説明している。この下流の課題では、課題の説明のトークン「Summarize」「:」とその後に続く記事のトークンがエンコーダに入力される。
After fine-tuning, the 11-billion-parameter T5 (T5-11B) achieved state-of-the-art results on multiple encoding (e.g., classification) and generation (e.g., summarization) benchmarks. Since released, T5 has been extensively used in later research. For example, switch Transformers are designed based on T5 to activate a subset of the parameters for better computational efficiency (Fedus et al., 2022). In a text-to-image model called Imagen, text is input to a frozen T5 encoder (T5-XXL) with 4.6 billion parameters (Saharia et al., 2022). The photorealistic text-to-image examples in Fig. 11.9.5 suggest that the T5 encoder alone may effectively represent text even without fine-tuning.
英語のヒント
微調整の後、110億パラメータのT5(T5-11B)は、複数の符号化(たとえば分類)と生成(たとえば要約)のベンチマークで最先端の結果を達成した。公開されて以来、T5は後の研究で広く使われてきた。たとえば、スイッチTransformerは、計算の効率をよくするためにパラメータの一部だけを働かせるよう、T5にもとづいて設計されている(Fedus et al., 2022)。Imagenと呼ばれるテキストから画像へのモデルでは、テキストは46億パラメータの凍結したT5のエンコーダ(T5-XXL)に入力される(Saharia et al., 2022)。図11.9.5の写実的なテキストから画像への例は、T5のエンコーダだけでも、微調整なしでテキストを効果的に表現できるかもしれないことを示唆している。
Image omitted because its reuse rights could not be verified.権利の確認ができないため画像を割愛。
Fig. 11.9.5図11.9.5