C3_w4 q6: predict() "cannot unpack non-iterable NoneType object"

My predict() function looks like it is working on the example questions, but then when I try to run the test_predict() unit test, I get:

<ipython-input-50-ae8bca3db877> in predict(question1, question2, threshold, model, vocab, data_generator, verbose)
     33     Q1, Q2 = next(data_generator(Q1=[Q1], Q2=[Q2], batch_size=1, pad=vocab['<PAD>']))
     34     # Call the model
---> 35     v1, v2 = model((Q1,Q2))
     36     # take dot product to compute cos similarity of each pair of entries, v1, v2
     37     # don't forget to transpose the second argument

TypeError: cannot unpack non-iterable NoneType object

Answers to similar questions mentioned to use vocab['<PAD>'] as the pad argument, but I am already doing that.

Any help would be appreciated, thanks!

The implication is that one of Q1 or Q2 is set to None, rather than the expected iterable value.

1 Like

Hi Izak,

In case you didn’t find a solution. I had a similar error to the one you are getting. The fix was not in the Predict() code, it was in the data_generator() code (the first exercise of week 4). I didn’t correctly calculate the amount of padding to add to my sentence. It was difficult to catch this error because my incorrect data_generator code still passed all testing.

1 Like

Thanks for the feedback. printing out the values of Q1 and Q2 helped me to debug my problem.

In the data_generator, I had made a typo and used 'word' in stead of word as the key to the vocab dictionary.