Beispiel #1
0
def test_override_defaults_supervised_embeddings_pipeline():
    builder = ComponentBuilder()

    _config = RasaNLUModelConfig(
        {
            "language": "en",
            "pipeline": [
                {"name": "SpacyNLP"},
                {"name": "SpacyTokenizer"},
                {"name": "SpacyFeaturizer", "pooling": "max"},
                {
                    "name": "DIETClassifier",
                    "epochs": 10,
                    "hidden_layers_sizes": {"text": [256, 128]},
                },
            ],
        }
    )

    idx_featurizer = _config.component_names.index("SpacyFeaturizer")
    idx_classifier = _config.component_names.index("DIETClassifier")

    component1 = builder.create_component(
        _config.for_component(idx_featurizer), _config
    )
    assert component1.component_config["pooling"] == "max"

    component2 = builder.create_component(
        _config.for_component(idx_classifier), _config
    )
    assert component2.component_config["epochs"] == 10
    assert (
        component2.defaults["hidden_layers_sizes"].keys()
        == component2.component_config["hidden_layers_sizes"].keys()
    )
Beispiel #2
0
def test_create_component_exception_messages(
    component_builder: ComponentBuilder,
    blank_config: RasaNLUModelConfig,
    test_input: Text,
    expected_output: Text,
    error: Exception,
):

    with pytest.raises(error):
        component_config = {"name": test_input}
        component_builder.create_component(component_config, blank_config)
Beispiel #3
0
def test_override_defaults_supervised_embeddings_pipeline():
    cfg = config.load("data/test/config_embedding_test.yml")
    builder = ComponentBuilder()

    component1_cfg = cfg.for_component(0)

    component1 = builder.create_component(component1_cfg, cfg)
    assert component1.max_ngram == 3

    component2_cfg = cfg.for_component(1)
    component2 = builder.create_component(component2_cfg, cfg)
    assert component2.epochs == 10
Beispiel #4
0
    def validate_rasa_config(config: Dict):
        """
        validates bot config.yml content for invalid entries
        :param config: configuration
        :return: None
        """
        rasa_config = RasaNLUModelConfig(config)
        component_builder = ComponentBuilder()
        for i in range(len(rasa_config.pipeline)):
            component_cfg = rasa_config.for_component(i)
            component_builder.create_component(component_cfg, rasa_config)

        configuration.load(config)
Beispiel #5
0
def test_builder_create_by_module_path(component_builder: ComponentBuilder,
                                       blank_config: RasaNLUModelConfig):
    from rasa.nlu.featurizers.sparse_featurizer.regex_featurizer import RegexFeaturizer

    path = "rasa.nlu.featurizers.sparse_featurizer.regex_featurizer.RegexFeaturizer"
    component_config = {"name": path}
    component = component_builder.create_component(component_config,
                                                   blank_config)
    assert type(component) == RegexFeaturizer
Beispiel #6
0
    def _build_pipeline(
        cfg: RasaNLUModelConfig, component_builder: ComponentBuilder
    ) -> List[Component]:
        """Transform the passed names of the pipeline components into classes"""
        pipeline = []

        # Transform the passed names of the pipeline components into classes
        for i in range(len(cfg.pipeline)):
            component_cfg = cfg.for_component(i)
            component = component_builder.create_component(component_cfg, cfg)
            pipeline.append(component)

        return pipeline
Beispiel #7
0
    def _build_pipeline(
        self, cfg: RasaNLUModelConfig, component_builder: ComponentBuilder
    ) -> List[Component]:
        """Transform the passed names of the pipeline components into classes."""
        pipeline = []

        # Transform the passed names of the pipeline components into classes
        for index, pipeline_component in enumerate(cfg.pipeline):
            component_cfg = cfg.for_component(index)
            component = component_builder.create_component(component_cfg, cfg)
            components.validate_component_keys(component, pipeline_component)
            pipeline.append(component)

        if not self.skip_validation:
            components.validate_pipeline(pipeline)

        return pipeline
Beispiel #8
0
def spacy_nlp(component_builder: ComponentBuilder,
              blank_config: RasaNLUModelConfig):
    spacy_nlp_config = {"name": "SpacyNLP", "model": "en_core_web_md"}
    return component_builder.create_component(spacy_nlp_config,
                                              blank_config).nlp
Beispiel #9
0
def mitie_feature_extractor(component_builder: ComponentBuilder, blank_config):
    mitie_nlp_config = {"name": "MitieNLP"}
    return component_builder.create_component(mitie_nlp_config,
                                              blank_config).extractor