（空气呼啸） (air whooshing)
- 什么是转移学习？ - What is transfer learning?
转移学习的思想 The idea of transfer learning
是利用在另一项任务上使用大量数据训练的模型结果 is to leverage the knowledge acquired
来获取知识。 by a model trained with lots of data on another task.
模型 A 将专门针对任务 A 进行训练。 The model A will be trained specifically for task A.
现在假设您想为了另一个任务 Now let's say you want to train a model B
训练模型 B。 for a different task.
一种选择是从头开始训练模型。 One option would be to train the model from scratch.
但这可能需要大量的计算、时间和数据。 This could take lots of computation, time and data.
我们可以有另一种选择，初始化模型 B Instead, we could initialize model B
它与模型 A 具有相同的权重， with the same weights as model A,
将模型 A 的知识转移到任务 B 上。 transferring the knowledge of model A on task B.
从头开始训练时， When training from scratch,
所有模型的权重都是随机初始化的。 all the model's weight are initialized randomly.
在这个例子中，我们正在基于识别任务上 In this example, we are training a BERT model
训练一个 BERT 模型 on the task of recognizing
来判断两个句子是否相似。 if two sentences are similar or not.
左边的例子是从头开始训练的， On the left, it's trained from scratch,
右边则代表正在微调预训练模型。 and on the right it's fine-tuning a pretrained model.
正如我们所见，使用转移学习 As we can see, using transfer learning
和预训练模型产生了更好的结果。 and the pretrained model yields better results.
如果我们训练更长时间也没关系。 And it doesn't matter if we train longer.
从头开始的训练准确率上限在 70% 左右 The training from scratch is capped around 70% accuracy
而预训练模型轻松达到了 86%。 while the pretrained model beats the 86% easily.
这是因为预训练模型 This is because pretrained models
通常基于大量数据进行训练 are usually trained on large amounts of data
这些数据为模型在预训练期间 that provide the model with a statistical understanding
提供了对语言使用的统计理解。 of the language used during pretraining.
在计算机视觉中， In computer vision,
转移学习已成功应用 transfer learning has been applied successfully
将近十年。 for almost ten years.
模型经常在 ImageNet 上进行预训练， Models are frequently pretrained on ImageNet,
它是一种包含 120 万张照片图像的数据集。 a dataset containing 1.2 millions of photo images.
每个图像都按 1000 个标签中的一个进行分类。 Each image is classified by one of 1000 labels.
像这样在标记数据上训练 Training like this, on labeled data
称为监督学习。 is called supervised learning.
在自然语言处理中， In Natural Language Processing,
转移学习是最近才出现的。 transfer learning is a bit more recent.
它与 ImageNet 的一个关键区别是预训练 A key difference with ImageNet is that the pretraining
通常是自我监督的， is usually self-supervised,
这意味着它不需要人工对标签 which means it doesn't require humans annotations
进行注释。 for the labels.
一个非常常见的预训练目标 A very common pretraining objective
是猜测句子中的下一个单词。 is to guess the next word in a sentence.
它只需要大量的输入文本。 Which only requires lots and lots of text.
例如 GPT-2，就是这样预训练的 GPT-2 for instance, was pretrained this way
它使用 4500 万个用户在 Reddit 上发布的 using the content of 45 millions links
链接的内容。 posted by users on Reddit.
自监督预训练目标的另一个例子 Another example of self-supervised pretraining objective
是预测随机屏蔽词的值。 is to predict the value of randomly masked words.
这类似于填空测试 Which is similar to fill-in-the-blank tests
您可能在学校做过。 you may have done in school.
BERT 是使用英文维基百科和 11,000 本未出版的书籍 BERT was pretrained this way using the English Wikipedia
进行预训练的。 and 11,000 unpublished books.
在实践中，转移学习是通过抛弃原模型的头部 In practice, transfer learning is applied on a given model
即其针对预训练目标的最后几层 by throwing away its head, that is,
并用一个新的、随机初始化的头部 its last layers focused on the pretraining objective,
来替换它来应用的 and replacing it with a new, randomly initialized head
这个新的头部适用于当前的任务。 suitable for the task at hand.
例如，当我们之前微调 BERT 模型时， For instance, when we fine-tuned a BERT model earlier,
我们删除了分类掩码词的头部 we removed the head that classified mask words
并将其替换为具有 2 个输出的分类器。 and replaced it with a classifier with 2 outputs.
因为我们的任务有两个标签。 Since our task had two labels.
为了尽可能高效 To be as efficient as possible, the pretrained model used
所使用的预训练模型 should be as similar as possible
应尽可能与其微调的任务相似。 to the task it's fine-tuned on.
例如，如果当前需要 For instance, if the problem
对德语句子进行分类， is to classify German sentences,
最好使用德语预训练模型。 it's best to use a German pretrained model.
但有好事也有坏事。 But with the good comes the bad.
预训练模型不仅转移了它的知识， The pretrained model does not only transfer its knowledge,
同时也转移了它可能包含的任何偏见。 but also any bias it may contain.
ImageNet 主要包含来自美国和西欧 ImageNet mostly contains images
的图像。 coming from the United States and Western Europe.
所以基于它进行微调的模型 So models fine-tuned with it
通常会在来自这些国家或地区的图像上表现更好。 usually will perform better on images from these countries.
OpenAI 还研究了 OpenAI also studied the bias
其使用猜测下一个单词目标 in the predictions of its GPT-3 model
预训练的 GPT-3 模型中 which was pretrained
预测的偏差。 using the guess the next word objective.
将提示的性别 Changing the gender of the prompt
从“他”更改到“她” from he was very to she was very
会使预测从主要是中性形容词 changed the predictions from mostly neutral adjectives
变为几乎只有物理上的形容词。 to almost only physical ones.
在他们的 GPT-2 的模型卡中， In their model card of the GPT-2 model,
OpenAI 也承认了它的偏见 OpenAI also acknowledges its bias
并且不鼓励在与人类交互的系统中 and discourages its use
使用它。 in systems that interact with humans.
（空气呼啸） (air whooshing)