Ejemplo n.º 1
0
def fetch_attention_feats(interpreter, text):
    msg = Message({TEXT: text})

    for p in interpreter.interpreter.pipeline:
        p.process(msg)

    diag_data = msg.as_dict()["diagnostic_data"]
    diet_key = [k for k in diag_data.keys() if "DIETClassifier" in k][0]
    return (
        diag_data[diet_key]["attention_weights"],
        [t.text for t in msg.as_dict()["text_tokens"]] + ["<SENT>"],
    )
Ejemplo n.º 2
0
    def parse(
        self,
        text: Text,
        time: Optional[datetime.datetime] = None,
        only_output_properties: bool = True,
    ) -> Dict[Text, Any]:
        """Parse the input text, classify it and return pipeline result.

        The pipeline result usually contains intent and entities."""

        if not text:
            # Not all components are able to handle empty strings. So we need
            # to prevent that... This default return will not contain all
            # output attributes of all components, but in the end, no one
            # should pass an empty string in the first place.
            output = self.default_output_attributes()
            output["text"] = ""
            return output

        data = self.default_output_attributes()
        data[TEXT] = text

        message = Message(data=data, time=time)

        for component in self.pipeline:
            component.process(message, **self.context)

        output = self.default_output_attributes()
        output.update(
            message.as_dict(only_output_properties=only_output_properties))
        return output