Skip to content

Instantly share code, notes, and snippets.

@Polaris000
Created February 26, 2022 11:56
Show Gist options
  • Save Polaris000/a7809b15b9e32f4cfe32c9154e403404 to your computer and use it in GitHub Desktop.
Save Polaris000/a7809b15b9e32f4cfe32c9154e403404 to your computer and use it in GitHub Desktop.
def process(self, message: Message, **kwargs: Any) -> None:
"""
The driver method. Its executed after every user message.
"""
X = message.get_sparse_features(TEXT)[1].features.reshape(1, -1)
probs = self.clf.predict_proba(X).flatten()
intents = self.le.inverse_transform(self.clf.classes_)
ranking = [
{"name": intent, "confidence": confidence} for intent, confidence in zip(intents, probs)
]
top_intent = max(ranking, key=lambda x:x['confidence'])
message.set("intent", top_intent, add_to_output=True)
message.set("intent_ranking", [ranking], add_to_output=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment