Spaces:
Running
Running
AzizHamad
commited on
Commit
·
7eba1aa
1
Parent(s):
fc2f2b4
Add SQL-BLEU metric
Browse files- README.md +12 -5
- requirements.txt +3 -0
- text2sql-sql-bleu.py +34 -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-sql-bleu
|
| 3 |
+
emoji: "📏"
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
Hugging Face Evaluate metric for **SQL BLEU** (token BLEU in [0,1]).
|
| 11 |
+
|
| 12 |
+
Usage:
|
| 13 |
+
|
| 14 |
+
```python
|
| 15 |
+
import evaluate
|
| 16 |
+
m = evaluate.load("3zizo3/text2sql-sql-bleu")
|
| 17 |
+
print(m.compute(predictions=["select 1"], references=["select 2"]))
|
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-sql-bleu.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import evaluate
|
| 2 |
+
import datasets
|
| 3 |
+
|
| 4 |
+
from text2sql_eval.metrics.bleu import bleu_score
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_DESCRIPTION = "SQL token BLEU (0–1). Returns mean score in [0, 1]."
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _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 |
+
|
| 16 |
+
class SQLBLEU(evaluate.Metric):
|
| 17 |
+
def _info(self):
|
| 18 |
+
return evaluate.MetricInfo(
|
| 19 |
+
description=_DESCRIPTION,
|
| 20 |
+
citation="Uses sacrebleu via text2sql-eval implementation.",
|
| 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(bleu_score(_to_str(p), _to_str(r))))
|
| 33 |
+
mean = sum(scores) / len(scores) if scores else 0.0
|
| 34 |
+
return {"sql_bleu": mean}
|