15b19130a9162feb9153a2f38c5c8b0af02c6a1d,train.py,,eval_epoch,#,75
Before Change
n_words = gold.data.ne(Constants.PAD).sum()
n_total_words += n_words
n_total_correct += n_correct
total_loss += loss.data[0]
return total_loss/n_total_words, n_total_correct/n_total_words
def train(model, training_data, validation_data, crit, optimizer, opt):
After Change
n_total_words = 0
n_total_correct = 0
with torch.no_grad():
for batch in tqdm(
validation_data, mininterval=2,
desc=" - (Validation) ", leave=False):
// prepare data
src_seq, src_pos, tgt_seq, tgt_pos = map(lambda x: x.to(device), batch)
gold = tgt_seq[:, 1:]
// forward
pred = model(src_seq, src_pos, tgt_seq, tgt_pos)
loss, n_correct = get_performance(crit, pred, gold)
// note keeping
n_words = gold.data.ne(Constants.PAD).sum()
n_total_words += n_words
n_total_correct += n_correct
total_loss += loss.item()
loss_per_word = total_loss/n_total_words
accuracy = n_total_correct/n_total_words
return loss_per_word, accuracy
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 6
Instances
Project Name: jadore801120/attention-is-all-you-need-pytorch
Commit Name: 15b19130a9162feb9153a2f38c5c8b0af02c6a1d
Time: 2018-08-21
Author: yhhuang@nlg.csie.ntu.edu.tw
File Name: train.py
Class Name:
Method Name: eval_epoch
Project Name: gpleiss/efficient_densenet_pytorch
Commit Name: b0a156d87b736d90c3e27933e8e4d0114bd5ef36
Time: 2019-01-27
Author: gpleiss@gmail.com
File Name: demo.py
Class Name:
Method Name: test_epoch
Project Name: bearpaw/pytorch-pose
Commit Name: 585303417c3f4641f61ac5a916a51505a67cc507
Time: 2019-01-24
Author: platero.yang@gmail.com
File Name: example/mscoco.py
Class Name:
Method Name: validate