Skip to content

Commit

Permalink
error_handling/very_large_utterances (#392)
Browse files Browse the repository at this point in the history
if we get a very large utterance (over 50 words) we are almost certain any intent match is wrong

these utterances are better handled by a fallback skill, skip adapt/padatious matching entirely
  • Loading branch information
JarbasAl authored Dec 31, 2023
1 parent 98e8b46 commit afbf6c5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ovos_core/intent_services/adapt_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, config=None):
for lang in langs}

self.lock = Lock()
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match

@property
def context_keywords(self):
Expand Down Expand Up @@ -143,6 +144,12 @@ def match_intent(self, utterances, lang=None, message=None):
"""
# we call flatten in case someone is sending the old style list of tuples
utterances = flatten_list(utterances)

utterances = [u for u in utterances if len(u.split()) < self.max_words]
if not utterances:
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping adapt match")
return None

lang = lang or self.lang
if lang not in self.engines:
return None
Expand Down
5 changes: 5 additions & 0 deletions ovos_core/intent_services/padacioso_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(self, bus, config):

self.registered_intents = []
self.registered_entities = []
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match

def _match_level(self, utterances, limit, lang=None):
"""Match intent and make sure a certain level of confidence is reached.
Expand Down Expand Up @@ -217,6 +218,10 @@ def calc_intent(self, utterances: List[str], lang: str = None) -> Optional[Padac
"""
if isinstance(utterances, str):
utterances = [utterances] # backwards compat when arg was a single string
utterances = [u for u in utterances if len(u.split()) < self.max_words]
if not utterances:
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping padacioso match")
return None
lang = lang or self.lang
lang = lang.lower()
if lang in self.containers:
Expand Down
6 changes: 6 additions & 0 deletions ovos_core/intent_services/padatious_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self, bus, config):

self.registered_intents = []
self.registered_entities = []
self.max_words = 50 # if an utterance contains more words than this, don't attempt to match

def train(self, message=None):
"""Perform padatious training.
Expand Down Expand Up @@ -259,6 +260,11 @@ def calc_intent(self, utterances: List[str], lang: str = None) -> Optional[Padat
"""
if isinstance(utterances, str):
utterances = [utterances] # backwards compat when arg was a single string
utterances = [u for u in utterances if len(u.split()) < self.max_words]
if not utterances:
LOG.error(f"utterance exceeds max size of {self.max_words} words, skipping padatious match")
return None

lang = lang or self.lang
lang = lang.lower()
if lang in self.containers:
Expand Down

0 comments on commit afbf6c5

Please sign in to comment.