Skip to content

Commit

Permalink
Fix translate.py bug (OpenNMT#1317) (OpenNMT#1318)
Browse files Browse the repository at this point in the history
`translate.py` would ignore all sentences after processing
`shard_size*shard_size` sentences in `src`, if no `tgt` file
was provided. This commit fixes this.
  • Loading branch information
fdalvi authored and vince62s committed Feb 24, 2019
1 parent cae083f commit 052954d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from itertools import repeat

from onmt.utils.logging import init_logger
from onmt.utils.misc import split_corpus
from onmt.translate.translator import build_translator
Expand All @@ -17,7 +19,7 @@ def main(opt):
translator = build_translator(opt, report_score=True)
src_shards = split_corpus(opt.src, opt.shard_size)
tgt_shards = split_corpus(opt.tgt, opt.shard_size) \
if opt.tgt is not None else [None]*opt.shard_size
if opt.tgt is not None else repeat(None)
shard_pairs = zip(src_shards, tgt_shards)

for i, (src_shard, tgt_shard) in enumerate(shard_pairs):
Expand Down

0 comments on commit 052954d

Please sign in to comment.