aboutsummaryrefslogtreecommitdiffstats
path: root/snips_inference_agl/pipeline/configs/intent_parser.py
diff options
context:
space:
mode:
Diffstat (limited to 'snips_inference_agl/pipeline/configs/intent_parser.py')
-rw-r--r--snips_inference_agl/pipeline/configs/intent_parser.py127
1 files changed, 127 insertions, 0 deletions
diff --git a/snips_inference_agl/pipeline/configs/intent_parser.py b/snips_inference_agl/pipeline/configs/intent_parser.py
new file mode 100644
index 0000000..f017472
--- /dev/null
+++ b/snips_inference_agl/pipeline/configs/intent_parser.py
@@ -0,0 +1,127 @@
+from __future__ import unicode_literals
+
+from snips_inference_agl.common.from_dict import FromDict
+from snips_inference_agl.constants import CUSTOM_ENTITY_PARSER_USAGE, STOP_WORDS
+from snips_inference_agl.entity_parser import CustomEntityParserUsage
+from snips_inference_agl.pipeline.configs import ProcessingUnitConfig
+from snips_inference_agl.resources import merge_required_resources
+
+
+class ProbabilisticIntentParserConfig(FromDict, ProcessingUnitConfig):
+ """Configuration of a :class:`.ProbabilisticIntentParser` object
+
+ Args:
+ intent_classifier_config (:class:`.ProcessingUnitConfig`): The
+ configuration of the underlying intent classifier, by default
+ it uses a :class:`.LogRegIntentClassifierConfig`
+ slot_filler_config (:class:`.ProcessingUnitConfig`): The configuration
+ that will be used for the underlying slot fillers, by default it
+ uses a :class:`.CRFSlotFillerConfig`
+ """
+
+ def __init__(self, intent_classifier_config=None, slot_filler_config=None):
+ from snips_inference_agl.intent_classifier import IntentClassifier
+ from snips_inference_agl.slot_filler import SlotFiller
+
+ if intent_classifier_config is None:
+ from snips_inference_agl.pipeline.configs import LogRegIntentClassifierConfig
+ intent_classifier_config = LogRegIntentClassifierConfig()
+ if slot_filler_config is None:
+ from snips_inference_agl.pipeline.configs import CRFSlotFillerConfig
+ slot_filler_config = CRFSlotFillerConfig()
+ self.intent_classifier_config = IntentClassifier.get_config(
+ intent_classifier_config)
+ self.slot_filler_config = SlotFiller.get_config(slot_filler_config)
+
+ @property
+ def unit_name(self):
+ from snips_inference_agl.intent_parser import ProbabilisticIntentParser
+ return ProbabilisticIntentParser.unit_name
+
+ def get_required_resources(self):
+ resources = self.intent_classifier_config.get_required_resources()
+ resources = merge_required_resources(
+ resources, self.slot_filler_config.get_required_resources())
+ return resources
+
+ def to_dict(self):
+ return {
+ "unit_name": self.unit_name,
+ "slot_filler_config": self.slot_filler_config.to_dict(),
+ "intent_classifier_config": self.intent_classifier_config.to_dict()
+ }
+
+
+class DeterministicIntentParserConfig(FromDict, ProcessingUnitConfig):
+ """Configuration of a :class:`.DeterministicIntentParser`
+
+ Args:
+ max_queries (int, optional): Maximum number of regex patterns per
+ intent. 50 by default.
+ max_pattern_length (int, optional): Maximum length of regex patterns.
+ ignore_stop_words (bool, optional): If True, stop words will be
+ removed before building patterns.
+
+
+ This allows to deactivate the usage of regular expression when they are
+ too big to avoid explosion in time and memory
+
+ Note:
+ In the future, a FST will be used instead of regexps, removing the need
+ for all this
+ """
+
+ def __init__(self, max_queries=100, max_pattern_length=1000,
+ ignore_stop_words=False):
+ self.max_queries = max_queries
+ self.max_pattern_length = max_pattern_length
+ self.ignore_stop_words = ignore_stop_words
+
+ @property
+ def unit_name(self):
+ from snips_inference_agl.intent_parser import DeterministicIntentParser
+ return DeterministicIntentParser.unit_name
+
+ def get_required_resources(self):
+ return {
+ CUSTOM_ENTITY_PARSER_USAGE: CustomEntityParserUsage.WITHOUT_STEMS,
+ STOP_WORDS: self.ignore_stop_words
+ }
+
+ def to_dict(self):
+ return {
+ "unit_name": self.unit_name,
+ "max_queries": self.max_queries,
+ "max_pattern_length": self.max_pattern_length,
+ "ignore_stop_words": self.ignore_stop_words
+ }
+
+
+class LookupIntentParserConfig(FromDict, ProcessingUnitConfig):
+ """Configuration of a :class:`.LookupIntentParser`
+
+ Args:
+ ignore_stop_words (bool, optional): If True, stop words will be
+ removed before building patterns.
+ """
+
+ def __init__(self, ignore_stop_words=False):
+ self.ignore_stop_words = ignore_stop_words
+
+ @property
+ def unit_name(self):
+ from snips_inference_agl.intent_parser.lookup_intent_parser import \
+ LookupIntentParser
+ return LookupIntentParser.unit_name
+
+ def get_required_resources(self):
+ return {
+ CUSTOM_ENTITY_PARSER_USAGE: CustomEntityParserUsage.WITHOUT_STEMS,
+ STOP_WORDS: self.ignore_stop_words
+ }
+
+ def to_dict(self):
+ return {
+ "unit_name": self.unit_name,
+ "ignore_stop_words": self.ignore_stop_words
+ }