From 7e8600d924f082c2d4b84e5d80993531e880c390 Mon Sep 17 00:00:00 2001 From: Michael Denkowski Date: Mon, 2 Sep 2013 15:09:19 -0700 Subject: Use kbest_cut_mira stream as decoder --- realtime/realtime.py | 6 +++--- realtime/rt/decoder.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'realtime') diff --git a/realtime/realtime.py b/realtime/realtime.py index c42b52ab..c169ce4c 100755 --- a/realtime/realtime.py +++ b/realtime/realtime.py @@ -11,7 +11,7 @@ import tempfile import time from rt import ForceAligner -from rt import CdecDecoder +from rt import MIRADecoder class RealtimeDecoder: @@ -35,8 +35,7 @@ class RealtimeDecoder: # Decoder decoder_config = os.path.join(configdir, 'cdec.ini') decoder_weights = os.path.join(configdir, 'weights.final') - #TODO: run MIRA instead - self.decoder = CdecDecoder(decoder_config, decoder_weights) + self.decoder = MIRADecoder(decoder_config, decoder_weights) def close(self): logging.info('Closing processes') @@ -90,6 +89,7 @@ def main(): if len(input) == 1: hyp = rtd.decode(input[0]) sys.stdout.write('{}\n'.format(hyp)) + sys.stdout.flush() elif len(input) == 2: rtd.learn(*input) diff --git a/realtime/rt/decoder.py b/realtime/rt/decoder.py index f4fea0e2..786bc07a 100644 --- a/realtime/rt/decoder.py +++ b/realtime/rt/decoder.py @@ -8,6 +8,11 @@ class Decoder: def close(self): self.decoder.stdin.close() + def decode(self, sentence, grammar): + input = '{s}\n'.format(i=id, s=sentence, g=grammar) + self.decoder.stdin.write(input) + return self.decoder.stdout.readline().strip() + class CdecDecoder(Decoder): def __init__(self, config, weights): @@ -16,8 +21,11 @@ class CdecDecoder(Decoder): decoder_cmd = [decoder, '-c', config, '-w', weights] self.decoder = util.popen_io(decoder_cmd) - def decode(self, sentence, grammar): - input = '{s}\n'.format(i=id, s=sentence, g=grammar) - self.decoder.stdin.write(input) - return self.decoder.stdout.readline().strip() +class MIRADecoder(Decoder): + def __init__(self, config, weights): + cdec_root = os.path.dirname(os.path.dirname(os.path.dirname(__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'] + self.decoder = util.popen_io(mira_cmd) -- cgit v1.2.3