C2_W3 Q9 test case with key error ('l', 'i', 'k', 'e')

I ran the test cases on W3 Q9 and got the key type error (‘l’, ‘i’, ‘k’, ‘e’). I tried to print out the ‘word’ parameter and noticed that the type was at the “test your codes” section but it came as in the following cell “Test your function”

Any suggestions to resolve this problem?

Thanks!


i

Resolved. It looks like the test case is intended to see if the previous n-gram is in the n_gram_counts dictionary. I added the condition to take care of the scenario and all test cases passed.

Hey @Chin-Wen_Chang,
Welcome, and we are glad that could be a part of our community :partying_face: Thanks for letting us know that your issue has been resolved.

Cheers,
Elemento

By looking at the test case, I feel this(‘l’,‘i’,‘k’,‘e’ as a 2-gram) is not really a good or should be a test case that is in high priority. Especially given there are only two test cases. Maybe we should replace it with a valid 2-gram case instead give a invalid one to let student to deal with abnormal parameters.

Hey @Hu_Qing,
Can you please elaborate your response a little more? I am unable to understand it in it’s present state. Should we remove this test-case, and if yes, then why and with what should we replace it with?

Cheers,
Elemento

My suggestion is add a new modified test case of test_estimate_probability with a valid 2-gram test case. For example replace
“word”: “i”,
“previous_n_gram”: “like”,

WITH

“word”: “a”,
“previous_n_gram”: [“I”, “like”],

Hey @Hu_Qing,
Apologies for the delayed response. I am still a little unsure if what you are saying is really needed. As of now, there are 2 test-cases. The first test-case checks the implementation for the case when the previous_n_gram has a non-zero count in the n_gram_counts dictionary, and the second test-case checks the implementation for the case when the previous_n_gram is not there in the n_gram_counts dictionary. I guess these 2 cases are more than enough to check any implementation. What you are proposing is already covered by the first test-case, so, do we really need to include it?

The only difference in what you are proposing is the number of tokens that form the keys, and I believe that it is not something that is implemented as a part of the function. Let me know your take on this.

Cheers,
Elemento