fix(data): reshape labels instead of unsqueeze so a column-vector y works - #455
Open
ChrisW09 wants to merge 1 commit into
Open
fix(data): reshape labels instead of unsqueeze so a column-vector y works#455ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
…orks fit() documents y as (n_samples,) or (n_samples, n_targets), but TabularDataModule.setup() applied unsqueeze(dim=1) without flattening first. An (n, 1) target therefore became a (B, 1, 1) label tensor against (B, 1) predictions: MSELoss broadcast that to (B, B, 1) and optimised an all-pairs objective, losing the per-row pairing entirely, while BCEWithLogitsLoss refused to broadcast and raised. Same data and seed, only the y shape differing, gave R2 0.996 for 1-D y versus 0.002 for y.reshape(-1, 1). The corrupted loss also drove val_loss, so early stopping and checkpoint selection were affected too. reshape(-1, 1) produces the intended (B, 1) labels for both 1-D and column-vector input. Fixes #441 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #441
Problem
fit()documentsy : array-like, shape (n_samples,) or (n_samples, n_targets), butTabularDataModule.setup()applied.unsqueeze(dim=1)without flattening first. An(n, 1)targetbecame a
(B, 1, 1)label tensor against(B, 1)predictions:MSELossbroadcasts(B, 1)against(B, 1, 1)to(B, B, 1)andoptimises an all-pairs objective — the per-row pairing between prediction and target is gone. Same
data, same seed, only the
yshape differing: R2 = 0.996 (1-D) vs 0.002 (column vector).ValueError: Target size (torch.Size([8, 1, 1])) must be the same as input size (torch.Size([8, 1])).The corrupted loss also drives
val_loss, so early stopping and checkpoint selection were affected.Fix
reshape(-1, 1)instead ofunsqueeze(dim=1)— identical output for 1-D input, correct for a columnvector. The multiclass path already used
view(-1)and was unaffected.Tests
New
tests/test_target_shapes.py: label tensors are 2-D for both input shapes, a column-vectoryreaches the same R2 as 1-D (within 0.1), and binary classification accepts a column vector.
Verified 3 of the 4 fail on
main.tests/test_data.pyandtests/test_models.pypass unchanged.🤖 Generated with Claude Code