Specifically, I suppose I wonder about this statement:

Future major versions of TensorFlow will allow gradients to flow into the labels input on backprop by default.

Which is shown when I use tf.nn.softmax_cross_entropy_with_logits. In the same message it urges me to have a look at tf.nn.softmax_cross_entropy_with_logits_v2. I looked through the documentation but it only states that for tf.nn.softmax_cross_entropy_with_logits_v2:

Backpropagation will happen into both logits and labels. To disallow backpropagation into labels, pass label tensors through a stop_gradients before feeding it to this function.

as opposed to, tf.nn.softmax_cross_entropy_with_logits's:

Backpropagation will happen only into logits.

Being very new to the subject (I'm trying to make my way through some basic tutorials) those statements are not very clear. I have a shallow understanding of backpropagation but what does the previous statement actually mean? How are backpropagation and the labels connected? And how does this change how I work with tf.nn.softmax_cross_entropy_with_logits_v2 as opposed to the original?


1 Answer 1


You have every reason to be confused, because in supervised learning one doesn't need to backpropagate to labels. They are considered fixed ground truth and only the weights need to be adjusted to match them.

But in some cases, the labels themselves may come from a differentiable source, another network. One example might be adversarial learning. In this case, both networks might benefit from the error signal. That's the reason why tf.nn.softmax_cross_entropy_with_logits_v2 was introduced. Note that when the labels are the placeholders (which is also typical), there is no difference if the gradient through flows or not, because there are no variables to apply gradient to.

  • 6
    $\begingroup$ Ah I see, I have yet to go beyond supervised learning, lots to learn. Just so that I understood you correctly, basically as long as I don't indicate that my labels are subject to optimization (e.i. store them as tf.Variable) they wont be touched and softmax_..._with_logits_v2 will work as softmax_with_logits? (Or I might use tf.stop_gradient on the labels variable.) $\endgroup$ Feb 7, 2018 at 22:04
  • 3
    $\begingroup$ Yes, that's right. $\endgroup$
    – Maxim
    Feb 7, 2018 at 22:06
  • 2
    $\begingroup$ Very clear and educational, thank you very much! $\endgroup$
    – Haitao Du
    Aug 28, 2018 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.