（空气呼啸） (air whooshing)
- 在我们的其他视频中， - In our other videos,
和往常一样，下面会有链接 and as always, there'll be links below
如果你想回看那些， if you want to check those out,
我们向你展示了如何初始化和微调 we showed you how to initialize and fine-tune
TensorFlow 中的 transformer 模型。 a transformer model in TensorFlow.
所以现在的问题是，我们可以用模型做什么 So the question now is, what can we do with a model
在我们训练之后？ after we train it?
显而易见的尝试 The obvious thing to try
是用它来获得对新数据的预测， is to use it to get predictions for new data,
所以让我们看看如何做到这一点。 so let's see how to do that.
同样，如果你熟悉 Keras，那么好消息是 Again, if you're familiar with Keras, the good news is
因为只有标准的 Keras 模型， that because there are just standard Keras models,
我们可以使用标准的 Keras 预测方法， we can use the standard Keras predict method,
如此处所示。 as shown here.
你只需将分词化的文本传递给此方法， You simply pass in tokenized text to this method,
就像你从分词器那里得到的一样， like you'd get from a tokenizer,
你得到你的结果。 and you get your results.
我们的模型可以输出几种不同的东西， Our models can output several different things,
根据你设置的选项， depending on the options you set,
但大多数时候你想要的东西 but most of the time the thing you want
是输出的 logits 。 is the output logits.
如果你在之前没有遇到过它们，logits If you haven't come across them before, logits,
有时发音成 logits ，因为没有人确定， sometimes pronounced to logits because no one's sure,
是网络最后一层的输出 are the outputs of the last layer of the network
因为在使用 softmax 之前。 because before a softmax has been applied.
所以如果你想把 logits So if you want to turn the logits
进成模型的概率输出， into the model's probability outputs,
你只需使用一个 softmax，就像这样。 you just apply a softmax, like so.
如果我们想这些概率 What if we want to turn those probabilities
进成类别预测？ into class predictions?
同样，它非常直接。 Again, it's very straightforward.
我们只是为每个输出选择最大的概率 We just pick the biggest probability for each output
你可以使用 argmax 函数立即获得它。 and you can get that immediately with the argmax function.
argmax 将返回索引 argmax will return the index
每行中的最大概率 of the largest probability in each row
这意味着我们将得到一个整数向量。 which means that we'll get a vector of integers.
如果最大概率在零位置，则为零， So zero if the largest probability was in the zero position,
一个在第一个位置，依此类推。 one in the first position, and so on.
所以这些是我们的类预测表明第零类， So these are our class predictions indicating class zero,
第一类，等等。 class one, and so on.
事实上，如果你想要的只是类别预测， In fact, if class predictions are all you want,
你可以完全跳过 softmax 步骤 you can skip the softmax step entirely
因为最大的 logit 永远是最大的 because the largest logit will always be the largest
概率也一样。 probability as well.
所以如果你想要概率和类别预测， So if probabilities and class predictions are all you want,
那么此时你已经看到了所需的一切。 then you've seen everything you need at this point.
但是如果你有兴趣对你的模型进行基准测试 But if you're interested in benchmarking your model
或将其用于研究， or using it for research,
你可能想更深入地研究你得到的结果。 you might want to delve deeper into the results you get.
一种方法是计算一些指标 And one way to do that is to compute some metrics
用于模型的预测。 for the model's predictions.
如果你关注我们有关数据集 If you're following along with our datasets
和微调的视频， and fine tuning videos,
我们从 MRPC 数据集中获取数据， we got our data from the MRPC dataset,
这是 GLUE 基准的一部分。 which is part of the GLUE benchmark.
GLUE 数据集的每一个 Each of the GLUE datasets
以及我们数据集 Light Hub 中的许多其他数据集 as well as many other datasets in our dataset, Light Hub
有一些预定义的指标， has some predefined metrics,
我们可以轻松加载它们 and we can load them easily
使用数据集加载度量函数。 with the datasets load metric function.
对于 MRPC 数据集，内置指标是准确性 For the MRPC dataset, the built-in metrics are accuracy
它只是衡量百分比, 其 which just measures the percentage of the time
模型的预测是正确的次数， the model's prediction was correct,
和 F1 分数， and the F1 score,
这是一个稍微复杂的度量 which is a slightly more complex measure
衡量模型如何权衡 that measures how well the model trades off
准确率和召回率。 precision and recall.
要计算这些指标以对我们的模型进行基准测试， To compute those metrics to benchmark our model,
我们只是将模型的预测传递给他们， we just pass them the model's predictions,
和真实标签， and to the ground truth labels,
我们在一个简单的 Python 字典中得到我们的结果。 and we get our results in a straightforward Python dict.
如果你熟悉 Keras， If you're familiar with Keras though,
你可能会注意到这是一种有点奇怪的方式 you might notice that this is a slightly weird way
计算指标， to compute metrics,
因为我们只计算指标 because we're only computing metrics
在训练的最后。 at the very end of training.
但是在 Keras 中，你有这个内置的能力 But in Keras, you have this built-in ability
计算范围广泛的指标 to compute a wide range of metrics
在你训练的过程中， on the fly while you're training,
这给了你一个非常有用的理解 which gives you a very useful insight
了解训练的进展情况。 into how training is going.
所以如果你想使用内置指标， So if you want to use built-in metrics,
这很简单 it's very straightforward
然后你再次使用标准的 Keras 方法。 and you use the standard Keras approach again.
你只需将一个度量参数传递给编译方法。 You just pass a metric argument to the compile method.
与损失和优化器之类的东西一样， As with things like loss and optimizer,
你可以通过字符串指定你想要的指标 you can specify the metrics you want by string
或者你可以导入实际的指标对象 or you can import the actual metric objects
并向他们传递具体的参数。 and pass specific arguments to them.
但请注意，与损失和准确性不同， But note that unlike loss and accuracy,
你必须以列表形式提供指标 you have to supply metrics as a list
即使你只需要一个指标。 even if there's only one metric you want.
一旦用度量标准编译了模型， Once a model has been compiled with a metric,
它将报告该指标对于训练， it will report that metric for training,
验证和预测。 validation, and predictions.
假设有标签传递给预测。 Assuming there are labels passed to the predictions.
你甚至可以编写自己的度量类。 You can even write your own metric classes.
虽然这有点超出本课程的范围， Although this is a bit beyond the scope of this course,
我将链接到下面的相关 TF 文档 I'll link to the relevant TF docs below
因为它可以非常方便 because it can be very handy
如果你想要一个不受支持的指标 if you want a metric that isn't supported
默认情况下，在 Keras 中， by default in Keras,
比如 F1 score. such as the F1 score.
（空气呼啸） (air whooshing)