Okay, I have fixed the problem, As I kept ‘0’ for <pad>, my increments reached the last index(shape of embedding matrix). Thus when a dataset contained the word of the embedding matrix, it threw this error.
Fix: Therefore, I initialized the last word in the matrix as ‘0’, now the code runs good for all datasets.
Thank you very very much for your time and showing me the right places to look for bug. As pytorch is a framework, error like this isn’t really that much transparent and demotivates coders to look for it. Kudos.