Skip to content

Commit

Permalink
[feat] Sort SQL result tuples for fair comparison during evaluation A…
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaordronneau committed Aug 19, 2024
1 parent ac71094 commit bcbfb0c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bird/llm/src/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def load_json(dir):
def result_callback(result):
exec_result.append(result)

def sort_tuple(t):
return tuple(sorted(t, key=lambda x: str(x)))

def execute_sql(predicted_sql,ground_truth, db_path):
conn = sqlite3.connect(db_path)
Expand All @@ -22,6 +24,11 @@ def execute_sql(predicted_sql,ground_truth, db_path):
predicted_res = cursor.fetchall()
cursor.execute(ground_truth)
ground_truth_res = cursor.fetchall()

# sort the results to allow fair comparison
predicted_res = [sort_tuple(t) for t in predicted_res]
ground_truth_res = [sort_tuple(t) for t in ground_truth_res]

res = 0
if set(predicted_res) == set(ground_truth_res):
res = 1
Expand Down

0 comments on commit bcbfb0c

Please sign in to comment.