# UNQ_C3 GRADED FUNCTION: extract_features

while implementing extract_features function, I tried to get the value for the key = (“word”,1) and compare if is not None in freqs dict. and if so update x[0,1] and x[0,2]. What am I doing wrong here?

Hi @Akshat_Sharma5

The easiest way to achieve what you want is with dictionary’s get() method. You can find more details in this thread.

Basically, what the function does is:

  • in the start x is set to an array of three values: [[0, 0, 0]]
  • next “bias” is set to 1; x[0,0] = 1 results in x → [[1, 0, 0]]
  • next you loop over the words:
    • in each loop you need to update (accumulate with +=) the “positive” part, which is at x[0,1] ; to get that, you use the get() method on freqs dictionary where keyname is (word, 1.0) and value for not found is 0. For example, if (word, 1.0) has 5 positive counts, then after the iteration x → [[1,5,0]]
    • in each loop you also need to update (accumulate with +=) the “negative” part, which is at x[0,2] (or third “column”); to get that, you also use the get() method on freqs dictionary where keyname is (word, 0.0) and value for not found is 0. For example, if (word, 1.0) has 2 negative counts, then after the iteration x → [[1,5,2]]
  • after the for loop is finished the example of the x could be [[1, 313, 61]] - the tweets words accumulated to be positive. If none of the words were in the dictionary (like the example of ‘blorb bleeeeb bloooob’), then x with [[1, 0, 0]] will be returned.

Good luck!