首页 > 解决方案 > 用主动学习训练的自注意力模型在几次迭代后停止学习

问题描述

我正在对 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 实现的模型上运行良好。

标签: pytorch

解决方案


推荐阅读