calculate perplexity