Added perplexity calculating code.