Skip to content

Commit

Permalink
[NL] Implement query-type fallback (#2225)
Browse files Browse the repository at this point in the history
In fulfillment, loop over a sequence of query_types until we are able to
produce some charts.

The two key functions are:
* `first_query_type`: Given a bunch of classification results in an
utterance, we pick the first query_type to process
* `next_query_type`: Given a list of past query_types we tried to
fulfill and failed, we pick the next query_type to process

Given fallbacks at query_type level, drop per-fulfillment-type
fallbacks.

Also, separate out the ClassificationType from a new QueryType, since
the latter may be more fine-grained.
  • Loading branch information
pradh authored Feb 11, 2023
1 parent 66e7772 commit 456151e
Show file tree
Hide file tree
Showing 34 changed files with 3,997 additions and 219 deletions.
11 changes: 11 additions & 0 deletions server/integration_tests/nlnext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,14 @@ def test_demo_feb2023(self):
'Which counties in the USA have the highest levels of blood pressure',
'How does this correlate with income',
])

def test_demo_fallback(self):
self.run_sequence(
'demo_fallback',
[
# We have no stats on this, so we should return Palo Alto overview.
'Number of Shakespeare fans in Palo Alto',
# We have no crime at county-level in CA, so we should fall back as:
# RANKING_ACROSS_PLACES -> CONTAINED_IN -> SIMPLE
'counties in California with highest crime',
])
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"config": {
"categories": [
{
"blocks": [
{
"columns": [
{
"tiles": [
{
"type": "PLACE_OVERVIEW"
}
]
}
],
"title": "Palo Alto"
}
]
}
],
"metadata": {
"placeDcid": [
"geoId/0655282"
]
}
},
"context": {},
"debug": {},
"place": {
"dcid": "geoId/0655282",
"name": "Palo Alto",
"place_type": "City"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"clustering_classification": "<None>",
"comparison_classification": "<None>",
"contained_in_classification": "<None>",
"correlation_classification": "<None>",
"counters": {
"failed_populate_main_place": [
"geoId/0655282"
],
"filtered_svs": [],
"num_chart_candidates": 1,
"num_populate_fallbacks": 1,
"processed_fulfillment_types": [
"simple",
"overview"
]
},
"data_spec": [
{
"classifications": [
{
"type": 11
}
],
"places": [
{
"dcid": "geoId/0655282",
"name": "Palo Alto",
"place_type": "City"
}
],
"query": "Number of Shakespeare fans in Palo Alto",
"query_type": 9,
"ranked_charts": [
{
"attr": {
"block_id": 1,
"chart_type": "",
"class": 0,
"description": "",
"include_percapita": false,
"place_type": null,
"ranking_types": [],
"source_topic": "",
"title": ""
},
"chart_type": 4,
"event": null,
"places": [
{
"dcid": "geoId/0655282",
"name": "Palo Alto",
"place_type": "City"
}
],
"svs": []
}
],
"svs": []
}
],
"event_classification": "<None>",
"main_place_dcid": "geoId/0655282",
"main_place_name": "Palo Alto",
"original_query": "Number of Shakespeare fans in Palo Alto",
"overview_classification": "<None>",
"places_detected": [
"palo alto"
],
"query_with_places_removed": "number of shakespeare fans",
"ranking_classification": "<None>",
"status": "",
"sv_matching": {
"CosineScore": [
0.3691325783729553,
0.29036542773246765,
0.2894546687602997,
0.2783313989639282,
0.272920161485672,
0.2691501975059509,
0.2653329074382782,
0.26523518562316895,
0.2610829472541809,
0.2539288103580475
],
"SV": [
"Count_HeavySnowEvent",
"Count_Person_Male",
"Count_CriminalIncidents_IsHateCrime",
"Count_EarthquakeEvent",
"Count_Person_5To9Years",
"Count_CriminalActivities_Robbery",
"Count_HeavyRainEvent",
"Count_Worker_NAICSArtsEntertainmentRecreation",
"Count_DroughtEvent",
"Count_FloodEvent"
],
"SV_to_Sentences": {
"Count_CriminalActivities_Robbery": [
"Number of heists (0.2691501975059509)"
],
"Count_CriminalIncidents_IsHateCrime": [
"Number of hate crimes (0.2894546687602997)",
"Number of Hate Crime Incidents (0.25507885217666626)",
"Number of hate crime incidents (0.25507885217666626)"
],
"Count_DroughtEvent": [
"Number of Droughts (0.2610829472541809)",
"Number of droughts (0.2610829174518585)"
],
"Count_EarthquakeEvent": [
"Number of tremors (0.2783313989639282)",
"Number of temblors (0.27476659417152405)",
"Number of quakes (0.27175652980804443)",
"Number of Earthquakes (0.25374898314476013)"
],
"Count_FloodEvent": [
"Number of Floods (0.2539288103580475)",
"Number of floods (0.2539288103580475)"
],
"Count_HeavyRainEvent": [
"Number of heavy rains (0.2653329074382782)",
"Number of Heavy Rains (0.2653329074382782)"
],
"Count_HeavySnowEvent": [
"Number of blizzards (0.3691325783729553)"
],
"Count_Person_5To9Years": [
"Number of 5 to 9 year old people (0.272920161485672)"
],
"Count_Person_Male": [
"Number of Males (0.29036542773246765)"
],
"Count_Worker_NAICSArtsEntertainmentRecreation": [
"Employment numbers in entertainment and recreation (0.26523518562316895)",
"number of arts, entertainment, and recreation workers (0.25554004311561584)",
"Population of Person: Arts, Entertainment, And Recreation (NAICS/71) (0.25426241755485535)"
]
}
},
"svs_to_sentences": {
"Count_CriminalActivities_Robbery": [
"Number of heists (0.2691501975059509)"
],
"Count_CriminalIncidents_IsHateCrime": [
"Number of hate crimes (0.2894546687602997)",
"Number of Hate Crime Incidents (0.25507885217666626)",
"Number of hate crime incidents (0.25507885217666626)"
],
"Count_DroughtEvent": [
"Number of Droughts (0.2610829472541809)",
"Number of droughts (0.2610829174518585)"
],
"Count_EarthquakeEvent": [
"Number of tremors (0.2783313989639282)",
"Number of temblors (0.27476659417152405)",
"Number of quakes (0.27175652980804443)",
"Number of Earthquakes (0.25374898314476013)"
],
"Count_FloodEvent": [
"Number of Floods (0.2539288103580475)",
"Number of floods (0.2539288103580475)"
],
"Count_HeavyRainEvent": [
"Number of heavy rains (0.2653329074382782)",
"Number of Heavy Rains (0.2653329074382782)"
],
"Count_HeavySnowEvent": [
"Number of blizzards (0.3691325783729553)"
],
"Count_Person_5To9Years": [
"Number of 5 to 9 year old people (0.272920161485672)"
],
"Count_Person_Male": [
"Number of Males (0.29036542773246765)"
],
"Count_Worker_NAICSArtsEntertainmentRecreation": [
"Employment numbers in entertainment and recreation (0.26523518562316895)",
"number of arts, entertainment, and recreation workers (0.25554004311561584)",
"Population of Person: Arts, Entertainment, And Recreation (NAICS/71) (0.25426241755485535)"
]
},
"temporal_classification": "<None>",
"time_delta_classification": "<None>"
}
Loading

0 comments on commit 456151e

Please sign in to comment.