In the compute cost exercise,I get the following error:
NameError: name 'new_y_train' is not defined
I believe my code from compute_cost(logits, labels) function is correct and I don’t see how this error is related to it. Shouldn’t it be coming from the compute_cost_test(target, Y) function?
The test cell for compute_cost uses that as one of the inputs. So where is that variable created? It is in one of the previous cells, right? Use the search function if you have trouble finding it (Cmd-F). So either you did not execute that cell or it threw an error when you did.
1 Like
got it! thanks a lot!! there was an issue with one of the previous cells and I didn’t realise as it was showing all tests passed.
1 Like
{moderator edit - solution code removed}
Hi @paulinpaloalto ,
Can you help me with an insight here please? I tried to apply sigmoid function to logits tensor after reshape.
I don’t understand what is missing to my code and I have 1.5743314 cost after I apply tf.reduce_mean to the cost.
If I don’t use sigmoid to logits I receive a more closest result 0.2490923 with the expected one
0.4051435
The point is that we aren’t supposed to “manually” do the output layer activation. If that were the intent, we would have done it in the forward propagation routine, right? The point is that it’s better to have the output activation done at the same time as the cost calculation, so they want us to do it that way. The way you tell the loss function to do that is by passing the argument from_logits with the value True. The default is false.
The one other point to make is that you could get the correct answer by manually doing the activation and taking the (default) value of from_logits, but we are doing a multiclass classification here. So sigmoid is not the function to use. It would be softmax, right?
Also note that it’s always a big mistake to “hard-code” shapes like the [2, 6] as you have done there. We are trying to write “general” code here that will work for any case. Rather than doing “reshape”, just use “transpose” and then you don’t have to know anything about the specific sizes.
Thank you for answer, @paulinpaloalto