From 9c8a0f7e134de01e281d24874d5be98179fb8451 Mon Sep 17 00:00:00 2001 From: Bo Xu Date: Thu, 16 May 2024 21:52:32 -0700 Subject: [PATCH] fix sort issue?? --- nl_server/search.py | 5 ++- server/integration_tests/explore_test.py | 1 - .../debug_info.json | 8 ++-- .../compareobesityvs.poverty/debug_info.json | 4 +- .../debug_info.json | 4 +- .../debug_info.json | 42 +++++++++---------- .../debug_info.json | 10 ++--- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/nl_server/search.py b/nl_server/search.py index febddfde76..76adfb6588 100644 --- a/nl_server/search.py +++ b/nl_server/search.py @@ -91,8 +91,9 @@ def _rank_vars(candidates: EmbeddingsResult, # TODO: truncate the score based on model parameters from yaml # Same model would produce different scores after certain decimals, so we want # to round to 6 decimal places to make the score and rank stable. - for sv, score in sorted(sv2score.items(), - key=lambda item: (-int(item[1] * 1e6), item[0])): + sorted_score = sorted(sv2score.items(), + key=lambda item: (-round(item[1], 6), item[0])) + for sv, score in sorted_score: result.svs.append(sv) result.scores.append(score) diff --git a/server/integration_tests/explore_test.py b/server/integration_tests/explore_test.py index 5aae671c81..77aa585f3f 100644 --- a/server/integration_tests/explore_test.py +++ b/server/integration_tests/explore_test.py @@ -63,7 +63,6 @@ def run_detection(self, d = '' else: d = re.sub(r'[ ?"]', '', q).lower() - print(d) self.handle_response(q, resp, test_dir, d, failure, check_detection) def run_detect_and_fulfill(self, diff --git a/server/integration_tests/test_data/detection_api_multivar/comparemalepopulationwithfemalepopulation/debug_info.json b/server/integration_tests/test_data/detection_api_multivar/comparemalepopulationwithfemalepopulation/debug_info.json index d143eb83c0..71605661ae 100644 --- a/server/integration_tests/test_data/detection_api_multivar/comparemalepopulationwithfemalepopulation/debug_info.json +++ b/server/integration_tests/test_data/detection_api_multivar/comparemalepopulationwithfemalepopulation/debug_info.json @@ -54,7 +54,7 @@ "Parts": [ { "CosineScore": [ - 0.925786018371582 + 0.9257855415344238 ], "QueryPart": "male population", "SV": [ @@ -89,8 +89,8 @@ }, { "CosineScore": [ - 0.8874198794364929, - 0.872346818447113 + 0.8874201774597168, + 0.8723466396331787 ], "QueryPart": "population", "SV": [ @@ -123,7 +123,7 @@ }, { "CosineScore": [ - 0.9170327186584473 + 0.917032778263092 ], "QueryPart": "population female population", "SV": [ diff --git a/server/integration_tests/test_data/detection_api_multivar/compareobesityvs.poverty/debug_info.json b/server/integration_tests/test_data/detection_api_multivar/compareobesityvs.poverty/debug_info.json index 35aa9ce57a..77d741517a 100644 --- a/server/integration_tests/test_data/detection_api_multivar/compareobesityvs.poverty/debug_info.json +++ b/server/integration_tests/test_data/detection_api_multivar/compareobesityvs.poverty/debug_info.json @@ -26,8 +26,8 @@ 0.7139475345611572, 0.7126951217651367, 0.7112098932266235, - 0.7085551023483276, 0.7085550427436829, + 0.7085551023483276, 0.7080719470977783, 0.7078822255134583, 0.7053750157356262, @@ -89,8 +89,8 @@ "dc/topic/sdg_1", "Count_Household_FamilyHousehold_BelowPovertyLevelInThePast12Months", "dc/4lvmzr1h1ylk1", - "dc/topic/sdg_2.1.2", "dc/topic/FoodInsecurity", + "dc/topic/sdg_2.1.2", "WHO/NCD_BMI_18A", "Count_Household_WithoutFoodStampsInThePast12Months_AbovePovertyLevelInThePast12Months", "WHO/NUTOVERWEIGHTPREV", diff --git a/server/integration_tests/test_data/detection_api_multivar/howarefactorslikeobesity,bloodpressureandasthmaimpactedbyclimatechange/debug_info.json b/server/integration_tests/test_data/detection_api_multivar/howarefactorslikeobesity,bloodpressureandasthmaimpactedbyclimatechange/debug_info.json index 63c69e2ad5..52d847fb77 100644 --- a/server/integration_tests/test_data/detection_api_multivar/howarefactorslikeobesity,bloodpressureandasthmaimpactedbyclimatechange/debug_info.json +++ b/server/integration_tests/test_data/detection_api_multivar/howarefactorslikeobesity,bloodpressureandasthmaimpactedbyclimatechange/debug_info.json @@ -85,7 +85,7 @@ "Parts": [ { "CosineScore": [ - 0.7976328730583191, + 0.7976329326629639, 0.7576606273651123 ], "QueryPart": "factors like obesity", @@ -96,7 +96,7 @@ }, { "CosineScore": [ - 0.9999996423721313 + 0.9999995827674866 ], "QueryPart": "blood pressure", "SV": [ diff --git a/server/integration_tests/test_data/detection_api_multivar/numberofpoorhispanicwomenwithphd/debug_info.json b/server/integration_tests/test_data/detection_api_multivar/numberofpoorhispanicwomenwithphd/debug_info.json index 560d14312a..88e50545fd 100644 --- a/server/integration_tests/test_data/detection_api_multivar/numberofpoorhispanicwomenwithphd/debug_info.json +++ b/server/integration_tests/test_data/detection_api_multivar/numberofpoorhispanicwomenwithphd/debug_info.json @@ -57,15 +57,15 @@ "Parts": [ { "CosineScore": [ - 0.8084912300109863, - 0.8080331683158875, - 0.8044112324714661, - 0.7984198331832886, - 0.7966947555541992, - 0.791584849357605, - 0.7901858687400818, - 0.7865886092185974, - 0.7773175239562988, + 0.8084911108016968, + 0.8080331087112427, + 0.8044111728668213, + 0.7984197735786438, + 0.7966943979263306, + 0.7915846705436707, + 0.790185809135437, + 0.7865886688232422, + 0.777317464351654, 0.776214063167572, 0.7629760503768921 ], @@ -86,8 +86,8 @@ }, { "CosineScore": [ - 0.8318259119987488, - 0.8029922842979431 + 0.8318256735801697, + 0.8029924631118774 ], "QueryPart": "women phd", "SV": [ @@ -104,7 +104,7 @@ { "CosineScore": [ 0.8433718681335449, - 0.8265039920806885 + 0.8265039324760437 ], "QueryPart": "number poor hispanic women", "SV": [ @@ -114,11 +114,11 @@ }, { "CosineScore": [ - 0.7646969556808472, - 0.7476687431335449, - 0.73770672082901, - 0.7362766861915588, - 0.7305881977081299 + 0.7646968960762024, + 0.7476688027381897, + 0.7377066612243652, + 0.7362767457962036, + 0.7305883169174194 ], "QueryPart": "phd", "SV": [ @@ -146,10 +146,10 @@ }, { "CosineScore": [ - 0.8151504993438721, - 0.7885995507240295, - 0.7775553464889526, - 0.7752051949501038 + 0.8151503801345825, + 0.7885993719100952, + 0.7775554060935974, + 0.7752052545547485 ], "QueryPart": "hispanic women phd", "SV": [ diff --git a/server/integration_tests/test_data/detection_api_multivar/showmetheimpactofclimatechangeondrought/debug_info.json b/server/integration_tests/test_data/detection_api_multivar/showmetheimpactofclimatechangeondrought/debug_info.json index 60ead22615..a92bf6e5a3 100644 --- a/server/integration_tests/test_data/detection_api_multivar/showmetheimpactofclimatechangeondrought/debug_info.json +++ b/server/integration_tests/test_data/detection_api_multivar/showmetheimpactofclimatechangeondrought/debug_info.json @@ -41,7 +41,7 @@ "Parts": [ { "CosineScore": [ - 0.8787485361099243 + 0.8787486553192139 ], "QueryPart": "show climate change", "SV": [ @@ -50,7 +50,7 @@ }, { "CosineScore": [ - 0.9999998807907104 + 1.0 ], "QueryPart": "drought", "SV": [ @@ -65,10 +65,10 @@ "Parts": [ { "CosineScore": [ - 0.7942370176315308, + 0.794236958026886, 0.7929013967514038, 0.7586168050765991, - 0.7583959102630615 + 0.758395791053772 ], "QueryPart": "show climate", "SV": [ @@ -80,7 +80,7 @@ }, { "CosineScore": [ - 0.8665127158164978 + 0.866512656211853 ], "QueryPart": "change drought", "SV": [