f6f6ee1df8d619d9816a5296bebca5736fa952bf,translate.py,,main,#,67
Before Change
gold_score_total += sum(gold_score)
gold_words_total += sum(len(x) for x in batch.tgt[1:])
for b in range(len(pred_batch)):
count += 1
for n in range(opt.n_best):
out_file.write(" ".join(pred_batch[b][n]) + "\n")
out_file.flush()
if opt.verbose:
words = []
for f in src[:, b]:
word = translator.fields["src"].vocab.itos[f]
if word == onmt.IO.PAD_WORD:
break
words.append(word)
os.write(1, bytes("\nSENT %d: %s\n" %
(count, " ".join(words)), "UTF-8"))
index += 1
os.write(1, bytes("PRED %d: %s\n" %
(count, " ".join(pred_batch[b][0])), "UTF-8"))
print("PRED SCORE: %.4f" % pred_score[b][0])
if opt.tgt:
tgtSent = " ".join(gold_batch[b])
os.write(1, bytes("GOLD %d: %s\n" %
(count, tgtSent), "UTF-8"))
print("GOLD SCORE: %.4f" % gold_score[b])
if opt.n_best > 1:
print("\nBEST HYP:")
for n in range(opt.n_best):
os.write(1, bytes("[%.4f] %s\n" % (pred_score[b][n],
" ".join(pred_batch[b][n])),
"UTF-8"))
report_score("PRED", pred_score_total, pred_words_total)
if opt.tgt:
report_score("GOLD", gold_score_total, gold_words_total)
After Change
// sentence in the batch. It has to be zip_longest instead of
// plain-old zip because the gold_batch has length 0 if the target
// is not included.
z_batch = zip_longest(
pred_batch, gold_batch,
pred_scores, gold_scores,
(sent.squeeze(1) for sent in src.split(1, dim=1)))
for pred_sents, gold_sent, pred_score, gold_score, src_sent in z_batch:
count += 1
for n in range(opt.n_best):
out_file.write(" ".join(pred_sents[n]) + "\n")
out_file.flush()
if opt.verbose:
words = []
for f in src_sent:
word = translator.fields["src"].vocab.itos[f]
if word == onmt.IO.PAD_WORD:
break
words.append(word)
os.write(1, bytes("\nSENT %d: %s\n" %
(count, " ".join(words)), "UTF-8"))
index += 1
os.write(1, bytes("PRED %d: %s\n" %
(count, " ".join(pred_sents[0])), "UTF-8"))
print("PRED SCORE: %.4f" % pred_score[0])
if opt.tgt:
tgtSent = " ".join(gold_sent)
os.write(1, bytes("GOLD %d: %s\n" %
(count, tgtSent), "UTF-8"))
print("GOLD SCORE: %.4f" % gold_score)
if opt.n_best > 1:
print("\nBEST HYP:")
for n in range(opt.n_best):
os.write(1, bytes("[%.4f] %s\n" % (pred_score[n],
" ".join(pred_sents[n])),
"UTF-8"))
report_score("PRED", pred_score_total, pred_words_total)
if opt.tgt:
report_score("GOLD", gold_score_total, gold_words_total)
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 8
Instances
Project Name: OpenNMT/OpenNMT-py
Commit Name: f6f6ee1df8d619d9816a5296bebca5736fa952bf
Time: 2017-09-21
Author: bpeters@coli.uni-saarland.de
File Name: translate.py
Class Name:
Method Name: main
Project Name: OpenNMT/OpenNMT-py
Commit Name: f6f6ee1df8d619d9816a5296bebca5736fa952bf
Time: 2017-09-21
Author: bpeters@coli.uni-saarland.de
File Name: translate.py
Class Name:
Method Name: main
Project Name: ixaxaar/pytorch-dnc
Commit Name: 51caa2e2cebe2e6e8c06ffbb918448dd2db011a7
Time: 2017-11-10
Author: root@ixaxaar.in
File Name: dnc/dnc.py
Class Name: DNC
Method Name: _layer_forward
Project Name: ixaxaar/pytorch-dnc
Commit Name: aa9592d811ad9765e06dd0e638e7cee9e5f4b00c
Time: 2017-11-10
Author: root@ixaxaar.in
File Name: dnc/dnc.py
Class Name: DNC
Method Name: _layer_forward