rasa_nlu/classifiers/sklearn_intent_classifier.py
def process(self, message, **kwargs):
        # type: (Message, **Any) -> None
        """Return the most likely intent and its probability for a message."""

        if not self.clf:
            # component is either not trained or didn't
            # receive enough training data
            intent = None
            intent_ranking = []
        else:
            X = message.get("text_features").reshape(1, -1)
            intent_ids, probabilities = self.predict(X)
            intents = self.transform_labels_num2str(intent_ids)
            # `predict` returns a matrix as it is supposed
            # to work for multiple examples as well, hence we need to flatten
            intents, probabilities = intents.flatten(), probabilities.flatten()

            if intents.size > 0 and probabilities.size > 0:
                ranking = list(zip(list(intents),
                                   list(probabilities)))[:INTENT_RANKING_LENGTH]

                intent = {"name": intents[0], "confidence": probabilities[0]}

                intent_ranking = [{"name": intent_name, "confidence": score}
                                  for intent_name, score in ranking]
            else:
                intent = {"name": None, "confidence": 0.0}
                intent_ranking = []

        message.set("intent", intent, add_to_output=True)
        message.set("intent_ranking", intent_ranking, add_to_output=True)
Return the most likely intent and its probability for a message.
Return the most likely intent and its probability for a message.
Return the most likely intent and its probability for a message .
def process(self, message, **kwargs):
        if not self.clf:
            intent = None
            intent_ranking = []
        else:
            X = message.get("text_features").reshape(1, -1)
            intent_ids, probabilities = self.predict(X)
            intents = self.transform_labels_num2str(intent_ids)
            intents, probabilities = intents.flatten(), probabilities.flatten()
            if intents.size > 0 and probabilities.size > 0:
                ranking = list(zip(list(intents),
                                   list(probabilities)))[:INTENT_RANKING_LENGTH]
                intent = {"name": intents[0], "confidence": probabilities[0]}
                intent_ranking = [{"name": intent_name, "confidence": score}
                                  for intent_name, score in ranking]
            else:
                intent = {"name": None, "confidence": 0.0}
                intent_ranking = []
        message.set("intent", intent, add_to_output=True)
        message.set("intent_ranking", intent_ranking, add_to_output=True)
def process ( self , message , ** kwargs ) : if not self . clf : intent = None intent_ranking = [ ] else : X = message . get ( "text_features" ) . reshape ( 1 , - 1 ) intent_ids , probabilities = self . predict ( X ) intents = self . transform_labels_num2str ( intent_ids ) intents , probabilities = intents . flatten ( ) , probabilities . flatten ( ) if intents . size > 0 and probabilities . size > 0 : ranking = list ( zip ( list ( intents ) , list ( probabilities ) ) ) [ : INTENT_RANKING_LENGTH ] intent = { "name" : intents [ 0 ] , "confidence" : probabilities [ 0 ] } intent_ranking = [ { "name" : intent_name , "confidence" : score } for intent_name , score in ranking ] else : intent = { "name" : None , "confidence" : 0.0 } intent_ranking = [ ] message . set ( "intent" , intent , add_to_output = True ) message . set ( "intent_ranking" , intent_ranking , add_to_output = True )
Return the most likely intent and its probability for a message.
Return the most likely intent and its probability for a message .
# type: (Message, **Any) -> None """Return the most likely intent and its probability for a message.""" # component is either not trained or didn't # receive enough training data # `predict` returns a matrix as it is supposed # to work for multiple examples as well, hence we need to flatten
self
message