Skip to content

[Solved][PyTorch] ValueError: expected sequence of length 300 at dim 1 (got 3)

Today when I use PyTorch to build a model, I got an error message:

ValueError: expected sequence of length 300 at dim 1 (got 3)

Usually this error is when we convert our data to torch tensor data type, it means that most of our conversion programs are 300-dimensional, but there is one dimension that only has 3 dimensions, which leads to our matrix can not be converted to torch tensor.

Of course, yours may be any dimension, but in the final analysis it is the same: there is an error in the dimension.

There is only one solution: print out the dimensions of your data, find different elements, and confirm why this problem occurs.

I hope I will not come back to confirm my article in the future, or think of how to solve it immediately after I made the same mistake.


References


Read More

Leave a ReplyCancel reply

Exit mobile version