Hello, I’m encountering this error in the predict code cell.
Your function could not be tested due an error. Please make sure you are passing the correct tensor to the model call. You need to expand its dimension before calling the model.
Test failed.
I’ve seen a previous question asked here, that says to use 4.3 a note on padding as a hint, but I’m not sure how I would incorporate the 4.3 points into sentence_vectorized.
I’m using sentence_vectorized in the tf.expand_dims line.
Any help is appreciated. Thank you!
I have now fixed that issue and run into this:
Your function could not be tested due an error. The error is:
Layer “sequential” expects 1 input(s), but it received 2 input tensors. Inputs received: [<tf.Tensor: shape=(), dtype=int32, numpy=1>, <tf.Tensor: shape=(), dtype=int32, numpy=8>]
Test failed.
Does this have to do with the predict graded cell or other places? I’m thinking it might be because passing in sentence_vectorized to tf.expand_dim is giving me an extra tensor? But how?
can you share a screenshot of the error currently you are encountering!!
Hi Deepti, this is the error that I’m encountering with exercise 6. Thank you for helping!
Kevin
1 Like
Hi @roses_r_red
Although your codes direct towards incorrect output code, the reason it raising an error because of your previous codes is incorrect as well as the next error in the screenshot also shows it requires correction for predicted labels, let me explain step-wise, you can debug based on the point.
-
The first code required you to Convert the sentence into ids, you have to use sentence_vectorizer to sentence for this step which I suppose you did write correctly.
-
Next code required you to expand its dimension to make it appropriate to pass to the model. here the code has an error, although use of tf.expand_dims was perfectly right with the correct axis, you didn’t required the shape list(), so kindly remove it.
-
Next to Get the model output, you have used only model where as you had to use model.predict to the sentence_vectorized
-
To get the predicted labels for each token, usin3g argmax function and specifying the correct axis to perform the argmax, here your axis choice is incorrect, remember what axis signifies in this code line, you are telling numpy along which axis you want the maximum argument . So is choice of -1 correct as per required output?? Remember axis of 1 also wouldn’t be the right choice, so what would be next best choice!!! For example you have 3D-array and you chose an axis of 3 it throws an error because your array only has 3 axes (0, 1, 2). I hope now you understood what should be your axis choice!!!
-
Further steps I am only adding for you to cross-check as I cannot see your codes further in the screenshot.
Next line is just to adjust outputs dimension. Since this function expects only one input to get a prediction, outputs will be something like [[1,2,3]]
so to avoid heavy notation below, let’s transform it into [1,2,3]
As per the above code instructions clearly mentions this functions expects only one input to get a prediction, so to transform an output to indexing as per [1,2,3] what would the ideal choice [0]!!!
-
Get a list of all keys, remember that the tag_map was built in a way that each label id matches its index in a list
Here the labels needs to be recalled as list of tag_map.keys()
next an empty string of pred
-
Next for iterating over every predicted token in outputs list. You would be creating a for loop for tag_map (index) in outputs, which will then predict labels as per labels of tag_idx, which then you would require pred_label to be append to pred
All the best!! let me know if any new error.
Regards
DP
1 Like
Hi Deepti! Your explanation really helped! You were right that the axis for getting the predicted label was incorrect. I think the main trip up here was the shape call and the axis being input incorrectly. Thank you for your help!!!
1 Like