Skip to content

Commit

Permalink
Truncate golden CosineScores to 6 decimals to reduce noisy diffs. (#4718
Browse files Browse the repository at this point in the history
)

Reduces CosineScores to 6 decimals to reduce the diffs that are
generated when updating the integration_test goldens.

This is to reduce noise in reviews and should not fundamentally affect
the actual tests.
  • Loading branch information
clincoln8 authored Nov 7, 2024
1 parent ddd3e22 commit 9d1d4e0
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 326 deletions.
19 changes: 17 additions & 2 deletions server/integration_tests/explore_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,23 @@ def handle_response(self,
# TODO: Proper fix should be to make NL server more deterministic
if 'variables' in resp:
resp_var_to_score = {}
dbg['sv_matching']['CosineScore'] = _format_scores(
dbg['sv_matching']['CosineScore'])
for i, sv in enumerate(dbg['sv_matching']['SV']):
score = dbg['sv_matching']['CosineScore'][i]
resp_var_to_score[sv] = float("{:.6f}".format(score))
resp_var_to_score[sv] = dbg['sv_matching']['CosineScore'][i]
sorted_variables = sorted(resp['variables'],
key=lambda x: (-resp_var_to_score.get(x, 0), x))
resp['variables'] = sorted_variables

# Truncate CosineScores to 6 decimals to reduce noisy diffs.
for candidate in dbg['sv_matching']['MultiSV'].get('Candidates', []):
for part in candidate.get('Parts', []):
if multisv_scores := part.get('CosineScore', []):
part['CosineScore'] = _format_scores(multisv_scores)

if props_scores := dbg['props_matching'].get('CosineScore', []):
dbg['props_matching']['CosineScore'] = _format_scores(props_scores)

resp['debug'] = {}
resp['context'] = {}
for category in resp.get('config', {}).get('categories', []):
Expand Down Expand Up @@ -793,3 +803,8 @@ def _del_field(d: dict, path: str):
del tmp[p]
else:
tmp = tmp[p]


# Helper function to consistently format float scores.
def _format_scores(scores):
return [float("{:.6f}".format(score)) for score in scores]
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@
"query_with_places_removed": "what is the phylum of",
"sv_matching": {
"CosineScore": [
0.35510897636413574,
0.3460870683193207,
0.3452577292919159,
0.34484589099884033,
0.3411366045475006,
0.3384982645511627,
0.3349902629852295,
0.3316609263420105,
0.32600605487823486,
0.3242444694042206,
0.32060620188713074,
0.31426557898521423,
0.3127654492855072,
0.3126293420791626,
0.31250452995300293,
0.31177404522895813,
0.3103388845920563,
0.3100748658180237,
0.3098835051059723,
0.3080541491508484,
0.3074587285518646,
0.3071962296962738,
0.30394214391708374
0.355109,
0.346087,
0.345258,
0.344846,
0.341137,
0.338498,
0.33499,
0.331661,
0.326006,
0.324244,
0.320606,
0.314266,
0.312765,
0.312629,
0.312505,
0.311774,
0.310339,
0.310075,
0.309883,
0.308054,
0.307459,
0.307196,
0.303942
],
"MultiSV": {},
"Query": "what is the phylum of",
Expand Down Expand Up @@ -64,35 +64,35 @@
},
"props_matching": {
"CosineScore": [
1.0000001192092896,
0.47528401017189026,
0.3615417182445526,
0.34543079137802124,
0.34543079137802124,
0.3420097231864929,
0.3293308615684509,
0.318451464176178,
0.31466978788375854,
0.308395117521286,
0.30794060230255127,
0.3046301007270813,
0.2827085852622986,
0.281875342130661,
0.28082770109176636,
0.2804528772830963,
0.2742983400821686,
0.2715050280094147,
0.27071818709373474,
0.2695467472076416,
0.25990068912506104,
0.25990068912506104,
0.24827904999256134,
0.24662022292613983,
0.24632100760936737,
0.2461635172367096,
0.24212227761745453,
0.23135530948638916,
0.2296244353055954
1.0,
0.475284,
0.361542,
0.345431,
0.345431,
0.34201,
0.329331,
0.318452,
0.31467,
0.308395,
0.307941,
0.30463,
0.282709,
0.281875,
0.280828,
0.280453,
0.274298,
0.271505,
0.270718,
0.269547,
0.259901,
0.259901,
0.248279,
0.24662,
0.246321,
0.246163,
0.242122,
0.231355,
0.229624
],
"PROP": [
"phylum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@
"query_with_places_removed": "what types of genes are and",
"sv_matching": {
"CosineScore": [
0.5237791538238525,
0.4451894760131836,
0.4198145866394043,
0.41922125220298767,
0.41366666555404663,
0.4096527099609375,
0.4066110849380493,
0.4013715386390686,
0.4010191559791565,
0.40063756704330444,
0.39874646067619324,
0.39836058020591736,
0.39052361249923706,
0.38903331756591797,
0.3884609639644623,
0.3883824050426483,
0.3873301148414612,
0.38642188906669617,
0.3858962655067444,
0.3856789469718933,
0.3854343295097351,
0.38533878326416016,
0.38184264302253723,
0.37970495223999023
0.523779,
0.445189,
0.419815,
0.419221,
0.413667,
0.409652,
0.406611,
0.401371,
0.401019,
0.400638,
0.398746,
0.398361,
0.390524,
0.389033,
0.388461,
0.388382,
0.38733,
0.386422,
0.385896,
0.385679,
0.385434,
0.385339,
0.381843,
0.379705
],
"MultiSV": {},
"Query": "what types of genes are and",
Expand Down Expand Up @@ -68,32 +68,32 @@
},
"props_matching": {
"CosineScore": [
0.9086110591888428,
0.7445294260978699,
0.7330226898193359,
0.7175887823104858,
0.6834690570831299,
0.6590196490287781,
0.6357895731925964,
0.6340402364730835,
0.6171568036079407,
0.5988123416900635,
0.5958784818649292,
0.5850145220756531,
0.5832706689834595,
0.5810792446136475,
0.576904296875,
0.5432419776916504,
0.5399729013442993,
0.5320467948913574,
0.5309585332870483,
0.5142703056335449,
0.5125279426574707,
0.46105992794036865,
0.4441080689430237,
0.39822953939437866,
0.3944427967071533,
0.39229002594947815
0.908611,
0.744529,
0.733023,
0.717589,
0.683469,
0.65902,
0.63579,
0.63404,
0.617157,
0.598812,
0.595879,
0.585015,
0.583271,
0.581079,
0.576904,
0.543242,
0.539973,
0.532047,
0.530959,
0.51427,
0.512528,
0.46106,
0.444108,
0.398229,
0.394443,
0.39229
],
"PROP": [
"typeOfGene",
Expand Down
Loading

0 comments on commit 9d1d4e0

Please sign in to comment.