迁移学习的起点
在这个练习中,您将看到以预训练向量作为模型起点的好处。
您将比较两个模型在训练 2 个 epoch 后的准确率。两个模型的结构相同:一个嵌入层、一个含 128 个单元的 LSTM 层,以及一个含 5 个单元的输出层,对应示例数据中的类别数。不同之处在于,其中一个模型在嵌入层上使用了预训练向量(迁移学习),而另一个没有。
使用的预训练向量为 GloVE,维度为 200。两个模型在验证集上的训练准确率历史分别保存在变量 history_no_emb 和 history_emb 中。
本练习是课程的一部分
使用 Keras 构建语言建模的循环神经网络(RNN)
练习说明
- 导入模块
matplotlib.pyplot并命名为plt。 - 将未使用嵌入的模型的准确率列表添加到图表中。
- 将使用嵌入的模型的准确率列表添加到图表中。
- 使用
.show()方法显示图表。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import plotting package
import matplotlib.____ as ____
# Insert lists of accuracy obtained on the validation set
plt.plot(____['acc'], marker='o')
plt.plot(history_emb[____], marker='o')
# Add extra descriptions to plot
plt.title('Learning with and without pre-trained embedding vectors')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['no_embeddings', 'with_embeddings'], loc='upper left')
# Display the plot
plt.____