By the way - is there a way to avoid the outer-most loop? (as shown below):
loss_function = nn.NLLLoss(ignore_index=out_word2idx['<PAD>']).cuda()
loss = 0
for word in range(max_seq_len-1):
    loss += loss_function(output[:,word,:], y_data[:,word+1])    

I’m wondering if it’s possible to avoid the loop over individual words in the sequence altogether.