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
- https://discuss.pytorch.org/t/converting-a-list-to-tensor/44914
- https://discuss.pytorch.org/t/valueerror-expected-sequence-of-length-x-at-dim-1-got-y/69546
- https://github.com/ctr4si/A-Hierarchical-Latent-Structure-for-Variational-Conversation-Modeling/issues/2