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 Interface] Query interpretation fine tuning (disable clustering for multi SV detection; defaulting to Earth place under some circumstances) #1988

Merged
merged 8 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
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
24 changes: 20 additions & 4 deletions server/routes/nl_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import flask
from flask import Blueprint, current_app, render_template, escape, request
from google.protobuf.json_format import MessageToJson, ParseDict
from lib.nl_detection import ClassificationType, Detection, NLClassifier, Place, PlaceDetection, SVDetection, SimpleClassificationAttributes
from lib.nl_detection import ClassificationType, ContainedInPlaceType, Detection, NLClassifier, Place, PlaceDetection, SVDetection, SimpleClassificationAttributes
import pandas as pd
import re
import requests
Expand Down Expand Up @@ -505,7 +505,22 @@ def _detection(orig_query, cleaned_query, embeddings_build) -> Detection:
if contained_in_classification is not None:
classifications.append(contained_in_classification)

if svs_scores_dict:
# Check if the contained in referred to COUNTRY type. If so,
# and the default location was chosen, then set it to Earth.
if (place_detection.using_default_place and
(contained_in_classification.attributes.contained_in_place_type
== ContainedInPlaceType.COUNTRY)):
logging.info(
"Changing detected place to Earth because no place was detected and contained in is about countries."
)
place_detection.main_place.dcid = "Earth"
place_detection.main_place.name = "Earth"
place_detection.main_place.place_type = "Place"
place_detection.using_default_place = False

# Clustering-based different SV detection is only enabled in LOCAL.
correlation_classification = None
if os.environ.get('FLASK_ENV') == 'local' and svs_scores_dict:
# Embeddings Indices.
sv_index_sorted = []
if 'EmbeddingIndex' in svs_scores_dict:
Expand All @@ -517,8 +532,9 @@ def _detection(orig_query, cleaned_query, embeddings_build) -> Detection:
svs_scores_dict['CosineScore'], sv_index_sorted,
COSINE_SIMILARITY_CUTOFF)
logging.info(f'Correlation classification: {correlation_classification}')
if correlation_classification is not None:
classifications.append(correlation_classification)
logging.info(f'Correlation Classification is currently disabled.')
# if correlation_classification is not None:
# classifications.append(correlation_classification)

if not classifications:
# Simple Classification simply means:
Expand Down
4 changes: 4 additions & 0 deletions server/services/nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ def _containedin_classification(self, prediction,
contained_in_place_type = place_enum
break

# If place_type is just PLACE, that means no actual type was detected.
if contained_in_place_type == ContainedInPlaceType.PLACE:
return None

# TODO: need to detect the type of place for this contained in.
attributes = ContainedInClassificationAttributes(
contained_in_place_type=contained_in_place_type)
Expand Down
2 changes: 1 addition & 1 deletion static/js/apps/nl_interface/debug_info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Col, Row } from "reactstrap";
import { DebugInfo, SVScores } from "../../types/app/nl_interface_types";

export const BUILD_OPTIONS = [
{ value: "us_filtered", text: "Filtered US SVs (PaLM)" },
{ value: "us_filtered", text: "Filtered US SVs" },
{
value: "curatedJan2022",
text: "Curated 3.5k+ SVs PaLM(Jan2022) - Default",
Expand Down