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() )
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)
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
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)
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
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
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
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
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