pytorch - 用主动学习训练的自注意力模型在几次迭代后停止学习
问题描述
我正在对 PyTorch 中实现的自注意力模型进行不确定性抽样的主动学习。该算法的工作原理如下(步骤 3-7 重复 14 次迭代):
1. Take 10% of the data as training set, L
2. Train the model on L
3. Either rank the remaining samples U by a certain informativeness measure and pick a batch B of the top n samples, or randomly pick a batch B
4. Add B to L
5. Remove B from U
6. Re-train the model on L union B, after resetting the weights of the model (this is for cumulative training)
7. Evaluate the model on the test set (accuracy)
现在,该模型在前 2-3 次迭代中表现良好,并显示在验证集上学习。然而,在后来的迭代中,它完全停止了学习,并显示出相同的训练和验证准确性和损失。然后测试准确率总是下降到随机分类器之一(大约 33%),如您在此处看到的:
相反,测试准确度应该提高,因为模型是在更大的数据集上训练的。我真的无法理解为什么会发生这种情况。每次迭代使用的代码完全相同,我总是在重新训练之前重新设置权重。这是我用来重置权重的代码:
def reset_weights(m):
for layer in m.children():
if hasattr(layer, 'reset_parameters'):
layer.reset_parameters()
接着:
model.apply(reset_weights)
它与 PyTorch 处理缓存的方式有关吗?相同的过程在使用 Keras 实现的模型上运行良好。
解决方案
推荐阅读
- asp.net-core - 如何使用 Xunit 在 Visual Studio 代码中调试非测试项目
- sql-update - 用字符更新 sql 问题
- python - 由于错误“WebDriverException:'chromedriver.exe' 可执行文件需要在 PATH 中”,无法运行 webdriver.chrome()。
- qt - 如何在 QML 中实现对象之间的单一连接?
- azure-functions - 在 Azure Functions 中绑定到 json 有效负载和 http 触发器的标头
- airflow - 任务在排队且未恢复时在 Airflow 中移动到已移除状态
- javascript - 使用javascript jquery将html附加到具有指定类的按钮最近的div
- node.js - Amazon SES verifyEmailIdentity 未发送电子邮件
- swagger - Swagger 是否可以为 POST 和 PATCH 显示不同的模型视图,即一次写入属性?
- postgresql - 将 DialogflowChatbot 与 PostgreSQL 数据库连接