tf.nn.sparse_softmax_cross_entropy_with_logits-tensorflow中没有一个热编码的标签

tf.nn.sparse_softmax_cross_entropy_with_logits-tensorflow中没有一个热编码的标签,tensorflow,softmax,one-hot-encoding,Tensorflow,Softmax,One Hot Encoding,我正在试图理解tf.nn.sparse\u softmax\u cross\u entropy\u with\u logits是如何工作的 描述说: A common use case is to have logits of shape [batch_size, num_classes] and labels of shape [batch_size]. But higher dimensions are supported. 因此,它建议我们可以以原始形式提供标签,例如[1,2,

我正在试图理解
tf.nn.sparse\u softmax\u cross\u entropy\u with\u logits
是如何工作的

描述说:

    A common use case is to have logits of shape [batch_size, num_classes]
 and labels of shape [batch_size]. But higher dimensions are supported.
因此,它建议我们可以以原始形式提供标签,例如
[1,2,3]

现在,由于所有计算都是每批完成的,我相信以下是可能的:

在所有情况下,我们假设批量大小等于2

案例1(一批): 罗吉特:

相应的标签:

2
3
1
2
我猜标签可能被编码为

[1 0 0]
[0 1 0] 
案例2(另一批): 罗吉特:

相应的标签:

2
3
1
2
我猜标签可能被编码为(我不知道是什么阻止我们进行这种编码,除非tensorflow跟踪它以前是如何编码的)


所以我们有两种不同的编码。假设tensorflow在批与批之间保持编码一致是否安全?

没有真正的编码发生。标签仅为
1
在相应热向量中的位置:

0 -> [1, 0, 0]
1 -> [0, 1, 0]
2 -> [0, 0, 1]

此“编码”将在每批中使用。

没有真正的编码发生。标签仅为
1
在相应热向量中的位置:

0 -> [1, 0, 0]
1 -> [0, 1, 0]
2 -> [0, 0, 1]

此“编码”将在每批中使用。

非常感谢!所以我的标签必须是某种格式的?如果我的标签是34、45、133,而我们只有三个呢classes@user1700890是的,您的标签必须是介于0和\u类的\u个数-1之间的整数。如果您的标签是34、45和133,您必须自己将它们编码为0、1和2。非常感谢!所以我的标签必须是某种格式的?如果我的标签是34、45、133,而我们只有三个呢classes@user1700890是的,您的标签必须是介于0和\u类的\u个数-1之间的整数。如果标签是34、45和133,则必须自己将其编码为0、1和2。