Created
February 26, 2022 11:56
-
-
Save Polaris000/a7809b15b9e32f4cfe32c9154e403404 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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