(self, message, **kwargs)
Returns the most likely label and its probability for the input text.
Returns the most likely label and its probability for the input text.
Returns the most likely label and its probability for the input text .
def process(self, message, **kwargs):
        # type: (Message, **Any) -> None
        """Returns the most likely label and its probability for the input text."""

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

            if labels.size > 0 and probabilities.size > 0:
                ranking = list(zip(list(labels), list(probabilities)))[:CLASSIFY_RANKING_LENGTH]
                label = {"name": labels[0], "confidence": probabilities[0]}
                label_ranking = [{"name": label_name, "confidence": score} for label_name, score in ranking]
            else:
                label = {"name": None, "confidence": 0.0}
                label_ranking = []

        message.set("classifylabel", label, add_to_output=True)
        message.set("classifylabel_ranking", label_ranking, add_to_output=True)
def process ( self , message , * * kwargs ) : # type: (Message, **Any) -> None if not self . clf : # component is either not trained or didn't receive enough training data label = None label_ranking = [ ] else : X = message . get ( "sentence_embedding" ) . reshape ( 1 , - 1 ) label_ids , probabilities = self . predict ( X ) labels = self . transform_labels_num2str ( label_ids ) # `predict` returns a matrix as it is supposed # to work for multiple examples as well, hence we need to flatten labels , probabilities = labels . flatten ( ) , probabilities . flatten ( ) if labels . size > 0 and probabilities . size > 0 : ranking = list ( zip ( list ( labels ) , list ( probabilities ) ) ) [ : CLASSIFY_RANKING_LENGTH ] label = { "name" : labels [ 0 ] , "confidence" : probabilities [ 0 ] } label_ranking = [ { "name" : label_name , "confidence" : score } for label_name , score in ranking ] else : label = { "name" : None , "confidence" : 0.0 } label_ranking = [ ] message . set ( "classifylabel" , label , add_to_output = True ) message . set ( "classifylabel_ranking" , label_ranking , add_to_output = True )