Add downsample and upsample transforms#258
Open
david-rx wants to merge 1 commit into
Open
Conversation
Downsample randomly keeps a fraction of rows (useful for dev/ablation). Upsample repeats every row N times (useful for epoch-matching small datasets). Both follow the existing transform conventions: Pydantic config with Literal type discriminator, from_config classmethod, DataBackend protocol, and register_transform registration. Tests cover both pandas and polars backends. Made-with: Cursor
GaganNarula
reviewed
Apr 7, 2026
| The downsampled backend and empty metadata dict. | ||
| """ | ||
| n = max(1, round(len(backend) * self.fraction)) | ||
| return backend.sample_rows(n=n, seed=self.seed), {} |
Collaborator
There was a problem hiding this comment.
if fraction == 1.0, then maybe we should just return the backend ? Not sure if the backends are shuffling even if fraction==1.0 (polars sets shuffle = False by default)
GaganNarula
requested changes
Apr 7, 2026
Collaborator
GaganNarula
left a comment
There was a problem hiding this comment.
Can we add these transform docs to docs/transforms.md ?
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.
Downsample and upsample randomly to a given ratio. Could be either here or NatureLM-specific
Summary
fraction(0, 1] andseed. Useful for quick dev iterations or ablation experiments.factor(>= 2). Useful for epoch-matching small datasets with larger ones during training.Both transforms follow the existing esp-data conventions (Pydantic config with
Literaltype discriminator,from_configclassmethod,DataBackendprotocol,register_transformregistration).Test plan
test_downsample.py: fraction accuracy, full fraction (1.0), small fraction floor (>= 1 row), manual vs config parity, config validation — all parametrized over pandas and polars backendstest_upsample.py: length correctness, row preservation, manual vs config parity, config validation — all parametrized over pandas and polars backendsMade with Cursor