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
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: 10
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: uber/ludwig
Commit Name: 5667af96dade79ef77194d519182d4989494b3a4
Time: 2019-08-25
Author: smiryala@uber.com
File Name: ludwig/features/image_feature.py
Class Name: ImageBaseFeature
Method Name: add_feature_data
Project Name: uber/ludwig
Commit Name: 7d9db23a389499c2764fb850cd19f853cc3e8565
Time: 2019-08-08
Author: smiryala@uber.com
File Name: ludwig/features/image_feature.py
Class Name: ImageBaseFeature
Method Name: add_feature_data