The error below popped up during my coding assignment. It seems to be related to the data generator created in a previous exercise in the same notebook, which had already been validated in previous unit tests.
Since I couldn’t find problems in my code (I validated the part of the code that gathers negative examples by looking at the part that gathers the positive examples, which is given), I submitted it and got 100%.
I refreshed my environment by deleting everything but my .ipynb file and the problem persisted, that’s why I am reporting it.
If my assignment is actually wrong, please let me know!
Lab ID: vxkvzrixlsdd
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-57-8e65d7b0b2c0> in <module>
4 accuracy = test_model(test_generator(16, val_pos
5 , val_neg, Vocab, loop=False
----> 6 , shuffle = False), model)
7
8 print(f'The accuracy of your model on the validation set is {accuracy:.4f}', )
<ipython-input-56-f60b23950676> in test_model(generator, model, compute_accuracy)
15
16 ### START CODE HERE (Replace instances of 'None' with your code) ###
---> 17 for batch in generator:
18
19 # Retrieve the inputs from the batch
<ipython-input-14-4a5659de7672> in data_generator(data_pos, data_neg, batch_size, loop, vocab_dict, shuffle)
105
106 # get the tweet as neg_index
--> 107 tweet = data_neg[neg_index_lines[neg_index]]
108
109 # convert the tweet into tensors of integers representing the processed words
IndexError: list index out of range
Hey @tetamusha,
Welcome, and we are glad that you could be a part of our community
Can you please elaborate on this, as to what you deleted apart from your .ipynb file, cause I hope that you haven’t deleted the helper files?
As to this, it is completely possible. You see the unit tests can only go so far as to rule out the most frequent errors. It is completely possible that your implementation might have some error and it still passes all the unit tests.
As to this, please don’t mention your Lab ID, unless someone explicitly asks you for it.
And lastly, for us to pin-point the exact issue in your implementation, can you please DM me your implementation for the data_generator function? For DM, click on my name, and select “Message”.
I followed the procedure for refreshing my workspace by deleting everything, except the files I wanted to keep. I renamed my .ipynb file just in case, and then requested an update version of the files. Then I executed my notebook again and got the same results (with the error).
Thanks for letting us know about this. I just wanted to be sure, in case, you have taken any wrong step. As for the issue, it lies in your code where you have reset the neg_index. The largest possible value for neg_index is (len_data_neg - 1), however, you have reset the neg_index only when it exceeds len_data_neg, and now when the 2 are equal. You can take a look at the counterpart for pos_index, for an extra reference. I hope this resolves your query.
You’re right, I changed a single sign and my code passed the remaining unit tests, as well as got 100% in the grader. Thank you for helping me spot my mistake.