Skip to content

Commit

Permalink
Merge pull request #544 from hellohaptik/BB-11092
Browse files Browse the repository at this point in the history
(adhoc)(platform-support) Add logs for debugging the entity detection issue for NSDC
  • Loading branch information
haptikrajasashtikar authored Oct 26, 2023
2 parents efa686a + 56fb55d commit 81aa200
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY docker/nginx.conf /etc/nginx/nginx.conf
COPY docker/default.site.conf /etc/nginx/sites-available/default

# TODO: Separate this out to a dev/test docker image
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash && \
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash && \
apt-get install nodejs && \
npm install -g newman && \
npm install -g newman-reporter-htmlextra && \
Expand Down
1 change: 1 addition & 0 deletions ner_v2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ def text(request):

try:
validate_text_request(request)
ner_logger.debug("Valid text request")
# if verify success get detection data
data = get_text_entity_detection_data(request)
except InvalidTextRequest as err:
Expand Down
4 changes: 1 addition & 3 deletions ner_v2/detectors/textual/text_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def _get_bulk_text_detection_with_variants(self, messages):
entity_list=entity_list,
text=text, processed_text=processed_text)
final_list.append(result_list)

ner_logger.debug(f'[bulk_text_detection_with_variants] final_list: {final_list}')
return final_list

def _get_entity_substring_from_text(self, text, variant, entity_name):
Expand Down Expand Up @@ -668,7 +668,6 @@ def detect(self, message=None, **kwargs):

entities[entity] = out
data_list.append(entities)

return data_list

def detect_bulk(self, messages=None, **kwargs):
Expand Down Expand Up @@ -768,7 +767,6 @@ def detect_bulk(self, messages=None, **kwargs):

entities[entity] = out
data_list.append(entities)

return data_list

@staticmethod
Expand Down
10 changes: 8 additions & 2 deletions ner_v2/detectors/textual/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ def get_detection(message, entity_dict, bot_message=None, language=ENGLISH_LANG,
detected entity output
"""
ner_logger.debug(f'[get_detection] message: {message}')
text_detector = TextDetector(entity_dict=entity_dict, source_language_script=language,
target_language_script=target_language_script)
if isinstance(message, six.string_types):
entity_output = text_detector.detect(message=message,
bot_message=bot_message)
ner_logger.debug(f'[Single Message Detection] Entity Output {entity_output}')
elif isinstance(message, (list, tuple)):
entity_output = text_detector.detect_bulk(messages=message)
ner_logger.debug(f'[Multiple Message Detection] Entity Output {entity_output}')
else:
raise TypeError('`message` argument must be either of type `str`, `unicode`, `list` or `tuple`.')

Expand Down Expand Up @@ -158,10 +161,12 @@ def get_text_entity_detection_data(request):
"""
request_data = json.loads(request.body)
messages = request_data.get("messages", [])
ner_logger.debug(f"Request message data {messages}")
bot_message = request_data.get("bot_message")
entities = request_data.get("entities", {})
target_language_script = request_data.get('language_script') or ENGLISH_LANG
source_language = request_data.get('source_language') or ENGLISH_LANG
ner_logger.debug(f"Request entity data {entities}")

data = []

Expand All @@ -188,10 +193,12 @@ def get_text_entity_detection_data(request):
# get detection for text entities which has ignore_message flag
if fallback_value_entities:
output = get_output_for_fallback_entities(fallback_value_entities, source_language)
ner_logger.debug(f'[output_for_fallback_entities] output: {output}')
data[0]["entities"].update(output)

# get detection for text entities
if text_value_entities:
ner_logger.debug(f'[output_for_fallback_entities] text_value_entities {text_value_entities}')
output = get_detection(message=message_str, entity_dict=text_value_entities,
structured_value=None, bot_message=bot_message,
language_script=source_language,
Expand All @@ -202,14 +209,13 @@ def get_text_entity_detection_data(request):
elif len(messages) > 1:
text_detection_result = get_detection(message=messages, entity_dict=entities,
structured_value=None, bot_message=bot_message)

data = [{"entities": x, "language": source_language} for x in text_detection_result]

else:
ner_logger.debug("No valid message provided")
raise InvalidTextRequest(f"Key `messages` is required to be a non-empty List[str], "
f"but got a list with length {message_len}")

ner_logger.debug(f"Final data {data}")
return data


Expand Down

0 comments on commit 81aa200

Please sign in to comment.