Ejemplo n.º 1
0
    def _generate_training_examples_md(self,
                                       training_data: "TrainingData") -> Text:
        """Generates markdown training examples."""

        import rasa.shared.nlu.training_data.util as rasa_nlu_training_data_utils

        training_examples = OrderedDict()

        # Sort by intent while keeping basic intent order
        for example in [
                e.as_dict_nlu() for e in training_data.training_examples
        ]:
            rasa_nlu_training_data_utils.remove_untrainable_entities_from(
                example)
            intent = example[INTENT]
            training_examples.setdefault(intent, [])
            training_examples[intent].append(example)

        # Don't prepend newline for first line
        prepend_newline = False
        lines = []

        for intent, examples in training_examples.items():
            section_header = self._generate_section_header_md(
                INTENT, intent, prepend_newline=prepend_newline)
            lines.append(section_header)
            prepend_newline = True

            lines += [
                self.generate_list_item(self.generate_message(example))
                for example in examples
            ]

        return "".join(lines)
Ejemplo n.º 2
0
    def prepare_training_examples(
            training_data: "TrainingData") -> OrderedDict:
        """Pre-processes training data examples by removing not trainable entities."""

        import rasa.shared.nlu.training_data.util as rasa_nlu_training_data_utils

        training_examples = OrderedDict()

        # Sort by intent while keeping basic intent order
        for example in [
                e.as_dict_nlu() for e in training_data.training_examples
        ]:
            if not example.get(INTENT):
                continue
            # bf >
            metadata = example.pop("metadata", {})
            language = metadata.pop("language", None)
            if metadata:
                example["metadata"] = metadata
            # < bf
            rasa_nlu_training_data_utils.remove_untrainable_entities_from(
                example)
            # bf >
            intent = (example[INTENT], language)
            # intent = example[INTENT]
            # < bf
            training_examples.setdefault(intent, [])
            training_examples[intent].append(example)

        return training_examples
Ejemplo n.º 3
0
    def prepare_training_examples(training_data: "TrainingData") -> OrderedDict:
        """Pre-processes training data examples by removing not trainable entities."""

        import rasa.shared.nlu.training_data.util as rasa_nlu_training_data_utils

        training_examples = OrderedDict()

        # Sort by intent while keeping basic intent order
        for example in [e.as_dict_nlu() for e in training_data.training_examples]:
            rasa_nlu_training_data_utils.remove_untrainable_entities_from(example)
            intent = example[INTENT]
            training_examples.setdefault(intent, [])
            training_examples[intent].append(example)

        return training_examples
Ejemplo n.º 4
0
    def prepare_training_examples(
        training_data: "TrainingData",
    ) -> Dict[Text, List[Union[Dict, Text]]]:
        """Pre-processes training data examples by removing not trainable entities."""
        import rasa.shared.nlu.training_data.util as rasa_nlu_training_data_utils

        training_examples: Dict[Text, List[Union[Dict, Text]]] = OrderedDict()

        # Sort by intent while keeping basic intent order
        for example in [e.as_dict_nlu() for e in training_data.training_examples]:
            if not example.get(INTENT):
                continue
            rasa_nlu_training_data_utils.remove_untrainable_entities_from(example)
            intent = example[INTENT]
            training_examples.setdefault(intent, [])
            training_examples[intent].append(example)

        return training_examples