Beispiel #1
0
def test_train_load_predict_loop(
    default_model_storage: ModelStorage,
    default_execution_context: ExecutionContext,
    mitie_model: MitieModel,
):
    resource = Resource("mitie_classifier")
    component = MitieIntentClassifierGraphComponent.create(
        MitieIntentClassifierGraphComponent.get_default_config(),
        default_model_storage,
        resource,
        default_execution_context,
    )

    training_data = rasa.shared.nlu.training_data.loading.load_data(
        "data/examples/rasa/demo-rasa.yml")
    tokenizer = MitieTokenizer()
    # Tokenize message as classifier needs that
    tokenizer.train(training_data)

    component.train(training_data, mitie_model)

    component = MitieIntentClassifierGraphComponent.load(
        MitieIntentClassifierGraphComponent.get_default_config(),
        default_model_storage,
        resource,
        default_execution_context,
    )

    test_message = Message({TEXT: "hi"})
    tokenizer.process(test_message)
    component.process([test_message], mitie_model)

    assert test_message.data[INTENT][INTENT_NAME_KEY] == "greet"
    assert test_message.data[INTENT][PREDICTED_CONFIDENCE_KEY] > 0
Beispiel #2
0
def test_custom_intent_symbol(text, expected_tokens):
    component_config = {
        "intent_tokenization_flag": True,
        "intent_split_symbol": "+"
    }

    tk = MitieTokenizer(component_config)

    message = Message(text)
    message.set(INTENT, text)

    tk.train(TrainingData([message]))

    assert [t.text
            for t in message.get(TOKENS_NAMES[INTENT])] == expected_tokens