Here is a beautiful explanation about perplexity by @jyadav202
feel free to ask if you still have any query
so basically it logs probability between the given context and predicted word or sentences(corpus), and gives a log of probabilities and the reshaped targets with the axis dimension, helps to get the text or output based on the model created for word or sentence prediction.