SoftALL/text2sql-tsed
0
1import evaluate2import datasets3 4from text2sql_eval.metrics.tsed_wrapper import tsed_score5 6 7_DESCRIPTION = "TSED (Tree Similarity of Edit Distance) for SQL/code strings. Returns mean score in [0, 1]."8 9 10def _to_str(x):11 if isinstance(x, (list, tuple)):12 return x[0] if x else ""13 return "" if x is None else str(x)14 15 16class TSED(evaluate.Metric):17 def _info(self):18 return evaluate.MetricInfo(19 description=_DESCRIPTION,20 citation="TSED: https://github.com/Etamin/TSED",21 features=datasets.Features(22 {23 "predictions": datasets.Value("string"),24 "references": datasets.Value("string"),25 }26 ),27 )28 29 def _compute(self, predictions, references):30 scores = []31 for p, r in zip(predictions, references):32 scores.append(float(tsed_score(_to_str(p), _to_str(r))))33 mean = sum(scores) / len(scores) if scores else 0.034 return {"tsed": mean}35 