def test_train_named_model(component_builder): _config = utilities.base_test_conf("keyword") _config['name'] = "my_keyword_model" (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline assert persisted_path.strip("/\\").endswith( "my_keyword_model") # should be saved in a dir named after model
def test_train_model(pipeline_template, component_builder): _config = utilities.base_test_conf(pipeline_template) (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, component_builder) assert loaded.pipeline
def test_train_model(pipeline_template, component_builder): _config = utilities.base_test_conf(pipeline_template) (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello", time=None) is not None
def test_train_model_multithread(pipeline_template, interpreter_builder): _config = utilities.base_test_conf(pipeline_template) _config['num_threads'] = 2 (trained, persisted_path) = utilities.run_train(_config) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, interpreter_builder) assert loaded.pipeline
def test_train_model_noents(component_builder): _config = utilities.base_test_conf("all_components") _config['data'] = "./data/examples/rasa/demo-rasa-noents.json" (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello", time=None) is not None
def test_train_model(pipeline_template, component_builder): _config = utilities.base_test_conf(pipeline_template) (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, 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_backend(backend_name): _config = base_test_conf(backend_name) (trained, persisted_path) = utilities.run_train(_config) assert trained.entity_extractor is not None assert trained.intent_classifier is not None loaded = utilities.load_interpreter_for_model(_config, persisted_path) assert loaded.extractor is not None assert loaded.classifier is not None
def test_train_model_noents(pipeline_template, interpreter_builder): _config = utilities.base_test_conf(pipeline_template) _config['data'] = "./data/examples/rasa/demo-rasa-noents.json" (trained, persisted_path) = utilities.run_train(_config) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, interpreter_builder) assert loaded.pipeline
def test_train_model_multithread(component_builder): _config = utilities.base_test_conf("all_components") _config['num_threads'] = 2 (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, component_builder) assert loaded.pipeline assert loaded.parse("hello", time=None) is not None
def test_train_model_noents(component_builder): _config = utilities.base_test_conf("all_components") _config['data'] = "./data/examples/mynlu/demo-mynlu-noents.json" (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, 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_backend_noents(backend_name): _config = base_test_conf(backend_name) _config['data'] = "./data/examples/rasa/demo-rasa-noents.json" (trained, persisted_path) = utilities.run_train(_config) assert trained.entity_extractor is None assert trained.intent_classifier is not None loaded = utilities.load_interpreter_for_model(_config, persisted_path) assert loaded.extractor is None assert loaded.classifier is not None
def test_train_backend_multithread(backend_name, spacy_nlp_en): # basic conf _config = base_test_conf(backend_name) _config['num_threads'] = 2 (trained, persisted_path) = utilities.run_train(_config) assert trained.entity_extractor is not None assert trained.intent_classifier is not None loaded = utilities.load_interpreter_for_model(spacy_nlp_en, _config, persisted_path) assert loaded.extractor is not None assert loaded.classifier is not None
def test_train_spacy_sklearn_finetune_ner(): # basic conf _config = base_test_conf(SPACY_BACKEND_NAME) _config['fine_tune_spacy_ner'] = True (trained, _) = utilities.run_train(_config) assert trained.entity_extractor is not None assert trained.intent_classifier is not None doc = trained.nlp(u"I am living in New York now.") entities = trained.entity_extractor.extract_entities(doc) # Although the model is trained on restaurant entities, we can use the entities (`GPE`, `DATE`) # from spacy since we are fine tuning. This should even be the case if the rasa-entity training data changes! assert { u'start': 15, u'end': 23, u'value': u'New York', u'entity': u'GPE' } in entities
def test_train_spacy_sklearn_finetune_ner(interpreter_builder): _config = utilities.base_test_conf("spacy_sklearn") _config['fine_tune_spacy_ner'] = True (trained, persisted_path) = utilities.run_train(_config) assert trained.pipeline loaded = utilities.load_interpreter_for_model(_config, persisted_path, interpreter_builder) result = loaded.parse(u"I am living in New York now.") entities = result['entities'] # Although the model is trained on restaurant entities, we can use the entities (`GPE`, `DATE`) # from spacy since we are fine tuning. This should even be the case if the rasa-entity training data changes! assert { u'start': 15, u'end': 23, u'value': u'New York', u'entity': u'GPE' } in entities
def test_handles_pipeline_with_non_existing_component(component_builder): _config = utilities.base_test_conf("spacy_sklearn") _config['pipeline'].append("my_made_up_component") with pytest.raises(Exception) as execinfo: utilities.run_train(_config, component_builder) assert "Failed to find component" in str(execinfo.value)
def test_train_model_empty_pipeline(component_builder): _config = utilities.base_test_conf( pipeline_template=None) # Should return an empty pipeline with pytest.raises(ValueError): utilities.run_train(_config, component_builder)
def test_train_model_empty_pipeline(component_builder): _config = utilities.base_test_conf(pipeline_template=None) # Should return an empty pipeline with pytest.raises(ValueError): utilities.run_train(_config, component_builder)
def test_train_named_model(component_builder): _config = utilities.base_test_conf("keyword") _config['name'] = "my_keyword_model" (trained, persisted_path) = utilities.run_train(_config, component_builder) assert trained.pipeline assert persisted_path.strip("/\\").endswith("my_keyword_model") # should be saved in a dir named after model