Skip to content

Commit

Permalink
Accept ambiguous results from DeterministicIntentParser when confiden…
Browse files Browse the repository at this point in the history
…ce score is above 0.5 (#797)
  • Loading branch information
adrienball authored May 6, 2019
1 parent 20aa29b commit 467028d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [Unreleased]
### Changed
- Re-score ambiguous `DeterministicIntentParser` results based on slots [#791](https://github.com/snipsco/snips-nlu/pull/791)
- Accept ambiguous results from `DeterministicIntentParser` when confidence score is above 0.5 [#797](https://github.com/snipsco/snips-nlu/pull/797)

## [0.19.6]
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion snips_nlu/intent_parser/deterministic_intent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def parse(self, text, intents=None, top_n=None):
if top_intents:
intent = top_intents[0][RES_INTENT]
slots = top_intents[0][RES_SLOTS]
if intent[RES_PROBA] < 1.0:
if intent[RES_PROBA] <= 0.5:
# return None in case of ambiguity
return empty_result(text, probability=1.0)
return parsing_result(text, intent, slots)
Expand Down
46 changes: 40 additions & 6 deletions snips_nlu/tests/test_deterministic_intent_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from snips_nlu.pipeline.configs import DeterministicIntentParserConfig
from snips_nlu.result import (
extraction_result, intent_classification_result, unresolved_slot,
empty_result)
empty_result, parsing_result)
from snips_nlu.tests.utils import FixtureTest, TEST_PATH


Expand Down Expand Up @@ -244,7 +244,7 @@ def test_should_parse_intent_with_duplicated_slot_names(self):
self.assertDictEqual(expected_intent, parsing[RES_INTENT])
self.assertListEqual(expected_slots, parsing[RES_SLOTS])

def test_should_ignore_ambiguous_utterances(self):
def test_should_ignore_completely_ambiguous_utterances(self):
# Given
dataset_stream = io.StringIO("""
---
Expand All @@ -268,30 +268,64 @@ def test_should_ignore_ambiguous_utterances(self):
# Then
self.assertEqual(empty_result(text, 1.0), res)

def test_should_ignore_subtly_ambiguous_utterances(self):
def test_should_ignore_very_ambiguous_utterances(self):
# Given
dataset_stream = io.StringIO("""
---
type: intent
name: intent_1
utterances:
- meeting tomorrow
- "[event_type](meeting) tomorrow"
---
type: intent
name: intent_2
utterances:
- meeting [time:snips/datetime](today)""")
- call [time:snips/datetime](today)
---
type: entity
name: event_type
values:
- call
- diner""")
dataset = Dataset.from_yaml_files("en", [dataset_stream]).json
parser = DeterministicIntentParser().fit(dataset)
text = "meeting tomorrow"
text = "call tomorrow"

# When
res = parser.parse(text)

# Then
self.assertEqual(empty_result(text, 1.0), res)

def test_should_parse_slightly_ambiguous_utterances(self):
# Given
dataset_stream = io.StringIO("""
---
type: intent
name: intent_1
utterances:
- call tomorrow
---
type: intent
name: intent_2
utterances:
- call [time:snips/datetime](today)""")
dataset = Dataset.from_yaml_files("en", [dataset_stream]).json
parser = DeterministicIntentParser().fit(dataset)
text = "call tomorrow"

# When
res = parser.parse(text)

# Then
expected_intent = intent_classification_result(
intent_name="intent_1", probability=2. / 3.)
expected_result = parsing_result(text, expected_intent, [])
self.assertEqual(expected_result, res)

def test_should_not_parse_when_not_fitted(self):
# Given
parser = DeterministicIntentParser()
Expand Down

0 comments on commit 467028d

Please sign in to comment.