Fritz02 commited on
Commit
59d1cc2
1 Parent(s): e7ef9c1

Add new etric for calculating execution accuracy for text-to-sql llms.

Browse files
Files changed (1) hide show
  1. execution_accuracy.py +35 -7
execution_accuracy.py CHANGED
@@ -17,18 +17,24 @@ import evaluate
17
  import datasets
18
 
19
 
 
20
  # TODO: Add BibTeX citation
21
  _CITATION = """\
22
- @InProceedings{huggingface:module,
23
- title = {A great new module},
24
- authors={huggingface, Inc.},
25
- year={2020}
 
 
 
26
  }
27
  """
28
 
29
  # TODO: Add description of the module here
30
  _DESCRIPTION = """\
31
- This new module is designed to solve this great ML task and is crafted with a lot of care.
 
 
32
  """
33
 
34
 
@@ -86,10 +92,32 @@ class ExecutionAccuracy(evaluate.Metric):
86
  # TODO: Download external resources if needed
87
  pass
88
 
89
- def _compute(self, predictions, references):
90
  """Returns the scores"""
91
  # TODO: Compute the different scores of the module
92
- accuracy = sum(i == j for i, j in zip(predictions, references)) / len(predictions)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  return {
94
  "accuracy": accuracy,
95
  }
 
17
  import datasets
18
 
19
 
20
+
21
  # TODO: Add BibTeX citation
22
  _CITATION = """\
23
+ @misc{li2023llm,
24
+ title={Can LLM Already Serve as A Database Interface? A BIg Bench for Large-Scale Database Grounded Text-to-SQLs},
25
+ author={Jinyang Li and Binyuan Hui and Ge Qu and Jiaxi Yang and Binhua Li and Bowen Li and Bailin Wang and Bowen Qin and Rongyu Cao and Ruiying Geng and Nan Huo and Xuanhe Zhou and Chenhao Ma and Guoliang Li and Kevin C. C. Chang and Fei Huang and Reynold Cheng and Yongbin Li},
26
+ year={2023},
27
+ eprint={2305.03111},
28
+ archivePrefix={arXiv},
29
+ primaryClass={cs.CL}
30
  }
31
  """
32
 
33
  # TODO: Add description of the module here
34
  _DESCRIPTION = """\
35
+ This new module is designed to calculate the EX, which is defined as the proportion of examples in the evaluation set for
36
+ which the executed results of both the predicted and ground-truth SQLs are identical, relative to the
37
+ overall number of SQLs.
38
  """
39
 
40
 
 
92
  # TODO: Download external resources if needed
93
  pass
94
 
95
+ def _compute(self, predictions, references, execute_func, filter_func=None):
96
  """Returns the scores"""
97
  # TODO: Compute the different scores of the module
98
+
99
+ if len(predictions) != len(references):
100
+ raise ValueError("Predictions and references must have the same number of elements.")
101
+
102
+ # Run filter_func on predictions and references if needed
103
+ filtered_predictions = []
104
+ filtered_references = []
105
+ divider = 0
106
+ if filter_func is not None:
107
+ for prediction, reference in zip(predictions, references):
108
+ # Only keep if both prediction and reference pass the filter
109
+ pred_bool = filter_func(prediction)
110
+ ref_bool = filter_func(reference)
111
+ if pred_bool and ref_bool:
112
+ filtered_predictions.append(prediction)
113
+ filtered_references.append(reference)
114
+ divider += 1
115
+ # If only the reference passes the filter, count it
116
+ elif pred_bool != ref_bool:
117
+ divider += 1
118
+
119
+ accuracy = sum(execute_func(i) == execute_func(j) for i, j in zip(filtered_predictions, filtered_references)) / divider
120
+
121
  return {
122
  "accuracy": accuracy,
123
  }