From 40d6306c5e88fd975da9c7a04522a18fef8a0373 Mon Sep 17 00:00:00 2001 From: Jehangir Amjad Date: Mon, 9 Jan 2023 17:45:50 -0800 Subject: [PATCH 1/5] Removing PaLM --- static/js/apps/nl_interface/debug_info.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/apps/nl_interface/debug_info.tsx b/static/js/apps/nl_interface/debug_info.tsx index ca77abda50..4aa855c73b 100644 --- a/static/js/apps/nl_interface/debug_info.tsx +++ b/static/js/apps/nl_interface/debug_info.tsx @@ -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", From b163c351918eb504907b2d2ab86ee936bd5ebc1d Mon Sep 17 00:00:00 2001 From: Jehangir Amjad Date: Mon, 9 Jan 2023 20:47:25 -0800 Subject: [PATCH 2/5] disable multi-sv clustering based classification --- server/routes/nl_interface.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/routes/nl_interface.py b/server/routes/nl_interface.py index 6ea17b12ff..6abc3390ec 100644 --- a/server/routes/nl_interface.py +++ b/server/routes/nl_interface.py @@ -505,7 +505,9 @@ 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: + # 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: @@ -517,8 +519,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: From a1788b36bacadd332c6b4d4bba2d08135a54c80c Mon Sep 17 00:00:00 2001 From: Jehangir Amjad Date: Mon, 9 Jan 2023 21:15:55 -0800 Subject: [PATCH 3/5] Some more fine tuning --- server/routes/nl_interface.py | 12 +++++++++++- server/services/nl.py | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/routes/nl_interface.py b/server/routes/nl_interface.py index 6abc3390ec..ef5b32fd0e 100644 --- a/server/routes/nl_interface.py +++ b/server/routes/nl_interface.py @@ -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 @@ -505,6 +505,16 @@ def _detection(orig_query, cleaned_query, embeddings_build) -> Detection: if contained_in_classification is not None: classifications.append(contained_in_classification) + # 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 & + (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: diff --git a/server/services/nl.py b/server/services/nl.py index 226b8af58f..a35d242ca3 100644 --- a/server/services/nl.py +++ b/server/services/nl.py @@ -294,6 +294,10 @@ def _containedin_classification(self, prediction, PLACE_TYPE_TO_PLURALS[place_type] in query: 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( From 90bee644dbb769d86fe8529eeef3a338ff7692fe Mon Sep 17 00:00:00 2001 From: Jehangir Amjad Date: Mon, 9 Jan 2023 21:20:57 -0800 Subject: [PATCH 4/5] lint fixes --- server/routes/nl_interface.py | 7 +++++-- server/services/nl.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/routes/nl_interface.py b/server/routes/nl_interface.py index ef5b32fd0e..03409477b2 100644 --- a/server/routes/nl_interface.py +++ b/server/routes/nl_interface.py @@ -508,8 +508,11 @@ def _detection(orig_query, cleaned_query, embeddings_build) -> Detection: # 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 & - (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.") + (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" diff --git a/server/services/nl.py b/server/services/nl.py index a35d242ca3..caffee4cb2 100644 --- a/server/services/nl.py +++ b/server/services/nl.py @@ -294,7 +294,7 @@ def _containedin_classification(self, prediction, PLACE_TYPE_TO_PLURALS[place_type] in query: 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 From 824715070ba1470c7949bd694a9b6ab189d5bdd8 Mon Sep 17 00:00:00 2001 From: Jehangir Amjad Date: Mon, 9 Jan 2023 21:27:37 -0800 Subject: [PATCH 5/5] minor fix --- server/routes/nl_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/routes/nl_interface.py b/server/routes/nl_interface.py index 03409477b2..141d6e04bb 100644 --- a/server/routes/nl_interface.py +++ b/server/routes/nl_interface.py @@ -507,7 +507,7 @@ def _detection(orig_query, cleaned_query, embeddings_build) -> Detection: # 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 & + if (place_detection.using_default_place and (contained_in_classification.attributes.contained_in_place_type == ContainedInPlaceType.COUNTRY)): logging.info(