【发布时间】:2017-09-06 22:55:05
【问题描述】:
nce_loss() 请求 num_true 的静态 int 值。这适用于每个训练示例具有相同数量的标签并且我们提前知道的问题。
当标签具有可变形状[None],并且使用.padded_batch() + .group_by_window() 按桶大小进行批处理和/或分桶时,需要提供可变大小num_true 以适应所有训练示例.据我所知,这目前不受支持(如果我错了,请纠正我)。
换句话说,假设我们有一个图像数据集,每个图像有任意数量的标签(狗、猫、鸭子等),或者有一个文本数据集,每个句子有多个类(class_1、class_2、.. ., 类_n)。类不是相互排斥的,并且示例之间的大小可能会有所不同。
但是由于可能的标签数量可能很大,10k-100k 有没有办法通过采样损失来提高性能(与 sigmoid_cross_entropy 相比)?
是否有适当的方法来执行此操作或任何其他解决方法?
nce_loss = tf.nn.nce_loss(
weights=nce_weights,
biases=nce_biases,
labels=labels,
inputs=inputs,
num_sampled=num_sampled,
# Something like this:
# `num_true=(tf.shape(labels)[-1])` instead of `num_true=const_int`
# , would be preferable here
num_classes=self.num_classes)
【问题讨论】:
-
嗨,MtDersvan,你找到这个问题的答案了吗?
-
@michal 来自官方页面tensorflow.org/api_docs/python/tf/nn/nce_loss 我们可以看到以下内容:
Note: It would be useful to allow a variable number of target classes per example. We hope to provide this functionality in a future release. For now, if you have a variable number of target classes, you can pad them out to a constant number by either repeating them or by padding with an otherwise unused class.同时,我在github.com/tensorflow/tensorflow/pull/14928 做了一个部分工作的 PR。
标签: tensorflow multilabel-classification