Josh98 commited on
Commit
5a101a3
·
1 Parent(s): 107f45c
Files changed (1) hide show
  1. 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
- 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
117
-
118
- # Get the option of predicted and ref
119
- pred_option = [ x for x in pred_words if x[0] == '-']
120
- ref_option = [ x for x in ref_words if x[0] == '-']
121
-
122
- # Get the arguments of predicted and ref
123
- pred_args = [ x for x in pred_words if x[0] != '-']
124
- ref_args = [ x for x in ref_words if x[0] != '-']
125
-
126
- # Calculate scores
127
- cmd_score = cmd_weight * cmd_corr
128
- opt_score = opt_weight * self.get_score(pred_option, ref_option)
129
- arg_score = arg_weight * self.get_score(pred_args, ref_args)
130
-
131
- score = cmd_score + opt_score + arg_score
 
 
 
 
 
 
 
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)