Spaces:
Runtime error
Runtime error
update format
Browse files- app.py +6 -0
- nl2bash_metric.py +22 -21
app.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import evaluate
|
2 |
+
from evaluate.utils import launch_gradio_widget
|
3 |
+
|
4 |
+
|
5 |
+
module = evaluate.load("nl2bash_metric")
|
6 |
+
launch_gradio_widget(module)
|
nl2bash_metric.py
CHANGED
@@ -15,9 +15,10 @@
|
|
15 |
import re
|
16 |
import string
|
17 |
|
|
|
18 |
import numpy as np
|
19 |
|
20 |
-
import
|
21 |
|
22 |
|
23 |
_DESCRIPTION = """
|
@@ -39,48 +40,48 @@ Args:
|
|
39 |
ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
|
40 |
comparing predictions and references.
|
41 |
Returns:
|
42 |
-
exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and
|
43 |
Examples:
|
44 |
-
>>> exact_match =
|
45 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
46 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
47 |
>>> results = exact_match.compute(references=refs, predictions=preds)
|
48 |
-
>>> print(round(results["exact_match"],
|
49 |
-
25
|
50 |
-
>>> exact_match =
|
51 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
52 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
53 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)
|
54 |
-
>>> print(round(results["exact_match"],
|
55 |
-
|
56 |
-
>>> exact_match =
|
57 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
58 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
59 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)
|
60 |
-
>>> print(round(results["exact_match"],
|
61 |
-
75
|
62 |
-
>>> exact_match =
|
63 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
64 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
65 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
|
66 |
-
>>> print(round(results["exact_match"],
|
67 |
-
|
68 |
-
>>> exact_match =
|
69 |
>>> refs = ["The cat sat on the mat.", "Theaters are great.", "It's like comparing oranges and apples."]
|
70 |
>>> preds = ["The cat sat on the mat?", "Theaters are great.", "It's like comparing apples and oranges."]
|
71 |
>>> results = exact_match.compute(references=refs, predictions=preds)
|
72 |
-
>>> print(round(results["exact_match"],
|
73 |
-
33
|
74 |
"""
|
75 |
|
76 |
_CITATION = """
|
77 |
"""
|
78 |
|
79 |
|
80 |
-
@
|
81 |
-
class nl2bash_metric(
|
82 |
def _info(self):
|
83 |
-
return
|
84 |
description=_DESCRIPTION,
|
85 |
citation=_CITATION,
|
86 |
inputs_description=_KWARGS_DESCRIPTION,
|
@@ -127,4 +128,4 @@ class nl2bash_metric(datasets.Metric):
|
|
127 |
|
128 |
score_list = predictions == references
|
129 |
|
130 |
-
return {"exact_match": np.mean(score_list)
|
|
|
15 |
import re
|
16 |
import string
|
17 |
|
18 |
+
import datasets
|
19 |
import numpy as np
|
20 |
|
21 |
+
import evaluate
|
22 |
|
23 |
|
24 |
_DESCRIPTION = """
|
|
|
40 |
ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before
|
41 |
comparing predictions and references.
|
42 |
Returns:
|
43 |
+
exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 1.0, inclusive.
|
44 |
Examples:
|
45 |
+
>>> exact_match = evaluate.load("exact_match")
|
46 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
47 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
48 |
>>> results = exact_match.compute(references=refs, predictions=preds)
|
49 |
+
>>> print(round(results["exact_match"], 2))
|
50 |
+
0.25
|
51 |
+
>>> exact_match = evaluate.load("exact_match")
|
52 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
53 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
54 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)
|
55 |
+
>>> print(round(results["exact_match"], 2))
|
56 |
+
0.5
|
57 |
+
>>> exact_match = evaluate.load("exact_match")
|
58 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
59 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
60 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)
|
61 |
+
>>> print(round(results["exact_match"], 2))
|
62 |
+
0.75
|
63 |
+
>>> exact_match = evaluate.load("exact_match")
|
64 |
>>> refs = ["the cat", "theater", "YELLING", "agent007"]
|
65 |
>>> preds = ["cat?", "theater", "yelling", "agent"]
|
66 |
>>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)
|
67 |
+
>>> print(round(results["exact_match"], 2))
|
68 |
+
1.0
|
69 |
+
>>> exact_match = evaluate.load("exact_match")
|
70 |
>>> refs = ["The cat sat on the mat.", "Theaters are great.", "It's like comparing oranges and apples."]
|
71 |
>>> preds = ["The cat sat on the mat?", "Theaters are great.", "It's like comparing apples and oranges."]
|
72 |
>>> results = exact_match.compute(references=refs, predictions=preds)
|
73 |
+
>>> print(round(results["exact_match"], 2))
|
74 |
+
0.33
|
75 |
"""
|
76 |
|
77 |
_CITATION = """
|
78 |
"""
|
79 |
|
80 |
|
81 |
+
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
82 |
+
class nl2bash_metric(evaluate.Metric):
|
83 |
def _info(self):
|
84 |
+
return evaluate.MetricInfo(
|
85 |
description=_DESCRIPTION,
|
86 |
citation=_CITATION,
|
87 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
128 |
|
129 |
score_list = predictions == references
|
130 |
|
131 |
+
return {"exact_match": np.mean(score_list)}
|