# Tensorflow Loss Function

**URL:** <https://community.deeplearning.ai/t/tensorflow-loss-function/78948>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [December 26, 2021, 8:42am UTC](https://community.deeplearning.ai/t/tensorflow-loss-function/78948 "2021-12-26T08:42:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anbu](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@Anbu](https://community.deeplearning.ai/u/Anbu)\
**Post date:** [December 26, 2021, 8:42am UTC](https://community.deeplearning.ai/t/tensorflow-loss-function/78948/1 "2021-12-26T08:42:27Z")

</div>

Hi Sir,

How can we find the code written for tensorflow categorial entropy loss or binary loss function in tensorflow ? Because we see in the documentation or github only the direct aip used ? But we would like to know how the actual code written behind the loss function ?

How we can find the code ? Please help

---

<div class="post-metadata">

**Author:** ![ai\_curious](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/ai_curious/32/128003_2.png) [@ai\_curious](https://community.deeplearning.ai/u/ai_curious)\
**Post date:** [December 26, 2021, 1:49pm UTC](https://community.deeplearning.ai/t/tensorflow-loss-function/78948/2 "2021-12-26T13:49:14Z")

</div>

1. [tf.keras.losses.BinaryCrossentropy &nbsp;|&nbsp; TensorFlow Core v2.7.0](https://www.tensorflow.org/api_docs/python/tf/keras/losses/BinaryCrossentropy)

2. [keras/losses.py at v2.7.0 · keras-team/keras · GitHub](https://github.com/keras-team/keras/blob/v2.7.0/keras/losses.py#L494-L593)

3. [tf.keras.metrics.binary\_crossentropy &nbsp;|&nbsp; TensorFlow Core v2.7.0](https://www.tensorflow.org/api_docs/python/tf/keras/metrics/binary_crossentropy)

4. [tensorflow/backend.py at master · tensorflow/tensorflow · GitHub](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/backend.py#L5007)

This omits some of the call stack details, such as the `Loss` and `LossFunctionWrapper` base class `init` and `call` functions, but that is the basic breadcrumb trail for Binary\_Crossentropy that ends with

```auto

  # Compute cross entropy from probabilities.
  bce = target * math_ops.log(output + epsilon())
  bce += (1 - target) * math_ops.log(1 - output + epsilon())
  return -bce

```
