training:
tensor([[  2.4237,   2.5905,   2.2169, -10.5635,  -1.0118, -10.1921],
        [  3.0716,   3.8252,   3.1995,  -8.1787,  -4.2393,  -8.7988],
        [  2.8787,   3.6345,   2.8708,  -8.3596,  -4.4989,  -8.4322],
        ...,
        [  1.5031,   1.0884,   1.2739,  -9.6650,   2.4617,  -9.0367],
        [  1.3291,   1.5163,   1.4576, -10.0381,   2.1117,  -9.5944],
        [  0.9889,   1.2590,   1.0715,  -9.5567,   2.5086,  -9.4345]],
       grad_fn=<ViewBackward>)
tensor([[  3.1798,   3.6515,   2.7826,  -8.4505,  -4.2253,  -8.5992],
        [  3.2187,   3.5649,   2.8608,  -8.9943,  -3.8257,  -8.1756],
        [  2.8734,   3.4187,   2.6570,  -7.9880,  -4.0824,  -8.3490],
        ...,
        [  1.0231,   1.5060,   0.9266,  -9.2981,   2.0333,  -9.3198],
        [  1.3715,   1.2931,   1.0752,  -9.4257,   2.2230,  -9.2558],
        [  1.7830,   1.6602,   1.5629, -10.3801,   1.7262, -10.1634]],
       grad_fn=<ViewBackward>)
tensor([[  3.0281,   3.7362,   3.0541,  -8.4012,  -4.0972,  -8.8399],
        [  2.5452,   3.5018,   2.7213,  -7.9301,  -3.7148,  -8.4083],
        [  2.9479,   3.6801,   2.8139,  -8.8359,  -3.9234,  -8.8597],

prediction loop:
SOS=3, EOS=4, PAD=5
def show_predictions_transformer(model, loader):
    model.eval()
    
    with torch.no_grad():
        for source, target in loader:

            target_max_len = 12
            outputs = torch.zeros(target_max_len, dtype=torch.long)
            outputs[0] = torch.LongTensor([SOS])

            for i in range(1, target_max_len):
                pred = model(source, outputs[:i].unsqueeze(1))
                outputs[i] = pred[-1].argmax(1)
                if outputs[i] == EOS:
                    #print('eos')
                    break

            print('targ', target.squeeze())
            print('pred', outputs)

targ tensor([3, 1, 1, 2, 1, 0, 2, 4])
pred tensor([3, 1, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0])
Epoch: 04 | Time: 0m 27s
	Train Loss: 1.180 | Train PPL:   3.254
	 Val. Loss: 1.104 |  Val. PPL:   3.017
targ tensor([3, 2, 2, 2, 0, 1, 1, 4])
pred tensor([3, 1, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0])
Epoch: 05 | Time: 0m 27s
	Train Loss: 1.176 | Train PPL:   3.240
	 Val. Loss: 1.131 |  Val. PPL:   3.098
targ tensor([3, 2, 1, 1, 2, 1, 0, 4])
pred tensor([3, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0])
Epoch: 06 | Time: 0m 26s
	Train Loss: 1.166 | Train PPL:   3.210