CoolFace
Apppublic

SoftALL/text2sql-sqam

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
text2sql-sqam.py36 linesDownload Raw Back to root
1import evaluate2import datasets3 4from text2sql_eval.metrics.sqam_wrapper import sqam_score5 6 7_DESCRIPTION = "SQAM (Structural Query Alignment Metric) for SQL. Returns mean score in [0, 1]."8 9 10def _to_str(x):11    # Evaluate sometimes passes references as list-of-lists; we accept both.12    if isinstance(x, (list, tuple)):13        return x[0] if x else ""14    return "" if x is None else str(x)15 16 17class SQAM(evaluate.Metric):18    def _info(self):19        return evaluate.MetricInfo(20            description=_DESCRIPTION,21            citation="SQAM: https://github.com/ezzini/SQAM",22            features=datasets.Features(23                {24                    "predictions": datasets.Value("string"),25                    "references": datasets.Value("string"),26                }27            ),28        )29 30    def _compute(self, predictions, references):31        scores = []32        for p, r in zip(predictions, references):33            scores.append(float(sqam_score(_to_str(p), _to_str(r))))34        mean = sum(scores) / len(scores) if scores else 0.035        return {"sqam": mean}36