Amar Parajuli
Amar Parajuli

Reputation: 45

Softmax Cross Entropy implementation in Tensorflow Github Source Code

I am trying to implement a Softmax Cross-Entropy loss in python. So, I was looking at the implementation of Softmax Cross-Entropy loss in the GitHub Tensorflow repository. I am trying to understand it but I run into a loop of three functions and I don't understand which line of code in the function is computing the Loss?

The function softmax_cross_entropy_with_logits_v2(labels, logits, axis=-1, name=None) returns the function softmax_cross_entropy_with_logits_v2_helper(labels=labels, logits=logits, axis=axis, name=name) , which in turn returns softmax_cross_entropy_with_logits(precise_logits, labels, name=name).

Now the function softmax_cross_entropy_with_logits(precise_logits, labels, name=name) returns the function softmax_cross_entropy_with_logits_v2(labels, logits, axis=-1, name=None).

This makes me fall in a loop of functions without knowing explicitly where the code for computing the cost for Softmax function is. Can anyone point out where the code for Softmax Cross-Entropy is Implemented in Tensorflow GitHub Repository?

The link of the GitHub repository that I am referencing is here. It contains the definitions of the above three functions.

If in case the code for cost requires lots of functions which is cumbersome to understand, could you explain the lines of code as well? Thanks.

Upvotes: 0

Views: 669

Answers (1)

Lukasz Tracewski
Lukasz Tracewski

Reputation: 11377

When you follow the call stack for this function, you eventually find this:

cost, unused_backprop = gen_nn_ops.softmax_cross_entropy_with_logits(
      precise_logits, labels, name=name)

Whenever you see a reference to a gen_ module, it means it's an automatically generated python wrapper over the C++ code - that's why you cannot find by simply looking up the function and following call stack.

C++ source code can be found here.

How gen_nn_ops is created is nicely described in this answer.

Upvotes: 2

Related Questions