使用 softmax 进行 Keras 强化训练
Keras reinforcement training with softmax
我正在从事的一个项目有一个使用 REINFORCE 算法的强化学习阶段。使用的模型具有最终的 softmax 激活层,因此负学习率被用作负奖励的替代品。我对这个过程有些怀疑,也找不到太多关于使用负学习率的文献。
强化学习是否可以在正负学习率之间切换?如果不是,什么是更好的方法,摆脱 softmax 或让 keras 成为一个不错的选择?
损失函数:
def log_loss(y_true, y_pred):
'''
Keras 'loss' function for the REINFORCE algorithm,
where y_true is the action that was taken, and updates
with the negative gradient will make that action more likely.
We use the negative gradient because keras expects training data
to minimize a loss function.
'''
return -y_true * K.log(K.clip(y_pred, K.epsilon(), 1.0 - K.epsilon()))
切换学习率:
K.set_value(optimizer.lr, lr * (+1 if won else -1))
learner_net.train_on_batch(np.concatenate(st_tensor, axis=0),
np.concatenate(mv_tensor, axis=0))
更新,测试结果
我 运行 一个只有正强化样本的测试,忽略了所有负样本,因此忽略了负学习率。获胜率正在上升,正在改善,我可以放心地假设使用负学习率 是不正确的。
有人对我们应该如何实施有任何想法吗?
更新,型号说明
我们正在尝试重建AlphaGo as described by DeepMind,慢速策略网:
For the first stage of the training pipeline, we build on prior work
on predicting expert moves in the game of Go using supervised
learning13,21–24. The SL policy network pσ(a| s) alternates between convolutional
layers with weights σ, and rectifier nonlinearities. A final softmax
layer outputs a probability distribution over all legal moves a.
不确定这是否是最好的方法,但至少我找到了一种可行的方法。
对于所有负训练样本,我重新使用网络预测,将我想要取消学习的动作设置为零,并调整所有值以再次总和为 1
之后我尝试了几种方法来调整它们,但还没有 运行 足够的测试来确定哪种方法最有效:
- 应用 softmax(必须取消学习的动作获得非零值..)
- 重新分配所有其他操作的旧操作价值
- 将所有非法操作值设置为零并分配总移除值
- 分配与其他值成比例的值
可能还有其他几种方法可以做到这一点,这可能取决于最有效的用例,并且可能有更好的方法来做到这一点,但至少这个方法有效。
我正在从事的一个项目有一个使用 REINFORCE 算法的强化学习阶段。使用的模型具有最终的 softmax 激活层,因此负学习率被用作负奖励的替代品。我对这个过程有些怀疑,也找不到太多关于使用负学习率的文献。
强化学习是否可以在正负学习率之间切换?如果不是,什么是更好的方法,摆脱 softmax 或让 keras 成为一个不错的选择?
损失函数:
def log_loss(y_true, y_pred):
'''
Keras 'loss' function for the REINFORCE algorithm,
where y_true is the action that was taken, and updates
with the negative gradient will make that action more likely.
We use the negative gradient because keras expects training data
to minimize a loss function.
'''
return -y_true * K.log(K.clip(y_pred, K.epsilon(), 1.0 - K.epsilon()))
切换学习率:
K.set_value(optimizer.lr, lr * (+1 if won else -1))
learner_net.train_on_batch(np.concatenate(st_tensor, axis=0),
np.concatenate(mv_tensor, axis=0))
更新,测试结果
我 运行 一个只有正强化样本的测试,忽略了所有负样本,因此忽略了负学习率。获胜率正在上升,正在改善,我可以放心地假设使用负学习率 是不正确的。
有人对我们应该如何实施有任何想法吗?
更新,型号说明
我们正在尝试重建AlphaGo as described by DeepMind,慢速策略网:
For the first stage of the training pipeline, we build on prior work on predicting expert moves in the game of Go using supervised learning13,21–24. The SL policy network pσ(a| s) alternates between convolutional layers with weights σ, and rectifier nonlinearities. A final softmax layer outputs a probability distribution over all legal moves a.
不确定这是否是最好的方法,但至少我找到了一种可行的方法。
对于所有负训练样本,我重新使用网络预测,将我想要取消学习的动作设置为零,并调整所有值以再次总和为 1
之后我尝试了几种方法来调整它们,但还没有 运行 足够的测试来确定哪种方法最有效:
- 应用 softmax(必须取消学习的动作获得非零值..)
- 重新分配所有其他操作的旧操作价值
- 将所有非法操作值设置为零并分配总移除值
- 分配与其他值成比例的值
可能还有其他几种方法可以做到这一点,这可能取决于最有效的用例,并且可能有更好的方法来做到这一点,但至少这个方法有效。