From 1543b24f05d344568560f4ff15905939d0281062 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Thu, 26 Mar 2015 22:53:06 -0400 Subject: fix bug --- training/mira/mira.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/training/mira/mira.py b/training/mira/mira.py index ec9c2d64..dc1bd724 100755 --- a/training/mira/mira.py +++ b/training/mira/mira.py @@ -152,6 +152,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 @@ -319,7 +322,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 @@ -330,7 +333,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 @@ -450,7 +453,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 -- cgit v1.2.3