Skip to content

Commit

Permalink
update paddle tutorial_e1
Browse files Browse the repository at this point in the history
  • Loading branch information
x54-729 committed Jun 27, 2022
1 parent dabb8b9 commit 513a5f8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tutorials/fastnlp_tutorial_paddle_e1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"source": [
"# 使用 paddlenlp 和 FastNLP 实现中文文本情感分析\n",
"\n",
"本篇教程属于 **`FastNLP v0.8 tutorial` 的 `paddle examples` 系列**。在本篇教程中,我们将为您展示如何使用 `paddlenlp` 自然语言处理库和 `FastNLP` 来完成比较简单的情感分析任务。\n",
"\n",
"1. 基础介绍:飞桨自然语言处理库 ``paddlenlp`` 和语义理解框架 ``ERNIE``\n",
"\n",
"2. 准备工作:使用 ``tokenizer`` 处理数据并构造 ``dataloader``\n",
Expand Down Expand Up @@ -254,8 +256,7 @@
"\n",
"其次,我们还可以为 ``Trainer`` 指定多个 ``Callback`` 来在基础的训练过程之外进行额外的定制操作。在本篇教程中,我们使用的 ``Callback`` 有以下三种:\n",
"\n",
"- ``RichCallback`` - 在训练和验证时显示进度条,以便观察训练的过程\n",
"- ``LRSchedCallback`` - 由于我们使用了 ``Scheduler``,因此需要将 ``lr_scheduler`` 传给该 ``Callback`` 以在训练中进行更新\n",
"- ``LRSchedCallback`` - 由于我们使用了 ``Scheduler``,因此需要将 ``lr_scheduler`` 传给该 ``Callback`` 以在训练中进行更新。\n",
"- ``LoadBestModelCallback`` - 该 ``Callback`` 会评估结果中的 ``'acc#accuracy'`` 值,保存训练中出现的正确率最高的模型,并在训练结束时加载到模型上,方便对模型进行测试和评估。\n",
"\n",
"在 ``Trainer`` 中,我们还可以设置 ``metrics`` 来衡量模型的表现。``Accuracy`` 能够根据传入的预测值和真实值计算出模型预测的正确率。还记得模型中 ``evaluate_step`` 函数的返回值吗?键 ``pred`` 和 ``target`` 分别为 ``Accuracy.update`` 的参数名,在验证过程中 ``FastNLP`` 会自动将键和参数名匹配从而计算出正确率,这也是我们规定模型需要返回字典类型数据的原因。\n",
Expand Down Expand Up @@ -820,7 +821,7 @@
}
],
"source": [
"from fastNLP import LRSchedCallback, RichCallback, LoadBestModelCallback\n",
"from fastNLP import LRSchedCallback, LoadBestModelCallback\n",
"from fastNLP import Trainer, Accuracy\n",
"from paddlenlp.transformers import LinearDecayWithWarmup\n",
"\n",
Expand All @@ -834,7 +835,6 @@
"callbacks = [\n",
" LRSchedCallback(lr_scheduler, step_on=\"batch\"),\n",
" LoadBestModelCallback(\"acc#accuracy\", larger_better=True, save_folder=\"fnlp-ernie\"),\n",
" RichCallback()\n",
"]\n",
"trainer = Trainer(\n",
" model=model,\n",
Expand Down

0 comments on commit 513a5f8

Please sign in to comment.