这两行在训练时产生不同的结果
loss = tf.reduce_mean(tf.keras.losses.categorical_crossentropy(answers_matrix, predictions_matrix))
和
loss = -tf.reduce_mean(answers_matrix * tf.log(predictions_matrix))
我想可视化训练中的损失,所以我想打印整个批次和序列长度上的损失平均值。不取均值,最终的损失将是(batch_size,sequence_length)形状
第二行使我在训练/优化神经网络时获得更好的结果。
我在tensorflow后端使用keras