C3_w4 Classify cannot unpack non-iterable NoneType object


This question has been asked before, but the solution of pad = vocab['<PAD>'] doesn't work. When I print the shape of q1 and q2 they are both np.arrays of (512, 16384). When I print i.e. print(model((q1,q2))) it prints none. Here is the how I got q1 and q2

q1, q2 = next(data_generator(Q1 = test_Q1[i:i+batch_size], Q2 = test_Q2[i:i+batch_size],batch_size = batch_size, pad = vocab['<PAD>'],shuffle = False))

Is there a chance the model provided is incorrect?

TypeError                                 Traceback (most recent call last)
<ipython-input-41-62ddffad3694> in <module>
      1 # Test your function
----> 2 w4_unittest.test_classify(classify, vocab, data_generator)

~/work/w4_unittest.py in test_classify(target, vocab, data_generator)
   1346     for test_case in test_cases:
-> 1347         result = target(**test_case["input"])
   1349         try:

<ipython-input-40-2d9ab9a77c02> in classify(test_Q1, test_Q2, y, threshold, model, vocab, data_generator, batch_size)
     32         y_test = y[i:i+batch_size]
     33         # Call the model
---> 34         v1, v2 = model((q1,q2))
     36         for j in range(batch_size):

TypeError: cannot unpack non-iterable NoneType object
1 Like

I solved this case. It turned out the issue was not in the classify() 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. My data_generator function was adding thousands of vocab[‘’] to the end of my sentences, even when the max sentence length was less then a hundred. It was difficult to catch this error because my incorrect data_generator code still passed all testing.

Hey @Richard_Xiang,
Thanks for confirming that your issue has been resolved.