summaryrefslogtreecommitdiff
path: root/training
diff options
context:
space:
mode:
Diffstat (limited to 'training')
-rwxr-xr-xtraining/mira/mira.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/training/mira/mira.py b/training/mira/mira.py
index 32478c4f..4c87c664 100755
--- a/training/mira/mira.py
+++ b/training/mira/mira.py
@@ -138,6 +138,9 @@ def main():
args = parser.parse_args()
args.metric = args.metric.upper()
+ score_sign = 1.0
+ if args.metric == 'TER' or args.metric == 'WER' or args.metric == 'CER':
+ score_sign = -1.0
if not args.update_size:
args.update_size = args.kbest_size
@@ -187,7 +190,7 @@ def main():
args.devset = newdev
log_config(args)
- args.weights, hope_best_fear = optimize(args, script_dir, dev_size)
+ args.weights, hope_best_fear = optimize(args, script_dir, dev_size, score_sign)
graph_file = ''
if have_mpl: graph_file = graph(args.output_dir, hope_best_fear, args.metric)
@@ -305,7 +308,7 @@ def split_devset(dev, outdir):
refs.close()
return (outdir+'/source.input', outdir+'/refs.input')
-def optimize(args, script_dir, dev_size):
+def optimize(args, script_dir, dev_size, score_sign):
parallelize = script_dir+'/../utils/parallelize.pl'
if args.qsub:
parallelize += " -p %s"%args.pmem
@@ -316,7 +319,7 @@ def optimize(args, script_dir, dev_size):
num_features = 0
last_p_score = 0
best_score_iter = -1
- best_score = -1
+ best_score = -10 * score_sign
i = 0
hope_best_fear = {'hope':[],'best':[],'fear':[]}
#main optimization loop
@@ -433,7 +436,7 @@ def optimize(args, script_dir, dev_size):
hope_best_fear['fear'].append(dec_score_f)
logging.info('DECODER SCORE: {0} HOPE: {1} FEAR: {2}'.format(
dec_score, dec_score_h, dec_score_f))
- if dec_score > best_score:
+ if score_sign*dec_score > score_sign*best_score:
best_score_iter = i
best_score = dec_score