summaryrefslogtreecommitdiff
path: root/realtime
diff options
context:
space:
mode:
authorMichael Denkowski <mdenkows@cs.cmu.edu>2014-04-08 13:54:25 -0700
committerMichael Denkowski <mdenkows@cs.cmu.edu>2014-04-08 13:54:25 -0700
commit7242963e683d7b3d4b6c49ac3814ced360ef10c8 (patch)
tree2a29709f5c7cad4acc7b5789f9e1f151257586da /realtime
parentb7d8454761a67f385b8e551fbf4f342e53ad81d8 (diff)
setup for hpyplm being optional, different metrics
Diffstat (limited to 'realtime')
-rwxr-xr-xrealtime/mkconfig.py20
-rw-r--r--realtime/rt/decoder.py6
2 files changed, 18 insertions, 8 deletions
diff --git a/realtime/mkconfig.py b/realtime/mkconfig.py
index f193c57a..71944080 100755
--- a/realtime/mkconfig.py
+++ b/realtime/mkconfig.py
@@ -12,11 +12,14 @@ from cdec.configobj import ConfigObj
def main():
- if len(sys.argv[1:]) != 12:
- sys.stderr.write('usage: {} a.fwd_params a.fwd_err a.rev_params a.rev_err sa sa.ini mono.klm libcdec_ff_hpyplm.so corpus.hpyplm cdec.ini weights.final output.d\n'.format(sys.argv[0]))
+ if len(sys.argv[1:]) not in (10, 12):
+ sys.stderr.write('usage: {} a.fwd_params a.fwd_err a.rev_params a.rev_err sa sa.ini mono.klm cdec.ini weights.final output.d [libcdec_ff_hpyplm.so corpus.hpyplm]\n'.format(sys.argv[0]))
sys.exit(2)
- (a_fwd_params, a_fwd_err, a_rev_params, a_rev_err, sa, sa_ini, mono_klm, libcdec_ff_hpyplm_so, corpus_hpyplm, cdec_ini, weights_final, output_d) = sys.argv[1:]
+ (a_fwd_params, a_fwd_err, a_rev_params, a_rev_err, sa, sa_ini, mono_klm, cdec_ini, weights_final, output_d) = sys.argv[1:11]
+
+ # Optional
+ (libcdec_ff_hpyplm_so, corpus_hpyplm) = sys.argv[11:13] if len(sys.argv[1:]) == 12 else (None, None)
if os.path.exists(output_d):
sys.stderr.write('Directory {} exists, exiting.\n'.format(output_d))
@@ -40,8 +43,10 @@ def main():
# language models
shutil.copy(mono_klm, os.path.join(output_d, 'mono.klm'))
- shutil.copy(libcdec_ff_hpyplm_so, os.path.join(output_d, 'libcdec_ff_hpyplm.so'))
- shutil.copy(corpus_hpyplm, os.path.join(output_d, 'corpus.hpyplm'))
+ if libcdec_ff_hpyplm_so:
+ shutil.copy(libcdec_ff_hpyplm_so, os.path.join(output_d, 'libcdec_ff_hpyplm.so'))
+ if corpus_hpyplm:
+ shutil.copy(corpus_hpyplm, os.path.join(output_d, 'corpus.hpyplm'))
# decoder config
config = [[f.strip() for f in line.split('=')] for line in open(cdec_ini)]
@@ -52,6 +57,11 @@ def main():
# weights
shutil.copy(weights_final, os.path.join(output_d, 'weights.final'))
+
+ # other options
+ # TODO: automatically set some things here
+ with open(os.path.join(output_d, 'rt.ini'), 'w') as rt_ini:
+ pass
if __name__ == '__main__':
main()
diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py
index ed45c248..5082911d 100644
--- a/realtime/rt/decoder.py
+++ b/realtime/rt/decoder.py
@@ -38,11 +38,11 @@ class CdecDecoder(Decoder):
class MIRADecoder(Decoder):
- def __init__(self, config, weights):
+ def __init__(self, config, weights, metric='bleu'):
cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
mira = os.path.join(cdec_root, 'training', 'mira', 'kbest_cut_mira')
- # optimizer=2 step=0.001 best=500, k=500, uniq, stream
- mira_cmd = [mira, '-c', config, '-w', weights, '-o', '2', '-C', '0.001', '-b', '500', '-k', '500', '-u', '-t']
+ # optimizer=2 step=0.001 best=500, k=500, uniq, stream, metric
+ mira_cmd = [mira, '-c', config, '-w', weights, '-o', '2', '-C', '0.001', '-b', '500', '-k', '500', '-u', '-t', '-m', metric]
logger.info('Executing: {}'.format(' '.join(mira_cmd)))
self.decoder = util.popen_io(mira_cmd)
self.lock = util.FIFOLock()