第15章自然言語処理:事前学習
15.8.3. BERT: Combining the Best of Both Worlds15.8.3 BERT:両方のよいところを組み合わせる
As we have seen, ELMo encodes context bidirectionally but uses task-specific architectures; while GPT is task-agnostic but encodes context left-to-right. Combining the best of both worlds, BERT (Bidirectional Encoder Representations from Transformers) encodes context bidirectionally and requires minimal architecture changes for a wide range of natural language processing tasks (Devlin et al., 2018). Using a pretrained Transformer encoder, BERT is able to represent any token based on its bidirectional context. During supervised learning of downstream tasks, BERT is similar to GPT in two aspects. First, BERT representations will be fed into an added output layer, with minimal changes to the model architecture depending on nature of tasks, such as predicting for every token vs. predicting for the entire sequence. Second, all the parameters of the pretrained Transformer encoder are fine-tuned, while the additional output layer will be trained from scratch. Fig. 15.8.1 depicts the differences among ELMo, GPT, and BERT.
英語のヒント
これまで見てきたように、ELMoは文脈を双方向に符号化するがタスク固有のアーキテクチャを使い、一方GPTはタスクに依存しないが文脈を左から右へ符号化する。両方のよいところを組み合わせて、BERT(Bidirectional Encoder Representations from Transformers、Transformerによる双方向エンコーダ表現)は文脈を双方向に符号化し、幅広い自然言語処理のタスクに対して、アーキテクチャにわずかな変更しか必要としない(Devlin et al., 2018)。事前学習したTransformerのエンコーダを使うことで、BERTはどのトークンも、その双方向の文脈にもとづいて表せる。下流のタスクの教師あり学習のあいだ、BERTは二つの点でGPTに似ている。第一に、BERTの表現は追加した出力層に入れられ、モデルのアーキテクチャには、各トークンについて予測するか系列全体について予測するかといったタスクの性質に応じて、わずかな変更を加えるだけである。第二に、事前学習したTransformerのエンコーダのパラメータはすべて微調整され、追加の出力層は一から訓練される。図15.8.1は、ELMo、GPT、BERTの違いを描いている。
Fig. 15.8.1図15.8.1
A comparison of ELMo, GPT, and BERT.
英語のヒント
ELMo、GPT、BERTの比較。
BERT further improved the state of the art on eleven natural language processing tasks under broad categories of (i) single text classification (e.g., sentiment analysis), (ii) text pair classification (e.g., natural language inference), (iii) question answering, (iv) text tagging (e.g., named entity recognition). All proposed in 2018, from context-sensitive ELMo to task-agnostic GPT and BERT, conceptually simple yet empirically powerful pretraining of deep representations for natural languages have revolutionized solutions to various natural language processing tasks.
英語のヒント
BERTはさらに、(i) 単一テキストの分類(たとえば感情分析)、(ii) テキスト対の分類(たとえば自然言語推論)、(iii) 質問応答、(iv) テキストのタグづけ(たとえば固有表現認識)という大まかな区分のもとで、11の自然言語処理のタスクで最先端を更新した。文脈に依存するELMoから、タスクに依存しないGPTやBERTまで、どれも2018年に提案された、概念的には単純だが経験的には強力な、自然言語の深い表現の事前学習は、さまざまな自然言語処理のタスクの解法に革命をもたらした。
In the rest of this chapter, we will dive into the pretraining of BERT. When natural language processing applications are explained in Section 16, we will illustrate fine-tuning of BERT for downstream applications.
英語のヒント
この章の残りでは、BERTの事前学習に深く入り込む。第16章で自然言語処理の応用を説明するときに、下流の応用のためのBERTの微調整を示す。
import torch
from torch import nn
from d2l import torch as d2l