fix bugs
Browse files- nl2bash_m.py +25 -18
nl2bash_m.py
CHANGED
@@ -111,24 +111,31 @@ class nl2bash_m(evaluate.Metric):
|
|
111 |
final_score = 0
|
112 |
|
113 |
for pred, ref in zip(predictions, references):
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
final_score += score
|
133 |
|
134 |
final_score = final_score/len(predictions)
|
|
|
111 |
final_score = 0
|
112 |
|
113 |
for pred, ref in zip(predictions, references):
|
114 |
+
if len(pred) == 0 and len(ref[0]) == 0:
|
115 |
+
score = 1
|
116 |
+
elif len(pred) == 0 or len(ref[0]) == 0:
|
117 |
+
score = 0
|
118 |
+
else:
|
119 |
+
pred_words, ref_words = pred.split(), ref[0].split()
|
120 |
+
|
121 |
+
|
122 |
+
# Get the cmd of predicted and ref
|
123 |
+
cmd_corr = 1 if pred_words.pop(0)==ref_words.pop(0) else 0
|
124 |
+
|
125 |
+
# Get the option of predicted and ref
|
126 |
+
pred_option = [ x for x in pred_words if x[0] == '-']
|
127 |
+
ref_option = [ x for x in ref_words if x[0] == '-']
|
128 |
+
|
129 |
+
# Get the arguments of predicted and ref
|
130 |
+
pred_args = [ x for x in pred_words if x[0] != '-']
|
131 |
+
ref_args = [ x for x in ref_words if x[0] != '-']
|
132 |
+
|
133 |
+
# Calculate scores
|
134 |
+
cmd_score = cmd_weight * cmd_corr
|
135 |
+
opt_score = opt_weight * self.get_score(pred_option, ref_option)
|
136 |
+
arg_score = arg_weight * self.get_score(pred_args, ref_args)
|
137 |
+
|
138 |
+
score = cmd_score + opt_score + arg_score
|
139 |
final_score += score
|
140 |
|
141 |
final_score = final_score/len(predictions)
|