@ptrblck thank you very much for pointing it out.
prob = torch.tensor([item.item() for sublist in prob for item in sublist],dtype = torch.float32)

This above code didn’t let loss function calculate the gradients. Finally I used torch.flatten() to reshape the tensor.
But, now I have another question. Still my weights looks unupdated after calculating gradients and even after every epoch the weights remain the very same. I used this code to check it.
list(rnn.parameters())[0].clone()

Where I am I going wrong? Please check the screenshot.

Screen Shot 2021-07-22 at 2.00.38 AM1376×964 95.8 KB