-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global step for merging datasets (#9)
Step uses the `inputs` key as the datasets to be combined, `output` as the new dataset name and can optionally shuffle the resulting dataset.
- Loading branch information
1 parent
22d61e5
commit c65e202
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
::: ragfoundry.processing.global_steps.aggregation |
This file contains 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 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,31 @@ | ||
from datasets import concatenate_datasets | ||
|
||
from ..step import GlobalStep | ||
|
||
|
||
class MergeDatasets(GlobalStep): | ||
""" | ||
Step for merging datasets. | ||
Merge is done using concatenation. Optional shuffling by providing a seed. | ||
""" | ||
|
||
def __init__(self, output, shuffle=None, **kwargs): | ||
""" | ||
Args: | ||
output (str): Name of the output dataset. Should be unique. | ||
shuffle (int, optional): seed for shuffling. Default is None. | ||
""" | ||
super().__init__(**kwargs) | ||
self.output = output | ||
self.shuffle = shuffle | ||
self.completed = False | ||
self.cache_step = False | ||
|
||
def process(self, dataset_name, datasets, **kwargs): | ||
if not self.completed: | ||
data = concatenate_datasets([datasets[name] for name in self.inputs]) | ||
if self.shuffle: | ||
data = data.shuffle(self.shuffle) | ||
datasets[self.output] = data | ||
self.completed = True |