-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
add split argument to Generator #7015
Conversation
…Stream, GeneratorDatasetInputStream
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Thanks for your proposed contribution @piercus.
This is a nice one!
Some comments below. Basically, I would propose to define the split
parameter just as an attribute of GeneratorConfig
instead of Generator
, GeneratorDatasetInputStream
, AbstractDatasetInputStream
and SqlDatasetReader
.
src/datasets/arrow_dataset.py
Outdated
@@ -1088,6 +1089,8 @@ def from_generator( | |||
Number of processes when downloading and generating the dataset locally. | |||
This is helpful if the dataset is made of multiple files. Multiprocessing is disabled by default. | |||
If `num_proc` is greater than one, then all list values in `gen_kwargs` must be the same length. These values will be split between calls to the generator. The number of shards will be the minimum of the shortest list in `gen_kwargs` and `num_proc`. | |||
split (`str`, defaults to `"train"`): | |||
Split name to be assigned to the dataset. |
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.
This docstring should go below <Added version="2.7.0"/>
, because the version added tag corresponds to the num_proc
parameter above split
.
I would suggest to align its type with the rest of the code as: ([`NamedSplit`], defaults to `Split.TRAIN`)
.
I would also add a specific version added tag for the split parameter: . We may eventually change this depending on the next release.
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.
just used <Added version="2.21.0"/>
, please cross-check
@@ -2074,7 +2075,8 @@ def from_generator( | |||
Keyword arguments to be passed to the `generator` callable. | |||
You can define a sharded iterable dataset by passing the list of shards in `gen_kwargs`. | |||
This can be used to improve shuffling and when iterating over the dataset with multiple workers. | |||
|
|||
split(`str`, default="train"): | |||
Split name to be assigned to the dataset. |
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.
Same comments as before.
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 also added <Added version="2.21.0"/>
please cross-check
dataset = Dataset.from_generator(data_generator, features=features, cache_dir=cache_dir) | ||
_check_generator_dataset(dataset, expected_features) | ||
dataset = Dataset.from_generator(data_generator, features=features, cache_dir=cache_dir, split=split) | ||
_check_generator_dataset(dataset, expected_features, split) | ||
|
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 would add a specific test_dataset_from_generator_split
with a parametrized split
values, such as not passing any value, passing NamedSplit("train")
, passing literal "train"
, passing other NamedSplit, etc.
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.
test_dataset_from_generator_split
added, still i have impacted _check_generator_dataset
to share the same generic check everywhere
@albertvillanova thanks for the review, please take a look |
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.
Thanks! Good work.
Just a fix of the non-passing test and a nit.
Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
@albertvillanova please take a look |
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.
Thanks for your contribution!
Note the CI action to generate the docs is failing due to an unrelated issue: https://github.com/huggingface/datasets/actions/runs/9887484572/job/27309892176?pr=7015
Therefore, if we do not want to break the generation of docs, this other PR should be merged before yours:
Thank you again! Your PR is merged. |
Show benchmarksPyArrow==8.0.0 Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
Show updated benchmarks!Benchmark: benchmark_array_xd.json
Benchmark: benchmark_getitem_100B.json
Benchmark: benchmark_indices_mapping.json
Benchmark: benchmark_iterating.json
Benchmark: benchmark_map_filter.json
|
* add split argument to Generator, from_generator, AbstractDatasetInputStream, GeneratorDatasetInputStream * split generator review feedbacks * import Split * tag added version in iterable_dataset, rollback change in _concatenate_iterable_datasets * rm useless Generator __init__ * docstring formatting Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * format docstring Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * fix test_dataset_from_generator_split[None] --------- Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
* add split argument to Generator, from_generator, AbstractDatasetInputStream, GeneratorDatasetInputStream * split generator review feedbacks * import Split * tag added version in iterable_dataset, rollback change in _concatenate_iterable_datasets * rm useless Generator __init__ * docstring formatting Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * format docstring Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * fix test_dataset_from_generator_split[None] --------- Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
* add split argument to Generator, from_generator, AbstractDatasetInputStream, GeneratorDatasetInputStream * split generator review feedbacks * import Split * tag added version in iterable_dataset, rollback change in _concatenate_iterable_datasets * rm useless Generator __init__ * docstring formatting Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * format docstring Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com> * fix test_dataset_from_generator_split[None] --------- Co-authored-by: Albert Villanova del Moral <8515462+albertvillanova@users.noreply.github.com>
Actual
When creating a multi-split dataset using generators like
It displays (for both test and val)
Expected
I would like to be able to improve this behavior by doing
It would display
and
Proposal
Current PR is adding an explicit
split
argument and replace the implicit "train" split in the following classes/function :Please share your feedbacks