Hello I have a problem with calculate_perplexity function.

No matter how I try I cannot make it calculate perplexity correctly.

Here is my output from test sentence.

Here are what I have done already.

- In the first for loop I already ran i starting from n to N-1 (already check to include N-1)
- In defining n_gram, i already make sure it is splicing from string → I used sentence[:t]
- In probability I use estimate_probability function from previous code and use parameter from calculate_perplexity function.

I’m not sure why it still calculating wrong value.

Thanks