perplexity function

Compute perplexity of a model