C2_W3_Assignment Exercise 9 wrong?

if in the UNQ_C9 convert tuple from a string I recive something like this :
[like] → [l, i, k, e]
i try to fix by the code
if type(previous_n_gram) is list ==> previous_n_grams = tuple(previous_n_gram)
else
==>previous_n_grams = tuple([previous_n_gram])
But the Estimate probabilities for all words i not recive expect output
this I recive.

  • What wrong with my code
  • Is previous_n_gram assign tuple(previous_n_gram) is wrong or correct
    {‘a’: 0.1111111111111111,
    ‘is’: 0.1111111111111111,
    ‘like’: 0.1111111111111111,
    ‘this’: 0.1111111111111111,
    ‘cat’: 0.1111111111111111,
    ‘dog’: 0.1111111111111111,
    ‘i’: 0.1111111111111111,
    ‘’: 0.1111111111111111,
    ‘’: 0.1111111111111111}

in the explanation of arguments of the method says: “previous_n_gram: A sequence of words of length n”

if you apply tuple to “previous_n_gram” you will not find any error because “previous_n_gram” is a list, be careful because names of variables are very similar but totally different.

1 Like