# I am confused, can you help me?

**URL:** <https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031>\
**Category:** Improving Deep Neural Networks: Hyperparameter tun\
**Tags:** week-module-3, coursera-platform\
**Created:** [August 21, 2024, 7:39am UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031 "2024-08-21T07:39:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhifine](https://avatars.discourse-cdn.com/v4/letter/z/9f8e36/32.png) [@zhifine](https://community.deeplearning.ai/u/zhifine)\
**Post date:** [August 21, 2024, 7:39am UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/1 "2024-08-21T07:39:21Z")

</div>

[Week 3 - Assignment - compute\_total\_loss - try to set from\_logits=False](https://community.deeplearning.ai/t/week-3-assignment-compute-total-loss-try-to-set-from-logits-false/)  
I have spended more than 2 hours for this problem, but it still show errors. help me please!

 ![image](https://global.discourse-cdn.com/dlai/original/3X/b/c/bc838cc739ce1c53a13e86e358f7a39b3809e1d5.png)

---

<div class="post-metadata">

**Author:** ![NyashaEysenck](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nyashaeysenck/32/129339_2.png) [@NyashaEysenck](https://community.deeplearning.ai/u/NyashaEysenck)\
**Post date:** [August 21, 2024, 8:09am UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/2 "2024-08-21T08:09:09Z")

</div>

Hi, did you complete the compute total loss function?

---

<div class="post-metadata">

**Author:** ![Kic](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/kic/32/76339_2.png) [@Kic](https://community.deeplearning.ai/u/Kic)\
**Post date:** [August 21, 2024, 9:53am UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/3 "2024-08-21T09:53:17Z")

</div>

Hi @NyashaEysenck , @zhifine ,

Just in case you have missed the instruction for this exercise, here is an extract:

### Exercise 6 - compute\_total\_loss

Implement the total loss function below. You will use it to compute the total loss of a batch of samples. With this convenient function, you can sum the losses across many batches, and divide the sum by the total number of samples to get the cost value.

- It’s important to note that the “`y_pred`” and “`y_true`” inputs of [tf.keras.losses.categorical\_crossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/losses/categorical_crossentropy) are expected to be of shape (number of examples, num\_classes).
- `tf.reduce_sum` does the summation over the examples.

As you can see from this instruction, you need to play attention to the input parameters as they are arranged differently from the [tf.keras.losses.categorical\_crossentropy]([https://www.tensorflow.org/api\_docs/python/tf/keras/losses/categorical\_crossentropy](https://www.tensorflow.org/api_docs/python/tf/keras/losses/categorical_crossentropy)

Let’s know if you still have problem.

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [August 21, 2024, 3:14pm UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/4 "2024-08-21T15:14:53Z")

</div>

Make sure you’re correctly summing the loss values. The hint in the error message suggests that the issue might be related to how the loss values are aggregated.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [August 21, 2024, 3:47pm UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/5 "2024-08-21T15:47:36Z")

</div>

[Here is a thread](https://community.deeplearning.ai/t/week-3-compute-total-loss-incorrect/291048/2) with a checklist of the most common problems for that function.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [August 21, 2024, 3:49pm UTC](https://community.deeplearning.ai/t/i-am-confused-can-you-help-me/681031/6 "2024-08-21T15:49:36Z")

</div>

> [@nadtriana](#):
>
> Make sure you’re correctly summing (or averaging) the loss values.

Please note that the definition of this function is that it computes the sum of the costs across each minibatch, not the average. [Here’s a thread](https://community.deeplearning.ai/t/dls-course2-week-3-exercise-6-compute-total-loss-method/234856/10) which explains why it is done that way.
