Lesson 12 (2019) discussion and wiki

Hi @w11wo,
It seems to be the same problem indeed, but somewhere else in the code. I have not faced it when going through the notebook, so I am not familiar with this specific case.
Just above the error message, the one you copied, there should be some code pointing you towards the bit of code which is in fault. It should help you identify which function uses an indexing on such a tensor. Feel free to paste what’s before the error message if you struggle with it.
Cheers

Hi @louis, thanks for the reply!

Here are the following lines of code which the error pointed to:

if isinstance(idx[0], bool):
    assert len(idx)==len(self) # bool mask
    return [o for m,o in zip(idx,self.items) if m]

it corresponds to the __getitem__ method in ListContainer class, which I obtained from notebook 06_cuda_cnn_hooks_init.ipynb. I believe it’s this line of code which triggered the error, hence I tried removing the [0] from the if statement, but it still wouldn’t work. Please let me know if you have a solution to this.

Thanks!

It seems that the error comes from the idx[0]. Try to replace it by idx.item(). You will have to reload the library to commit the change. If the error happens again, look in the error message if it still shows idx[0]. In that case it means that the modification has not been considered and so you should find a way to update the package with your correction. Hope this helps.

Hi @louis,

Thanks for keeping up with this problem, I really appreciate your help. I’ve tried your suggestion to replace [0] with .item(), but instead of being a problem in the following lines of code:

iter_dl = iter(train_dl)
x,y = next(iter_dl)

another error was triggered when the following lines of code were executed (before the code block above even ran):

dl = DataLoader(LM_PreLoader(ll.valid, shuffle=True), batch_size=64)

Here are the last few error lines:

--> 555         if isinstance(idx.item(), bool):
    556             assert len(idx)==len(self) # bool mask
    557             return [o for m,o in zip(idx,self.items) if m]

ValueError: only one element tensors can be converted to Python scalars

What I think happened was the new line of code no longer worked with multi-element tensors, hence the error message. Regardless, thanks for your assistance so far!

No worries.
If you are working with jupyter, you can user the. magic %debug in a new cell after get the error. Use it to look at what’s in your idx. It seems contradictory to me that on one hand you have a 0 rank tensor, and on the other you have a tensor with more than 1 element (thus a rank 1 tensor).
So check what’s the idx.

Hi everyone. I’m new to deep learning and I have a doubt in this lecture. Jeremy mentions that one should avoid stemming (@ 1:34:50 in the lecture). My intuition is; After tokenization, if the sentences have grammatical mistakes, wouldn’t that make it harder for the model to learn.