Calculate perplexity on a text with pre-trained language models. Support MLM (eg. DeBERTa), recurrent LM (eg. GPT3), and encoder-decoder LM (eg. Flan-T5).
nll.append(sum([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]))
I think this calculation may be wrong. May need to change to
nll.append(sum([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]) / len([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]))
nll.append(sum([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]))
I think this calculation may be wrong. May need to change tonll.append(sum([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]) / len([i for i in completion['choices'][0]['logprobs']['token_logprobs'] if i is not None]))