diff options
author | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-02 15:09:19 -0700 |
---|---|---|
committer | Michael Denkowski <mdenkows@cs.cmu.edu> | 2013-09-02 15:09:19 -0700 |
commit | 7e8600d924f082c2d4b84e5d80993531e880c390 (patch) | |
tree | 4a4d4d0903a42f939304f3423fd877ef01e6a2b6 /realtime/rt | |
parent | 532899b5101250d4f187733860404ee932a8851c (diff) |
Use kbest_cut_mira stream as decoder
Diffstat (limited to 'realtime/rt')
-rw-r--r-- | realtime/rt/decoder.py | 16 |
1 files changed, 12 insertions, 4 deletions
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 = '<seg grammar="{g}">{s}</seg>\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 = '<seg grammar="{g}">{s}</seg>\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) |