Skip to content

Instantly share code, notes, and snippets.

@joydeb28
Last active May 6, 2020 17:35
Show Gist options
  • Save joydeb28/19e73bf5f0ac233728b3efa86bc3737c to your computer and use it in GitHub Desktop.
Save joydeb28/19e73bf5f0ac233728b3efa86bc3737c to your computer and use it in GitHub Desktop.
class Prediction():
def __init__(self):
self.model = model_obj.model
def predict_validation(self):
valid_sentences = load_data_obj.validation_data_frame["query"].tolist()
valid_labels = load_data_obj.validation_data_frame["category"].tolist()
preprocess_bert_data_obj = PreprocessingBertData()
val_x = preprocess_bert_data_obj.prepare_data_x(valid_sentences)
prediction_labels = list(self.model.predict(val_x).argmax(axis=-1))
return valid_labels,prediction_labels
def predict(self,query):
query_seq = bert_model_obj.get_input_array([query])
pred = self.model.predict(query_seq)
pred = np.argmax(pred)
result = load_data_obj.cat_to_intent[pred]
return result
pred_obj = Prediction()
querylist = [['I want to see Medal for the General', 'SearchScreeningEvent', 1],
['Book a reservation for 5 people at the top-rated brasserie restaurant',
'BookRestaurant', 5],
['Can I put this tune onto my sin estres playlist?',
'AddToPlaylist', 6],
['add the artist Pete Murray to my relaxing playlist',
'AddToPlaylist', 6],
['Book me a reservation for a party of 3 at a pub in Northern Mariana Islands',
'BookRestaurant', 5]]
for query in querylist:
result = pred_obj.predict(query[0])
print("Predicted Intent: "+str(result)+"\tActual Intent: "+(load_data_obj.cat_to_intent[query[2]])+"\tQuery: "+str(query[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment