-
-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why does DataLoader
not throw an error when fed with a 1D vector for the target?
#1599
Comments
One thing to see would be the behaviour with |
In the original code, the label is 2D vector but the model returns a scalar. I think the "bug" here is with That being said, it is possible with |
I think @darsnack is right about
though when the second arguement is a 1D vector, it computes something else (not sure what it is computing):
Still I think this issue has to be taken care of by |
I think a good example is how the dataloader handles a smaller batch: julia> loader = DataLoader((train_input, train_target), batchsize=1);
julia> collect(loader)
2-element Vector{Tuple{Matrix{Int64}, Matrix{Int64}}}:
([0; 0], [0])
([1; 1], [1]) So the consistency in the number of observations is preserved. I would personally be worried if the dataloader is adding extra dimensions to the arrays I give it, as a) reshape may not preserve the original structure and b) is not always appropriate depending on how the loss function is formulated. I do agree that MSE and other loss functions should be better about failing fast given inputs with mismatched dims. |
I think we can and should do both. There are two things to address here:
(1) makes (2) redundant for now, but (2) let's us have friendlier errors and catch cases like (1) for future functions/losses. |
pytorch restricts losses to have prediction and target of the same shape, which seems safer than what we do now accepting any broadcast compatible pair. I don't think we would lose much in functionality, most losses are trivial for users to reimplement by themselves if needed and we would avoid a lot of people to fall into this trap. |
Suppose you have the following simple example:
We generate a machine learning model as follows:
The code runs without throwing any errors, though the model actually converges to a constant output value and fails to approximate the variation of the data.
If, however, one defines
train_target
aswhich is a 1*2 matrix, the model behaves as expected, and we get a good result.
The documentation of
DataLoader
says thattrain_input
andtrain_target
have to be tensors, with the last dimension in each of them to be the observation dimension. Are 1D vectors not included in this definition of "tensors"? If so, why doesn'tDataLoader
throw an error?The text was updated successfully, but these errors were encountered: