The estimated probability of word ‘cat’ given the previous n-gram ‘a’ is: 0.1111
I checked my code and logic and it seems nothing wrong.
The estimated probability of word ‘cat’ given the previous n-gram ‘a’ is: 0.1111
I checked my code and logic and it seems nothing wrong.
Please click my name and message your notebook as an attachment.
Can you post the solution to your question if it was solved? I’m having the same issue, and others might come across it as well, and would appreciate the update.
Edit: I was able to solve this issue by simply restarting the kernel and rerunning it. I guess it’s always worth a shot to try this
@Masoudinejad Sorry for the delay. Don’t recall seeing the notification for your message.
The issue as you might expect, is within the function estimate_probability
. tuple(a_string)
will create a tuple with each character as an element and not a tuple with 1 element. Here’s an example:
>>> tuple('hello')
('h', 'e', 'l', 'l', 'o')
Please use this hint to fix the lookup for n_plus_1_gram_count
.
Very helpful, thanks!!