As loss you probably want to calculate NLLLoss after having done LogSoftMax on your logits (or you can have a look at CrossEntropyLoss).
criterion = nn.NLLLoss()
loss = criterion(output, target_tensor[i])

where i is the i-th item that you are currently predicting.
In the code that I gave you can replace RU with LSTM. The difference in code being that GRU does not have a cell state, so it is easier to implement.