44any slots that are associated with that intent.
55"""
66import json
7+ import logging
78import os
89from importlib import import_module
910from typing import List , Tuple
1617from spokestack .nlu .result import Result
1718
1819
20+ _LOG = logging .getLogger (__name__ )
21+
22+
1923class TFLiteNLU :
2024 """ Abstraction for using TFLite NLU models
2125
@@ -60,12 +64,16 @@ def __call__(self, utterance: str) -> Result:
6064
6165 # slice off special tokens: [CLS], [SEP]
6266 tags = tags [: len (input_ids ) - 2 ]
67+ _LOG .debug (f"{ tags } " )
6368 input_ids = input_ids [1 :- 1 ]
69+ _LOG .debug (f"{ input_ids } " )
6470 # retrieve slots from the tagged positions and decode slots back
6571 # into original values
6672 slots = [
6773 (token_id , tag [2 :]) for token_id , tag in zip (input_ids , tags ) if tag != "o"
6874 ]
75+ _LOG .debug (f"{ slots } " )
76+
6977 slot_map : dict = {}
7078 for (token , tag ) in slots :
7179 if tag in slot_map :
@@ -86,6 +94,7 @@ def __call__(self, utterance: str) -> Result:
8694 "parsed_value" : parsed ,
8795 "raw_value" : slot_map [key ],
8896 }
97+ _LOG .debug (f"parsed slots: { parsed_slots } " )
8998 return Result (
9099 utterance = utterance ,
91100 intent = intent ,
@@ -123,6 +132,9 @@ def _decode(self, outputs) -> Tuple[str, List[str], float]:
123132 intent_posterior , tag_posterior = outputs
124133 intents , confidence = self ._decode_intent (intent_posterior )
125134 tags = self ._decode_tags (tag_posterior )
135+ _LOG .debug (f"decoded tags: { tags } " )
136+ _LOG .debug (f"decoded intent: { intents } " )
137+ _LOG .debug (f"confidence: { confidence } " )
126138 return intents , tags , confidence
127139
128140 def _decode_tags (self , posterior ):
0 commit comments