（空气呼啸） (air whooshing)
（笑脸弹出） (smiley face popping)
（空气呼啸） (air whooshing)
- [Instructor] push_to_hub API。 - [Instructor] So push_to_hub API.
让我们看一下 push_to_hub API。 Let's have a look at the push_to_hub API.
你需要使用你的 Hugging Face 帐户登录 You will need to be logged in with your Hugging Face account
你可以通过执行第一个单元格里的操作来登录， which you can do by executing this first cell,
或者在 terminal 中输入 huggingface-cli login。 or by typing huggingface-cli login in a terminal.
只需输入你的用户名和密码，然后点击登录， Just enter you username and password, then click login,
登录后将存储一个授权 token this will store a authentication token
到你正在使用的机器的缓存中。 in the cache of the machine you're using.
现在，让我们基于 GLUE COLA 数据集 Now, let's launch a fine tuning of a BERT model
对 BERT 模型进行微调。 on the GLUE COLA dataset.
我们不会深入探讨微调代码 We won't go over the fine tuning code
你可以在任何 transformer 教程 because you can find it in any transformer tutorial,
或查看下面的视频链接找到相关参考。 or by looking at the videos link below.
我们感兴趣的是 What interests us here is
如何在训练期间利用 model hub。 how we can leverage the model hub during training.
这是通过 “push_to_hub=true” 参数完成的 This is done with the "push_to_hub=true" argument
将该参数添加到你的 TrainingArguments。 passed in your TrainingArguments.
每次保存时将自动上传 This will automatically upload your model
你的模型到 Hub，在我们的示例中， to the Hub each time it is saved,
每个 epoch 都会如此操作。 so every epoch in our case.
如果当前的被打断 This allows you to resume training from a different machine
这允许你从不同的机器恢复训练之前的训练。 if the current one gets interrupted.
该模型将使用 The model will be updated in your namespace
你默认选择的输出目录的名称在你的 namespace 中更新。 with the name of the output directory you picked by default.
你可以通过将其 You can choose another name
传递给 hub_model_id 参数选择其他名称。 by passing it to the hub_model_id argument.
你还可以通过传递完整的仓库名称 You can also push inside an organization you are a member of
将模型 push 到你所属的组织内部， by passing a full repository name,
使用 organization/ 的形式, with the name of the organization/,
再加上你所选的 model ID。 the model ID you want to pick.
完成后，我们就可以开始训练了， With that done, we can just launch training,
稍等一下。 and wait a little bit.
视频中会跳过等待的过程。 I'll cut the waiting time from the video.
请注意，模型是异步 push 的， Note that the model is pushed asynchronously,
意味着当你的模型上传到 hub 时， meaning that the training continues
训练将继续进行。 while your model is uploaded to the hub.
当你的第一次 commit 完成时， When your first commit is finished,
你可以通过查看你的 namespace you can go inspect your model on the Hub
去 Hub 检查你的模型， by looking inside your namespace,
你会在最上面找到它。 and you'll find it at the very top.
你甚至可以在继续训练的同时 You can even start playing with its inference widget
开始使用它的 inference 小部件。 while it's continuing the training.
Cola 数据集让模型确定 The Cola dataset tasks the model with determining
句子在语法上是否是正确的。 if the sentence is grammatically correct on that.
所以我们选择一个错误句子的例子来测试它。 So we pick an example of incorrect sentence to test it.
请注意，第一次尝试使用它时， Note that it'll take a bit of time
这需要一些时间才能在 inference API 中 to load your model inside the inference APIs,
完成模型加载。 so first time you try to use it.
我们将根据时间从视频中删掉。 We'll cut by time from the video.
标签有点问题， There is something wrong with the labels,
我们稍后会在本视频中修复它。 but we'll fix it later in this video.
一旦你的训练完成， Once your training is finished,
你应该使用 trainer.push_to_hub 方法 you should do one last push with the trainer
最后再提交一次。 that pushed to a method.
这其中有两个原因。 This is for two reason.
首先，若你尚未完成 First, this will make sure
这将确保你正在预测模型的 you are predicting the final version of your model
最终版本。 if you didn't already.
例如，如果你曾经是在每一步保存 For instance, if you used to save
而不是每秒保存， every in step strategy instead of every second,
这将创建一个 model card this will draft a model card
那将是你的 model repo 的最初始页面。 that will be the landing page of your model repo.
commit 完成后， Once the commit is done,
让我们回到我们的 model 页面并刷新。 let's go back on our model page and refresh.
我们可以看到 model card 的草稿 We can see the drafters model card
其中包括信息， which includes information,
以及哪个模型被调整过。 and which one model we find tuned.
接下来是最终的评估 loss 和 metric， So final evaluation loss and metric,
使用过的训练超参数， the training hyperparameter used,
中间训练结果， the intermediate training results,
以及我们使用的框架版本 and the framework versions we used
以便其他人可以轻松地重现我们的结果。 so that other people can easily reproduce our results.
在所有这些信息之上， On top of all that information,
trainer 还包括一些 metadata，它可以 the trainer also included some metadata that is interpreted
通过 model cloud 上的 HuggingFace 网站解析。 by the Hugging Face website in the model cloud.
你将会得到一个漂亮的 widget 所返回的相关指标数值 You get the value of the metrics reported in a nice widget
以及一个链接指向 leaderboard(Paper with Code)。 as well as a link to a leaderboard with paper with code.
并且 Tensorboard 的运行结果也包含 So the Tensorboard runs have also been pushed
在这份报告中，我们可以在 Model Hub 中 to this report, and we can look at them
通过点击子菜单中的 directly from the model hub
Training metrics 查看报告。 by clicking on the training metrics sub menu.
如果你不使用 Trainer API If you are not using the Trainer API
微调你的模型， to fine-tune your model,
你可以在模型上直接 you can use a push_to_hub method
使用 push_to_hub 方法和分词器。 on the model, and tokenizer directly.
让我们测试一下以修复 inference widget 中的所有标签。 Let's test this to fix all labels in the inference widget.
inference widget 使用不同的标签名称 The inference widget was using different names for labels
因为我们没有在整数和标签名称之间 because we did not indicate the correspondence
注明关联性。 between integer and label names.
当推送模型配置到 hub 时， We can fix this in the configuration
我们可以通过将 label2id by setting the label2id,
和 id2label 字段设置为合适的值 and id2label fields through the proper values
在配置中解决这个问题。 when pushing the model config to the hub.
完成后，我们可以在网站上查看， Once this is done, we can check on the website,
模型现在显示正确的标签。 and the model is now showing the proper label.
现在模型在 hub 上， Now that the model is on the hub,
我们可以在任何地方使用它 we can use it from anywhere
就像我们对任何其他 Transformer 模型 as we would any other Transformer model
使用 from_pretrained 方法 with the from_pretrained method
或者使用 pipeline 函数。 or with the pipeline function.
我们只需要使用 hub 的标识符， We just have to use the identifier from the hub,
我们可以看到模型配置和权重 and we can see that the model configuration and weights
以及分词处理后的文件会自动下载。 as well as the tokenized files are automatically downloaded.
在下一次训练中尝试 push_to_hub API Try the push_to_hub API in the next training
轻松与世界其他地方分享你的模型。 to easily share your model with the rest of the world.
（空气呼啸） (air whooshing)