我最近读了一篇题为“通过惩罚自信输出分布来正则化神经网络”的论文。作者讨论了通过惩罚低熵来正则化神经网络 通过向负对数似然中添加负熵项并创建用于模型训练的自定义损失函数,输出分布
β值控制置信度惩罚的强度。我为分类交叉熵编写了一个自定义函数,如下所示,但需要将负熵项添加到损失函数中
import tensorflow as tf
def custom_loss(y_true, y_pred):
cce = tf.keras.losses.CategoricalCrossentropy()
cce_loss = cce(y_true, y_pred)
return cce_loss
y_pred
的熵本质上是y_pred
与自身之间的分类交叉熵:您不需要自定义丢失,因为它可以实现为活动正则化器(应用于层输出的正则化器):
然后可以将其应用于输出层:
相关问题 更多 >
编程相关推荐