hyp_sentence = []
for word_idx in hyps[i, 1:]:
hyp_sentence.append(
_get_word(decoder_vocab, word_idx)
)
if word_idx == decoder_vocab.get_token_index(END_SYMBOL, "targets"):
break
hyp_sentence = " ".join(hyp_sentence)
target = relevant_targets[i]
target_sentence = " ".join([_get_word(decoder_vocab, i) for i in target])
f.write("{}\t{}\n".format(hyp_sentence, target_sentence))
After Change
def write_translation_preds(hyps, relevant_targets, preds_file_path, decoder_vocab):
with open(preds_file_path, "a") as f:
for i in range(len(hyps)):
hyp, target = hyps[i], relevant_targets[i]
hyp_sentence = " ".join([_get_word(decoder_vocab, i) for i in hyp])
target_sentence = " ".join([_get_word(decoder_vocab, i) for i in target])
f.write("{}\t{}\n".format(hyp_sentence, target_sentence))