def test_random_seed(component_builder, tmpdir): """test if train result is the same for two runs of tf embedding""" _config = utilities.base_test_conf("supervised_embeddings") # set fixed random seed to 1 _config.set_component_attr(5, random_seed=1) # first run (trained_a, _, persisted_path_a) = train( _config, path=tmpdir.strpath + "_a", data=DEFAULT_DATA_PATH, component_builder=component_builder, ) # second run (trained_b, _, persisted_path_b) = train( _config, path=tmpdir.strpath + "_b", data=DEFAULT_DATA_PATH, component_builder=component_builder, ) loaded_a = Interpreter.load(persisted_path_a, component_builder) loaded_b = Interpreter.load(persisted_path_b, component_builder) result_a = loaded_a.parse("hello")["intent"]["confidence"] result_b = loaded_b.parse("hello")["intent"]["confidence"] assert result_a == result_b
def test_train_model_empty_pipeline(component_builder): # Should return an empty pipeline _config = utilities.base_test_conf(pipeline_template=None) with pytest.raises(ValueError): train(_config, data=DEFAULT_DATA_PATH, component_builder=component_builder)
def test_handles_pipeline_with_non_existing_component(component_builder): _config = utilities.base_test_conf("pretrained_embeddings_spacy") _config.pipeline.append({"name": "my_made_up_component"}) with pytest.raises(Exception) as execinfo: train(_config, data=DEFAULT_DATA_PATH, component_builder=component_builder) assert "Failed to find component" in str(execinfo.value)
def trained_moodbot_path(): _, _, persisted_path = train( data="examples/moodbot/data/nlu.md", nlu_config="examples/moodbot/config.yml", path=MOODBOT_MODEL_PATH, ) return persisted_path
def test_train_named_model(component_builder, tmpdir): _config = utilities.base_test_conf("keyword") (trained, _, persisted_path) = train( _config, path=tmpdir.strpath, data=DEFAULT_DATA_PATH, component_builder=component_builder, ) assert trained.pipeline normalized_path = os.path.dirname(os.path.normpath(persisted_path)) # should be saved in a dir named after a project assert normalized_path == tmpdir.strpath
def test_train_model(pipeline_template, component_builder, tmpdir): _config = utilities.base_test_conf(pipeline_template) (trained, _, persisted_path) = train( _config, path=tmpdir.strpath, data=DEFAULT_DATA_PATH, component_builder=component_builder) assert trained.pipeline loaded = Interpreter.load(persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello") is not None assert loaded.parse("Hello today is Monday, again!") is not None
def test_train_model_noents(language, pipeline, component_builder, tmpdir): _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language}) (trained, _, persisted_path) = train( _config, path=tmpdir.strpath, data="./data/test/demo-rasa-noents.json", component_builder=component_builder) assert trained.pipeline loaded = Interpreter.load(persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello") is not None assert loaded.parse("Hello today is Monday, again!") is not None
def test_train_model_on_test_pipelines(language, pipeline, component_builder, tmpdir): _config = RasaNLUModelConfig({"pipeline": pipeline, "language": language}) (trained, _, persisted_path) = train( _config, path=tmpdir.strpath, data=DEFAULT_DATA_PATH, component_builder=component_builder) assert trained.pipeline loaded = Interpreter.load(persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello") is not None assert loaded.parse("Hello today is Monday, again!") is not None