AzizHamad commited on
Commit
4f311be
·
1 Parent(s): 0f65876

Add TSED metric code + requirements

Browse files
Files changed (3) hide show
  1. README.md +8 -8
  2. requirements.txt +3 -0
  3. tsed.py +34 -0
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
- title: Text2sql Tsed
3
- emoji: 👀
4
- colorFrom: indigo
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 6.5.1
8
- app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
  ---
2
+ title: text2sql-tsed
3
+ emoji: 🧪
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: python
7
+ app_file: tsed.py
 
8
  pinned: false
9
  ---
10
 
11
+ Hugging Face Evaluate metric wrapper for **TSED** (SQL).
12
+ Compute via `evaluate.load("3zizo3/text2sql-tsed")`.
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
tsed.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import evaluate
2
+ import datasets
3
+
4
+ from text2sql_eval.metrics.tsed_wrapper import tsed_score
5
+
6
+
7
+ _DESCRIPTION = "TSED (Tree Similarity of Edit Distance) for SQL/code strings. 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 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.0
34
+ return {"tsed": mean}