Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NL] Disable llm fallback for entity based queries. #4722

Merged
merged 3 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions server/lib/nl/detection/llm_fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def need_llm(heuristic: Detection, prev_uttr: Utterance,
need_sv = False
need_place = False

# Do not use LLM when an entity has been identified.
if _has_entity(heuristic):
return NeedLLM.No

# 1. If there was no SV or prop.
if _has_no_sv(heuristic, ctr) and _has_no_prop(heuristic, ctr):

Expand All @@ -79,8 +83,8 @@ def need_llm(heuristic: Detection, prev_uttr: Utterance,
ctr.info('info_fallback_no_sv_found', '')
need_sv = True

# 2. If there was no place or entity.
if _has_no_place(heuristic) and _has_no_entity(heuristic):
# 2. If there was no place and no entity.
if _has_no_place(heuristic) and not _has_entity(heuristic):

# For COUNTRY contained-in type, Earth is assumed
# (e.g., countries with worst health), so exclude that.
Expand Down Expand Up @@ -118,8 +122,8 @@ def _has_no_prop(d: Detection, ctr: counters.Counters) -> bool:
d.svs_detected.prop, d.svs_detected.sv_threshold, ctr)


def _has_no_entity(d: Detection) -> bool:
return not d.places_detected or not d.places_detected.entities_found
def _has_entity(d: Detection) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think we need this helper since there's not really any logic here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double negative is a little rough for readability -- I updated the code to only have _has_entity to avoid this issue. Is that okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this for now so that the logic is in autopush. I can change the readability part if you prefer the _has_no_entity with the double negative as a follow up!

return d.places_detected and d.places_detected.entities_found


#
Expand Down
Loading