Skip to content

Commit

Permalink
Minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
mariosasko committed Aug 30, 2022
1 parent b642dd9 commit 01af906
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/datasets/data_files.py
Expand Up @@ -80,10 +80,10 @@ class Url(str):
DEFAULT_PATTERNS_ALL,
]
METADATA_PATTERNS = [
"metadata.jsonl",
"**/metadata.jsonl",
"metadata.csv",
"**/metadata.csv",
"metadata.jsonl",
"**/metadata.jsonl",
] # metadata file for ImageFolder and AudioFolder
WILDCARD_CHARACTERS = "*[]"
FILES_TO_IGNORE = ["README.md", "config.json", "dataset_infos.json", "dummy_data.zip", "dataset_dict.json"]
Expand Down
Expand Up @@ -70,7 +70,7 @@ class FolderBasedBuilder(datasets.GeneratorBasedBuilder):
EXTENSIONS: List[str]

SKIP_CHECKSUM_COMPUTATION_BY_DEFAULT: bool = True
METADATA_FILENAMES: List[str] = ["metadata.jsonl", "metadata.csv"]
METADATA_FILENAMES: List[str] = ["metadata.csv", "metadata.jsonl"]

def _info(self):
return datasets.DatasetInfo(features=self.config.features)
Expand Down Expand Up @@ -251,12 +251,12 @@ def _split_files_and_archives(self, data_files):

def _read_metadata(self, metadata_file):
metadata_file_ext = os.path.splitext(metadata_file)[1][1:]
if metadata_file_ext == "jsonl":
with open(metadata_file, "rb") as f:
return paj.read_json(f)
else:
if metadata_file_ext == "csv":
# Use `pd.read_csv` (although slower) instead of `pyarrow.csv.read_csv` for reading CSV files for consistency with the CSV packaged module
return pa.Table.from_pandas(pd.read_csv(metadata_file))
else:
with open(metadata_file, "rb") as f:
return paj.read_json(f)

def _generate_examples(self, files, metadata_files, split_name, add_metadata, add_labels):
split_metadata_files = metadata_files.get(split_name, [])
Expand All @@ -268,6 +268,13 @@ def _generate_examples(self, files, metadata_files, split_name, add_metadata, ad
metadata_dict = None
downloaded_metadata_file = None

if split_metadata_files:
metadata_ext = set(
os.path.splitext(downloaded_metadata_file)[1][1:]
for _, downloaded_metadata_file in split_metadata_files
)
metadata_ext = metadata_ext.pop()

file_idx = 0
for original_file, downloaded_file_or_dir in files:
if original_file is not None:
Expand Down Expand Up @@ -311,7 +318,7 @@ def _generate_examples(self, files, metadata_files, split_name, add_metadata, ad
}
else:
raise ValueError(
f"One or several metadata.jsonl were found, but not in the same directory or in a parent directory of {downloaded_file_or_dir}."
f"One or several metadata.{metadata_ext} were found, but not in the same directory or in a parent directory of {downloaded_file_or_dir}."
)
if metadata_dir is not None and downloaded_metadata_file is not None:
file_relpath = os.path.relpath(original_file, metadata_dir)
Expand All @@ -323,7 +330,7 @@ def _generate_examples(self, files, metadata_files, split_name, add_metadata, ad
sample_metadata = metadata_dict[file_relpath]
else:
raise ValueError(
f"One or several metadata.jsonl were found, but not in the same directory or in a parent directory of {downloaded_file_or_dir}."
f"One or several metadata.{metadata_ext} were found, but not in the same directory or in a parent directory of {downloaded_file_or_dir}."
)
else:
sample_metadata = {}
Expand Down Expand Up @@ -380,7 +387,7 @@ def _generate_examples(self, files, metadata_files, split_name, add_metadata, ad
}
else:
raise ValueError(
f"One or several metadata.jsonl were found, but not in the same directory or in a parent directory of {downloaded_dir_file}."
f"One or several metadata.{metadata_ext} were found, but not in the same directory or in a parent directory of {downloaded_dir_file}."
)
if metadata_dir is not None and downloaded_metadata_file is not None:
downloaded_dir_file_relpath = os.path.relpath(downloaded_dir_file, metadata_dir)
Expand All @@ -392,7 +399,7 @@ def _generate_examples(self, files, metadata_files, split_name, add_metadata, ad
sample_metadata = metadata_dict[downloaded_dir_file_relpath]
else:
raise ValueError(
f"One or several metadata.jsonl were found, but not in the same directory or in a parent directory of {downloaded_dir_file}."
f"One or several metadata.{metadata_ext} were found, but not in the same directory or in a parent directory of {downloaded_dir_file}."
)
else:
sample_metadata = {}
Expand Down

1 comment on commit 01af906

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show benchmarks

PyArrow==6.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.007145 / 0.011353 (-0.004208) 0.003487 / 0.011008 (-0.007521) 0.028452 / 0.038508 (-0.010056) 0.028935 / 0.023109 (0.005825) 0.321821 / 0.275898 (0.045923) 0.360757 / 0.323480 (0.037277) 0.005272 / 0.007986 (-0.002714) 0.004186 / 0.004328 (-0.000142) 0.006554 / 0.004250 (0.002303) 0.039648 / 0.037052 (0.002596) 0.317004 / 0.258489 (0.058515) 0.358948 / 0.293841 (0.065108) 0.028457 / 0.128546 (-0.100089) 0.009227 / 0.075646 (-0.066419) 0.247274 / 0.419271 (-0.171997) 0.045368 / 0.043533 (0.001835) 0.309048 / 0.255139 (0.053909) 0.334134 / 0.283200 (0.050934) 0.088123 / 0.141683 (-0.053560) 1.506514 / 1.452155 (0.054359) 1.527429 / 1.492716 (0.034713)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.202903 / 0.018006 (0.184897) 0.409625 / 0.000490 (0.409135) 0.001670 / 0.000200 (0.001470) 0.000077 / 0.000054 (0.000022)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.020798 / 0.037411 (-0.016613) 0.090974 / 0.014526 (0.076448) 0.104180 / 0.176557 (-0.072377) 0.146569 / 0.737135 (-0.590566) 0.103126 / 0.296338 (-0.193213)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.413910 / 0.215209 (0.198701) 4.146325 / 2.077655 (2.068671) 1.825984 / 1.504120 (0.321864) 1.634204 / 1.541195 (0.093009) 1.652661 / 1.468490 (0.184171) 0.443339 / 4.584777 (-4.141438) 3.259124 / 3.745712 (-0.486588) 1.828214 / 5.269862 (-3.441648) 1.194385 / 4.565676 (-3.371291) 0.052524 / 0.424275 (-0.371751) 0.010672 / 0.007607 (0.003065) 0.523976 / 0.226044 (0.297931) 5.251915 / 2.268929 (2.982987) 2.261936 / 55.444624 (-53.182689) 1.924780 / 6.876477 (-4.951697) 2.000905 / 2.142072 (-0.141167) 0.563625 / 4.805227 (-4.241602) 0.117829 / 6.500664 (-6.382835) 0.062360 / 0.075469 (-0.013109)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.499635 / 1.841788 (-0.342153) 12.102007 / 8.074308 (4.027699) 26.092167 / 10.191392 (15.900775) 0.873760 / 0.680424 (0.193336) 0.604612 / 0.534201 (0.070411) 0.347164 / 0.579283 (-0.232119) 0.385851 / 0.434364 (-0.048513) 0.237460 / 0.540337 (-0.302877) 0.247157 / 1.386936 (-1.139779)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.005534 / 0.011353 (-0.005819) 0.003462 / 0.011008 (-0.007547) 0.026640 / 0.038508 (-0.011868) 0.027050 / 0.023109 (0.003941) 0.391984 / 0.275898 (0.116086) 0.463136 / 0.323480 (0.139656) 0.003371 / 0.007986 (-0.004614) 0.004033 / 0.004328 (-0.000295) 0.004589 / 0.004250 (0.000338) 0.034285 / 0.037052 (-0.002767) 0.410619 / 0.258489 (0.152130) 0.439189 / 0.293841 (0.145348) 0.026729 / 0.128546 (-0.101818) 0.009226 / 0.075646 (-0.066420) 0.248159 / 0.419271 (-0.171112) 0.045474 / 0.043533 (0.001942) 0.366919 / 0.255139 (0.111780) 0.431467 / 0.283200 (0.148267) 0.088132 / 0.141683 (-0.053551) 1.486404 / 1.452155 (0.034249) 1.514804 / 1.492716 (0.022088)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.238792 / 0.018006 (0.220786) 0.390218 / 0.000490 (0.389729) 0.006673 / 0.000200 (0.006473) 0.000090 / 0.000054 (0.000035)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.021605 / 0.037411 (-0.015806) 0.092410 / 0.014526 (0.077884) 0.104920 / 0.176557 (-0.071637) 0.139163 / 0.737135 (-0.597972) 0.104794 / 0.296338 (-0.191545)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.469958 / 0.215209 (0.254749) 4.697180 / 2.077655 (2.619525) 2.438633 / 1.504120 (0.934513) 2.247222 / 1.541195 (0.706027) 2.272050 / 1.468490 (0.803560) 0.443799 / 4.584777 (-4.140978) 3.305805 / 3.745712 (-0.439907) 1.779593 / 5.269862 (-3.490268) 1.082863 / 4.565676 (-3.482813) 0.052527 / 0.424275 (-0.371748) 0.010979 / 0.007607 (0.003372) 0.573949 / 0.226044 (0.347905) 5.743210 / 2.268929 (3.474282) 2.835752 / 55.444624 (-52.608872) 2.478871 / 6.876477 (-4.397606) 2.569353 / 2.142072 (0.427281) 0.556916 / 4.805227 (-4.248312) 0.117791 / 6.500664 (-6.382873) 0.063180 / 0.075469 (-0.012289)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.576356 / 1.841788 (-0.265432) 12.468393 / 8.074308 (4.394085) 26.366309 / 10.191392 (16.174917) 0.924414 / 0.680424 (0.243991) 0.653393 / 0.534201 (0.119192) 0.344431 / 0.579283 (-0.234852) 0.392442 / 0.434364 (-0.041921) 0.229312 / 0.540337 (-0.311026) 0.233518 / 1.386936 (-1.153418)

CML watermark

Please sign in to comment.