Esempio n. 1
0
    def __init__(self, configuration_values: Optional[Dict[Text, Any]] = None) -> None:
        """Create a model configuration, optionally overriding
        defaults with a dictionary ``configuration_values``.
        """
        if not configuration_values:
            configuration_values = {}

        self.language = "en"
        self.pipeline = []
        self.data = None

        self.override(configuration_values)

        if self.__dict__["pipeline"] is None:
            # replaces None with empty list
            self.__dict__["pipeline"] = []
        elif isinstance(self.__dict__["pipeline"], str):
            from rasa.nlu import registry

            template_name = self.__dict__["pipeline"]
            new_names = {
                "spacy_sklearn": "pretrained_embeddings_spacy",
                "tensorflow_embedding": "supervised_embeddings",
            }
            if template_name in new_names:
                raise_warning(
                    f"You have specified the pipeline template "
                    f"'{template_name}' which has been renamed to "
                    f"'{new_names[template_name]}'. "
                    f"Please update your configuration as it will no "
                    f"longer work with future versions of "
                    f"Rasa.",
                    FutureWarning,
                    docs=DOCS_URL_PIPELINE,
                )
                template_name = new_names[template_name]

            pipeline = registry.pipeline_template(template_name)

            if pipeline:
                # replaces the template with the actual components
                self.__dict__["pipeline"] = pipeline
            else:
                known_templates = ", ".join(
                    registry.registered_pipeline_templates.keys()
                )

                raise InvalidConfigError(
                    f"No pipeline specified and unknown "
                    f"pipeline template '{template_name}' passed. Known "
                    f"pipeline templates: {known_templates}"
                )

        for key, value in self.items():
            setattr(self, key, value)
Esempio n. 2
0
    def __init__(self, configuration_values=None):
        """Create a model configuration, optionally overriding
        defaults with a dictionary ``configuration_values``.
        """
        if not configuration_values:
            configuration_values = {}

        self.language = "en"
        self.pipeline = []
        self.data = None

        self.override(configuration_values)

        if self.__dict__["pipeline"] is None:
            # replaces None with empty list
            self.__dict__["pipeline"] = []
        elif isinstance(self.__dict__["pipeline"], str):
            from rasa.nlu import registry

            template_name = self.__dict__["pipeline"]
            new_names = {
                "spacy_sklearn": "pretrained_embeddings_spacy",
                "tensorflow_embedding": "supervised_embeddings",
            }
            if template_name in new_names:
                logger.warning("You have specified the pipeline template "
                               "'{}' which has been renamed to '{}'. "
                               "Please update your code as it will no "
                               "longer work with future versions of "
                               "Rasa NLU.".format(template_name,
                                                  new_names[template_name]))
                template_name = new_names[template_name]

            pipeline = registry.pipeline_template(template_name)

            if pipeline:
                # replaces the template with the actual components
                self.__dict__["pipeline"] = pipeline
            else:
                known_templates = ", ".join(
                    registry.registered_pipeline_templates.keys())

                raise InvalidConfigError(
                    "No pipeline specified and unknown "
                    "pipeline template '{}' passed. Known "
                    "pipeline templates: {}"
                    "".format(template_name, known_templates))

        for key, value in self.items():
            setattr(self, key, value)