I have spent quite some time trying to find an error in my function to compute perplexity for the case n=1. I got 321 instead of desired 318.
It turns out that the mistake was in count_ngrams, and for the case n=1 I have counted EOS twice. In order to find a similar mistake earlier and spend a little bit less time then I did, I propose to add one more assert for this corner-case.
I have spent quite some time trying to find an error in my function to compute perplexity for the case n=1. I got 321 instead of desired 318.
It turns out that the mistake was in count_ngrams, and for the case n=1 I have counted EOS twice. In order to find a similar mistake earlier and spend a little bit less time then I did, I propose to add one more assert for this corner-case.