Josh98 commited on
Commit
eb8ecc4
1 Parent(s): 28bbd1a

update some comments

Browse files
Files changed (1) hide show
  1. nl2bash_m.py +14 -43
nl2bash_m.py CHANGED
@@ -11,7 +11,7 @@
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
- """Exact Match metric."""
15
  import re
16
  import string
17
 
@@ -28,50 +28,23 @@ returns a score that indicates how close the bash command generated is to the ac
28
  _KWARGS_DESCRIPTION = """
29
  Args:
30
  predictions: List of predicted texts.
31
- references: List of reference texts.
32
- regexes_to_ignore: List, defaults to None. Regex expressions of characters to
33
- ignore when calculating the exact matches. Note: these regexes are removed
34
- from the input data before the changes based on the options below (e.g. ignore_case,
35
- ignore_punctuation, ignore_numbers) are applied.
36
- ignore_case: Boolean, defaults to False. If true, turns everything
37
- to lowercase so that capitalization differences are ignored.
38
- ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before
39
- comparing predictions and references.
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 = """
@@ -138,7 +111,6 @@ class nl2bash_m(evaluate.Metric):
138
  final_score = 0
139
 
140
  for pred, ref in zip(predictions, references):
141
- print(pred, ref)
142
  pred_words, ref_words = pred.split(), ref[0].split()
143
  # Get the cmd of predicted and ref
144
  cmd_corr = 1 if pred_words.pop(0)==ref_words.pop(0) else 0
@@ -158,7 +130,6 @@ class nl2bash_m(evaluate.Metric):
158
 
159
  score = cmd_score + opt_score + arg_score
160
  final_score += score
161
- print(score)
162
 
163
  final_score = final_score/len(predictions)
164
  print("f_s: ", final_score)
 
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
  # See the License for the specific language governing permissions and
13
  # limitations under the License.
14
+ """nl2bash metric."""
15
  import re
16
  import string
17
 
 
28
  _KWARGS_DESCRIPTION = """
29
  Args:
30
  predictions: List of predicted texts.
31
+ references: List of reference texts.
32
+ cmd_weight: The weight you want to put on getting the command correct
33
+ opt_weight: The weight you want to put on getting the option correct
34
+ arg_weight: The weight you want to put on getting the arg correct
35
+ ignore_case=False,
36
+ ignore_numbers=False,
 
 
 
 
 
37
  Returns:
38
+ nl2bash metric: Dictionary containing nl2bash score. Possible values are between 0.0 and 1.0, inclusive.
39
  Examples:
40
+
41
+
42
+ >>> metric = evaluate.load("Josh98/nl2bash_m")
43
+ >>> preds = ["ls -l /home/userr", "ls -l /home/josh", "lss /home/josh some argument"]
44
+ >>> refs = [["ls -l /home/user"], ["ls -l --v /home/josh"], ["ls /home/josh"]]
45
  >>> results = exact_match.compute(references=refs, predictions=preds)
46
+ >>> print(round(results["nl2bash"], 2))
47
  0.25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  """
49
 
50
  _CITATION = """
 
111
  final_score = 0
112
 
113
  for pred, ref in zip(predictions, references):
 
114
  pred_words, ref_words = pred.split(), ref[0].split()
115
  # Get the cmd of predicted and ref
116
  cmd_corr = 1 if pred_words.pop(0)==ref_words.pop(0) else 0
 
130
 
131
  score = cmd_score + opt_score + arg_score
132
  final_score += score
 
133
 
134
  final_score = final_score/len(predictions)
135
  print("f_s: ", final_score)