I got the error in predict function. The error shows when I’m calling function “get_sentence_vectorizer(sentence)” but that function I passed. I searched for an error but I cannot understand.
Can you share image of complete error, probably in two screenshots!!!
I think my function get_sentence_vectorizer might be wrong. Can I use .adapt to adaptthe sentence vectorization.
get_sentence_vectorizer
is not in the predict
function scope (and it is not the function you would want to use - it returns a function and a vocabulary. What you want is to “vectorize” the sentence with a vectorizer that is in the scope of the predict
function).
You should be using sentence_vectorizer
.
Cheers
I got the error instead. Any clue for this error please. I used tf.expand_dims(sentence_vectorized, axis=0) is that right axis and parameters, I called to get model output by using “model(sentence_vectorized)” and get the predicted output by np.argmax(1, axis = -1)
Thanks
is this for the same unittest?
this is correct.
issue could be related to
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 YOU RECALLED list of tag_map.keys as labels
THEN prediction with empty string which you then
Iterating over every predicted token in outputs list
Create for loop for tag idx in outputs
check if predicted labels are equal to labels of tag_ids
which gets append to pred
Regards
DP
Yes, it is the same function and unittest.
When I am iterating on tag idx in out put and then check pred_label = labels[tag_idx] it’s show the error by the below.
Please DM your codes from the predict grade cell. Click on my name and then message.
Sorry for the late reply, somehow I missed your DM.
Okay codes in the screenshot you shared here in previous comment are correct but because your model output from sentenced you vectorised is incorrect, you are getting this error.
Remember in the code line
Get the model output, doesn’t mean you get model of the sentence you vectorised.
Hint: The parameter mentions
model (tf.keras.Model): Trained NER model.
then Predict NER labels for a given sentence using a trained model.
Probably the below screenshot is more of direct hint for the correction.
Regards
DP
so I need to get model output like model.predict(sentence_vectorized) but if doesnt mean I need to put the sentence_vectorize to call the model. From your clue I need to pass something like test label value ? I have no idea how to define pred_label
Yes. pred_label codes are correct
that clue was only related to the model output and not the label value.
Your pred_label codes are correct as mentioned in previous comment
Thanks. Problem solved by for tag_idx in outputs[0]. I change outputs to outputs[0].