Error in nn.NLLLoss() function while computing loss in lstm model

The error is in trying to compute loss using nn.NLLLoss() . The error "IndexError: Target 1 is out of bounds."
changes when ignore_index is set to 1. The error then is Target 2 is out of bounds.

I am unable to figure out the cause of problem.

The error resolved, refer to the link pytorch discussion.