Softmax Cross Entropy implementation in Tensorflow Github Source Code

我的梦境 提交于 2021-01-29 22:23:59

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/61558769/softmax-cross-entropy-implementation-in-tensorflow-github-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!