Ejemplo n.º 1
0
def test_model_accuracies_are_similar_before_and_after_caching(
        kwik_e_mart_app_path):
    # clear model cache
    model_cache_path = MODEL_CACHE_PATH.format(app_path=kwik_e_mart_app_path)
    try:
        shutil.rmtree(MODEL_CACHE_PATH.format(app_path=kwik_e_mart_app_path))
    except FileNotFoundError:
        pass

    # Make sure no cache exists
    assert os.path.exists(model_cache_path) is False
    nlp = NaturalLanguageProcessor(kwik_e_mart_app_path)
    nlp.build(incremental=True)
    nlp.dump()

    intent_eval = nlp.domains["store_info"].intent_classifier.evaluate()
    entity_eval = (nlp.domains["store_info"].intents["get_store_hours"].
                   entity_recognizer.evaluate())
    intent_accuracy_no_cache = intent_eval.get_accuracy()
    entity_accuracy_no_cache = entity_eval.get_accuracy()

    example_cache = os.listdir(
        MODEL_CACHE_PATH.format(app_path=kwik_e_mart_app_path))[0]
    nlp = NaturalLanguageProcessor(kwik_e_mart_app_path)
    nlp.load(example_cache)

    # make sure cache exists
    assert os.path.exists(model_cache_path) is True

    intent_eval = nlp.domains["store_info"].intent_classifier.evaluate()
    entity_eval = (nlp.domains["store_info"].intents["get_store_hours"].
                   entity_recognizer.evaluate())
    intent_accuracy_cached = intent_eval.get_accuracy()
    entity_accuracy_cached = entity_eval.get_accuracy()

    assert intent_accuracy_no_cache == intent_accuracy_cached
    assert entity_accuracy_no_cache == entity_accuracy_cached
Ejemplo n.º 2
0
def kwik_e_mart_nlp(kwik_e_mart_app_path):
    """Provides a built processor instance"""
    nlp = NaturalLanguageProcessor(app_path=kwik_e_mart_app_path)
    nlp.build()
    nlp.dump()
    return nlp
Ejemplo n.º 3
0
def home_assistant_nlp(home_assistant_app_path):
    """Provides a built processor instance"""
    nlp = NaturalLanguageProcessor(app_path=home_assistant_app_path)
    nlp.build()
    nlp.dump()
    return nlp
Ejemplo n.º 4
0
def food_ordering_nlp(food_ordering_app_path):
    """Provides a built processor instance"""
    nlp = NaturalLanguageProcessor(app_path=food_ordering_app_path)
    nlp.build()
    nlp.dump()
    return nlp