diff options
author | 2023-10-22 21:06:23 +0500 | |
---|---|---|
committer | 2023-10-23 14:38:13 +0000 | |
commit | 697a1adce1e463079e640b55d6386cf82d7bd6bc (patch) | |
tree | 86e299cc7fe12b10c2e549f640924b61c7d07a95 /snips_inference_agl/pipeline/configs/nlu_engine.py | |
parent | 97029ab8141e654a170a2282106f854037da294f (diff) |
Add Snips Inference Module
Add slightly modified version of the original Snips NLU
library. This module adds support for Python upto version
3.10.
Bug-AGL: SPEC-4856
Signed-off-by: Malik Talha <talhamalik727x@gmail.com>
Change-Id: I6d7e9eb181e6ff4aed9b6291027877ccb9f0d846
Diffstat (limited to 'snips_inference_agl/pipeline/configs/nlu_engine.py')
-rw-r--r-- | snips_inference_agl/pipeline/configs/nlu_engine.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/snips_inference_agl/pipeline/configs/nlu_engine.py b/snips_inference_agl/pipeline/configs/nlu_engine.py new file mode 100644 index 0000000..3826702 --- /dev/null +++ b/snips_inference_agl/pipeline/configs/nlu_engine.py @@ -0,0 +1,55 @@ +from __future__ import unicode_literals + +from snips_inference_agl.common.from_dict import FromDict +from snips_inference_agl.constants import CUSTOM_ENTITY_PARSER_USAGE +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 NLUEngineConfig(FromDict, ProcessingUnitConfig): + """Configuration of a :class:`.SnipsNLUEngine` object + + Args: + intent_parsers_configs (list): List of intent parser configs + (:class:`.ProcessingUnitConfig`). The order in the list determines + the order in which each parser will be called by the nlu engine. + """ + + def __init__(self, intent_parsers_configs=None, random_seed=None): + from snips_inference_agl.intent_parser import IntentParser + + if intent_parsers_configs is None: + from snips_inference_agl.pipeline.configs import ( + ProbabilisticIntentParserConfig, + DeterministicIntentParserConfig) + intent_parsers_configs = [ + DeterministicIntentParserConfig(), + ProbabilisticIntentParserConfig() + ] + self.intent_parsers_configs = [ + IntentParser.get_config(conf) for conf in intent_parsers_configs] + self.random_seed = random_seed + + @property + def unit_name(self): + from snips_inference_agl.nlu_engine.nlu_engine import SnipsNLUEngine + return SnipsNLUEngine.unit_name + + def get_required_resources(self): + # Resolving custom slot values must be done without stemming + resources = { + CUSTOM_ENTITY_PARSER_USAGE: CustomEntityParserUsage.WITHOUT_STEMS + } + for config in self.intent_parsers_configs: + resources = merge_required_resources( + resources, config.get_required_resources()) + return resources + + def to_dict(self): + return { + "unit_name": self.unit_name, + "intent_parsers_configs": [ + config.to_dict() for config in self.intent_parsers_configs + ] + } |