Question: # GRADED FUNCTION: predict def predict ( sentence , model, sentence _ vectorizer, tag _ map ) : Predict NER labels for

# GRADED FUNCTION: predict
def predict(sentence, model, sentence_vectorizer, tag_map):
"""
Predict NER labels for a given sentence using a trained model.
Parameters:
sentence (str): Input sentence.
model (tf.keras.Model): Trained NER model.
sentence_vectorizer (tf.keras.layers.TextVectorization): Sentence vectorization layer.
tag_map (dict): Dictionary mapping tag IDs to labels.
Returns:
predictions (list): Predicted NER labels for the sentence.
"""
### START CODE HERE ###
# Convert the sentence into ids
sentence_vectorized = None
# Expand its dimension to make it appropriate to pass to the model
sentence_vectorized = tf.expand_dims(None, None)
# Get the model output
output = None
# Get the predicted labels for each token, using argmax function and specifying the correct axis to perform the argmax
outputs = np.argmax(None, axis = None)
# 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]
outputs = outputs[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
labels = list(tag_map.keys())
pred =[]
# Iterating over every predicted token in outputs list
for tag_idx in None
pred_label = None
pred.append(None)
### END CODE HERE ###
return pred

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!