在Tensorflow中,sampled_softmax_loss和softmax_cross_entropy_with_logits有什么区别 [英] In Tensorflow, what is the difference between sampled_softmax_loss and softmax_cross_entropy_with_logits
问题描述
在tensorflow中,有一些方法称为 softmax_cross_entropy_with_logits
和 sampled_softmax_loss
。
In tensorflow, there are methods called softmax_cross_entropy_with_logits
and sampled_softmax_loss
.
我阅读了tensorflow文档,并在Google上搜索了更多信息,但我无法找不到区别。在我看来,两者都使用softmax函数来计算损失。
I read the tensorflow document and searched google for more information but I couldn't find the difference. It looks like to me both calculates the loss using softmax function.
loss = tf.reduce_mean(tf.nn.sampled_softmax_loss(...))
使用 softmax_cross_entropy_with_logits
计算损失
Using softmax_cross_entropy_with_logits
to calculate the loss
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(P, Q))
对我来说,计算softmax损失与计算softmaxed交叉熵相同(例如 cross_entropy(softmax(train_x))
)
To me, calculating softmax loss is same as calculating softmaxed cross entropy (e.g. cross_entropy(softmax(train_x))
)
有人可以告诉我为什么有两种不同的方法,以及在这种情况下应该使用哪种方法吗?
Could somebody tell me the why there is two different methods and which method should I use in which case?
推荐答案
如果您的目标词汇量(或您想预测的类的数量)确实很大,则很难使用常规softmax,因为您必须计算字典中每个单词的概率。通过使用 sampled_softmax_loss
,您只需考虑词汇表的子集 V 来计算损失。
If your target vocabulary(or in other words amount of classes you want to predict) is really big, it is very hard to use regular softmax, because you have to calculate probability for every word in dictionary. By Using sampled_softmax_loss
you only take in account subset V of your vocabulary to calculate your loss.
仅当我们采样的( V )小于词汇量时,采样的softmax才有意义。如果您的词汇量(标签数量)很小,则使用 sampled_softmax_loss
没有意义。
Sampled softmax only makes sense if we sample(our V) less than vocabulary size. If your vocabulary(amount of labels) is small, there is no point using sampled_softmax_loss
.
您可以看到实现本文详细信息:
http://arxiv.org/pdf/1412.2007v2.pdf
You can see implementation details in this paper: http://arxiv.org/pdf/1412.2007v2.pdf
另外,您还可以看到使用它的示例-在此示例
Also you can see example where it is used - Sequence to sequence translation in this example
这篇关于在Tensorflow中,sampled_softmax_loss和softmax_cross_entropy_with_logits有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!