Facing issues in C3W2_Assignment

In Named Entity Recognition : C3W2_Assignment .

In “4.4 - Training the Model” section, I faced some error when model.fit is called. This function is calling " masked_accuracy(y_true, y_pred) " function internally.

When I printed the y_true and y_pred values inside masked_accuracy function, I got below.

y_true : Tensor(“Cast_3:0”, shape=(None, 104), dtype=float32) <class ‘tensorflow.python.framework.ops.Tensor’>
y_pred : Tensor(“sequential/dense_7/LogSoftmax:0”, shape=(None, 104, 17), dtype=float32) <class ‘tensorflow.python.framework.ops.Tensor’>

I was expecting a list , numpy ndarray or a tensor of int/float values. But I received as above.

Note: I got all the test cases passed in “w2_unittest.test_masked_accuracy(masked_accuracy)”

can you please help me in this ? what exactly i am missing ?

Hi @paramaguru

Here y_true and y_pred are symbolic Tensors, not actual values. This is expected behavior, as the actual data only flows through these Tensors during training. Your function passes unit tests, so that means masked_accuracy is correct. If you need to inspect values for debugging, use tf.print to print them during execution or make sure you’re in eager mode, where Tensors hold real data.

Hope it helps! Feel free to ask of you need further assistance.

1 Like

hi @paramaguru

issue is not only about tf data type, but if you notice your y_true and y_pred shape don’t match.

So as first debug step check if you used the correct recall for y_pred.

See if the below pinned comment helps you debug.

Regards
DP