-
Notifications
You must be signed in to change notification settings - Fork 57
feat: add allow_resize for 1:N and N:1 generation patterns #286
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
Draft
andreatgretel
wants to merge
3
commits into
main
Choose a base branch
from
andreatgretel/feat/allow-resize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Example: Using allow_resize for 1:N expansion and N:1 retraction.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import data_designer.config as dd | ||
| from data_designer.interface import DataDesigner | ||
| from data_designer.lazy_heavy_imports import pd | ||
|
|
||
|
|
||
| @dd.custom_column_generator(required_columns=["topic"], side_effect_columns=["variation_id"]) | ||
| def expand_to_questions(df: pd.DataFrame) -> pd.DataFrame: | ||
| """Generate 3 questions per topic (1:N expansion).""" | ||
| rows = [] | ||
| for _, row in df.iterrows(): | ||
| for i in range(3): | ||
| rows.append( | ||
| { | ||
| "topic": row["topic"], | ||
| "question": f"Question {i + 1} about {row['topic']}?", | ||
| "variation_id": i, | ||
| } | ||
| ) | ||
| return pd.DataFrame(rows) | ||
|
|
||
|
|
||
| @dd.custom_column_generator(required_columns=["topic", "score"]) | ||
| def filter_high_scores(df: pd.DataFrame) -> pd.DataFrame: | ||
| """Keep only records with score > 0.5 (N:1 retraction).""" | ||
| filtered = df[df["score"] > 0.5].copy() | ||
| filtered["status"] = "passed" | ||
| return filtered | ||
|
|
||
|
|
||
| def run_expansion_example() -> None: | ||
| """3 topics -> 9 questions.""" | ||
| data_designer = DataDesigner() | ||
| config_builder = dd.DataDesignerConfigBuilder() | ||
|
|
||
| config_builder.add_column( | ||
| dd.SamplerColumnConfig( | ||
| name="topic", | ||
| sampler_type=dd.SamplerType.CATEGORY, | ||
| params=dd.CategorySamplerParams(values=["Python", "ML", "Data"]), | ||
| ) | ||
| ) | ||
| config_builder.add_column( | ||
| dd.CustomColumnConfig( | ||
| name="question", | ||
| generator_function=expand_to_questions, | ||
| generation_strategy=dd.GenerationStrategy.FULL_COLUMN, | ||
| allow_resize=True, | ||
| ) | ||
| ) | ||
|
|
||
| preview = data_designer.preview(config_builder=config_builder, num_records=3) | ||
| print(f"Expansion: 3 -> {len(preview.dataset)} records") | ||
| print(preview.dataset.to_string()) | ||
|
|
||
|
|
||
| def run_retraction_example() -> None: | ||
| """10 records -> ~5 (filtered).""" | ||
| data_designer = DataDesigner() | ||
| config_builder = dd.DataDesignerConfigBuilder() | ||
|
|
||
| config_builder.add_column( | ||
| dd.SamplerColumnConfig( | ||
| name="topic", | ||
| sampler_type=dd.SamplerType.CATEGORY, | ||
| params=dd.CategorySamplerParams(values=["A", "B", "C", "D", "E"]), | ||
| ) | ||
| ) | ||
| config_builder.add_column( | ||
| dd.SamplerColumnConfig( | ||
| name="score", | ||
| sampler_type=dd.SamplerType.UNIFORM, | ||
| params=dd.UniformSamplerParams(low=0.0, high=1.0), | ||
| ) | ||
| ) | ||
| config_builder.add_column( | ||
| dd.CustomColumnConfig( | ||
| name="status", | ||
| generator_function=filter_high_scores, | ||
| generation_strategy=dd.GenerationStrategy.FULL_COLUMN, | ||
| allow_resize=True, | ||
| ) | ||
| ) | ||
|
|
||
| preview = data_designer.preview(config_builder=config_builder, num_records=10) | ||
| print(f"Retraction: 10 -> {len(preview.dataset)} records") | ||
| print(preview.dataset.to_string()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| run_expansion_example() | ||
| # run_retraction_example() |
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
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should elevate this to a property on the base column config (default is
False), which you can override in custom columns and plugins.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was the initial solution, then I ended up doing a mixin instead.
Thought it was a bit opaque for plugins specifically, that they developer to find out about a specific attribute/property 🤔 But it makes things simpler I suppose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pattern we already use for custom emojis. Also the
required_columnsandside_effect_columns(these ones have to be set, though).