In [22]: y_true = [[0], [1]]
In [23]: y_pred = [[0.9], [0.9]]
In [24]: tf.keras.losses.binary_crossentropy(y_true, y_pred)
Out[24]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([2.302584 , 0.10536041], dtype=float32)>
In [25]: y_true = [[0, 1], [1, 0]]
In [26]: y_pred = [[0.9, 0.1], [0.9, 0.1]]
In [27]: tf.keras.losses.binary_crossentropy(y_true, y_pred)
Out[27]: <tf.Tensor: shape=(2,), dtype=float32, numpy=array([2.3025842 , 0.10536041], dtype=float32)>
所以不管是不是 one-hot encoding 都可以使用, 得到的 loss 是一样的.