Spaces:
Running
Running
AzizHamad
commited on
Commit
·
b4e76f9
1
Parent(s):
ba0b805
Add SQAM metric
Browse files- README.md +12 -5
- requirements.txt +3 -0
- text2sql-sqam.py +35 -0
README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: text2sql-sqam
|
| 3 |
+
emoji: "🧩"
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
Hugging Face Evaluate metric for **SQAM** (SQL Structural Query Alignment).
|
| 11 |
+
|
| 12 |
+
Usage:
|
| 13 |
+
|
| 14 |
+
```python
|
| 15 |
+
import evaluate
|
| 16 |
+
m = evaluate.load("3zizo3/text2sql-sqam")
|
| 17 |
+
print(m.compute(predictions=["select 1"], references=["select 1"]))
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
evaluate>=0.4.6
|
| 2 |
+
datasets>=2.0.0
|
| 3 |
+
git+https://github.com/AzizHamad03/text2sql-eval.git
|
text2sql-sqam.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import evaluate
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
from text2sql_eval.metrics.sqam_wrapper import sqam_score
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_DESCRIPTION = "SQAM (Structural Query Alignment Metric) for SQL. Returns mean score in [0, 1]."
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _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 |
+
|
| 17 |
+
class 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.0
|
| 35 |
+
return {"sqam": mean}
|