MycroftAI / adapt

Adapt Intent Parser
Apache License 2.0
710 stars 154 forks source link

An issue with adapt-parser. Adding new intents is breaking old behavior. #118

Closed Zhdanovich closed 3 years ago

Zhdanovich commented 3 years ago

Hello, I'm running adapt-parser version: 0.3.6 I've found a behavior that I don't understand. I've got different results when adding new intent, but I don't think it should work like this. Here is my code to reproduce an issue.

Here is the code:

from adapt.engine import IntentDeterminationEngine
from adapt.intent import IntentBuilder

adapt_engine = IntentDeterminationEngine()

triplets = []
for x in range(0, 5):
    for y in range(0, 5):
        for z in range(0, 5):
            triplets.append(f"{x} {y} {z}")

def register_entities(engine, entity_name, entities):
    for e in entities:
        engine.register_entity(e, entity_name)

register_entities(adapt_engine, "TripleNumbersMode", triplets)

triplet_numbers_intent = IntentBuilder("TripleNumbersIntent") \
    .require("TripleNumbersMode") \
    .build()
adapt_engine.register_intent_parser(triplet_numbers_intent)

register_entities(adapt_engine, "Numbers", [str(x) for x in list(range(5))])
navigation_verbs = [
    "jump",
    "go back"
]
register_entities(adapt_engine, "NavigationVerb", navigation_verbs)

navigation_intent = IntentBuilder("NavigationModeIntent") \
    .require("NavigationVerb") \
    .require("Numbers") \
    .build()

adapt_engine.register_intent_parser(navigation_intent)

utterance = "1 1 1 2 to 2 3 3 3"
intents = list(adapt_engine.determine_intent(utterance=utterance, num_results=3, include_tags=True))

for intent in intents:
    print(intent)

In this example, I either match triplets of numbers or commands like jump 3, go back 0. If you run my example you will get intent 1 1 2 which is surprising. I would expect to get intent 1 1 1. But when I remove code related to navigation I receive correct intent 1 1 1. I guess it's might be related that both TripleNumbersIntent and NavigationModeIntent contain numbers. How can I fix this issue?

Zhdanovich commented 3 years ago

If I pass "1 1 1 2", it returns two candidates 1 1 1 and 1 1 2 which is explainable behavior.

bjrati commented 3 years ago

If you edit so that "num_results=30", you will find that there are 8 intents returned. The results that you expected are among the 8.

Zhdanovich commented 3 years ago

@bjrati Thanks a lot for the answer, I've figured this behavior before.