DatasetGenerationError when using load_dataset

#1
by marksverdhei - opened

Breaks when trying to use load_dataset from the datasets library. Not sure why

Python version: 3.10.9
OS: Windows 11, WSL Ubuntu 22.04.1

In [1]: from datasets import load_dataset

In [2]: load_dataset("NbAiLab/norwegian-xsum")
Downloading data files: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 3/3 [00:00<00:00, 5273.64it/s]
Extracting data files: 100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 3/3 [00:00<00:00, 227.29it/s]
Generating train split: 204045 examples [00:00, 315823.63 examples/s]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
File ~/anaconda3/lib/python3.10/site-packages/datasets/builder.py:1940, in ArrowBasedBuilder._prepare_split_single(self, gen_kwargs, fpath, file_format, max_shard_size, job_id)
   1933     writer = writer_class(
   1934         features=writer._features,
   1935         path=fpath.replace("SSSSS", f"{shard_id:05d}").replace("JJJJJ", f"{job_id:05d}"),
   (...)
   1938         embed_local_files=embed_local_files,
   1939     )
-> 1940 writer.write_table(table)
   1941 num_examples_progress_update += len(table)

File ~/anaconda3/lib/python3.10/site-packages/datasets/arrow_writer.py:572, in ArrowWriter.write_table(self, pa_table, writer_batch_size)
    571 pa_table = pa_table.combine_chunks()
--> 572 pa_table = table_cast(pa_table, self._schema)
    573 if self.embed_local_files:

File ~/anaconda3/lib/python3.10/site-packages/datasets/table.py:2328, in table_cast(table, schema)
   2327 if table.schema != schema:
-> 2328     return cast_table_to_schema(table, schema)
   2329 elif table.schema.metadata != schema.metadata:

File ~/anaconda3/lib/python3.10/site-packages/datasets/table.py:2286, in cast_table_to_schema(table, schema)
   2285 if sorted(table.column_names) != sorted(features):
-> 2286     raise ValueError(f"Couldn't cast\n{table.schema}\nto\n{features}\nbecause column names don't match")
   2287 arrays = [cast_array_to_feature(table[name], feature) for name, feature in features.items()]

ValueError: Couldn't cast
builder_name: string
citation: string
config_name: string
dataset_size: int64
description: string
download_checksums: struct<data/XSUM-EMNLP18-Summary-Data-Original.tar.gz: struct<num_bytes: int64, checksum: string>, https://raw.githubusercontent.com/EdinburghNLP/XSum/master/XSum-Dataset/XSum-TRAINING-DEV-TEST-SPLIT-90-5-5.json: struct<num_bytes: int64, checksum: string>>
  child 0, data/XSUM-EMNLP18-Summary-Data-Original.tar.gz: struct<num_bytes: int64, checksum: string>
      child 0, num_bytes: int64
      child 1, checksum: string
  child 1, https://raw.githubusercontent.com/EdinburghNLP/XSum/master/XSum-Dataset/XSum-TRAINING-DEV-TEST-SPLIT-90-5-5.json: struct<num_bytes: int64, checksum: string>
      child 0, num_bytes: int64
      child 1, checksum: string
download_size: int64
features: struct<document: struct<dtype: string, _type: string>, summary: struct<dtype: string, _type: string>, id: struct<dtype: string, _type: string>>
  child 0, document: struct<dtype: string, _type: string>
      child 0, dtype: string
      child 1, _type: string
  child 1, summary: struct<dtype: string, _type: string>
      child 0, dtype: string
      child 1, _type: string
  child 2, id: struct<dtype: string, _type: string>
      child 0, dtype: string
      child 1, _type: string
homepage: string
license: string
size_in_bytes: int64
splits: struct<train: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>, validation: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>, test: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>>
  child 0, train: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>
      child 0, name: string
      child 1, num_bytes: int64
      child 2, num_examples: int64
      child 3, dataset_name: string
  child 1, validation: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>
      child 0, name: string
      child 1, num_bytes: int64
      child 2, num_examples: int64
      child 3, dataset_name: string
  child 2, test: struct<name: string, num_bytes: int64, num_examples: int64, dataset_name: string>
      child 0, name: string
      child 1, num_bytes: int64
      child 2, num_examples: int64
      child 3, dataset_name: string
supervised_keys: struct<input: string, output: string>
  child 0, input: string
  child 1, output: string
version: struct<version_str: string, major: int64, minor: int64, patch: int64>
  child 0, version_str: string
  child 1, major: int64
  child 2, minor: int64
  child 3, patch: int64
to
{'document': Value(dtype='string', id=None), 'summary': Value(dtype='string', id=None), 'id': Value(dtype='string', id=None)}
because column names don't match

The above exception was the direct cause of the following exception:

DatasetGenerationError                    Traceback (most recent call last)
Cell In[2], line 1
----> 1 load_dataset("NbAiLab/norwegian-xsum")

File ~/anaconda3/lib/python3.10/site-packages/datasets/load.py:2130, in load_dataset(path, name, data_dir, data_files, split, cache_dir, features, download_config, download_mode, verification_mode, ignore_verifications, keep_in_memory, save_infos, revision, token, use_auth_token, task, streaming, num_proc, storage_options, **config_kwargs)
   2127 try_from_hf_gcs = path not in _PACKAGED_DATASETS_MODULES
   2129 # Download and prepare data
-> 2130 builder_instance.download_and_prepare(
   2131     download_config=download_config,
   2132     download_mode=download_mode,
   2133     verification_mode=verification_mode,
   2134     try_from_hf_gcs=try_from_hf_gcs,
   2135     num_proc=num_proc,
   2136     storage_options=storage_options,
   2137 )
   2139 # Build dataset for splits
   2140 keep_in_memory = (
   2141     keep_in_memory if keep_in_memory is not None else is_small_dataset(builder_instance.info.dataset_size)
   2142 )

File ~/anaconda3/lib/python3.10/site-packages/datasets/builder.py:954, in DatasetBuilder.download_and_prepare(self, output_dir, download_config, download_mode, verification_mode, ignore_verifications, try_from_hf_gcs, dl_manager, base_path, use_auth_token, file_format, max_shard_size, num_proc, storage_options, **download_and_prepare_kwargs)
    952     if num_proc is not None:
    953         prepare_split_kwargs["num_proc"] = num_proc
--> 954     self._download_and_prepare(
    955         dl_manager=dl_manager,
    956         verification_mode=verification_mode,
    957         **prepare_split_kwargs,
    958         **download_and_prepare_kwargs,
    959     )
    960 # Sync info
    961 self.info.dataset_size = sum(split.num_bytes for split in self.info.splits.values())

File ~/anaconda3/lib/python3.10/site-packages/datasets/builder.py:1049, in DatasetBuilder._download_and_prepare(self, dl_manager, verification_mode, **prepare_split_kwargs)
   1045 split_dict.add(split_generator.split_info)
   1047 try:
   1048     # Prepare split will record examples associated to the split
-> 1049     self._prepare_split(split_generator, **prepare_split_kwargs)
   1050 except OSError as e:
   1051     raise OSError(
   1052         "Cannot find data file. "
   1053         + (self.manual_download_instructions or "")
   1054         + "\nOriginal error:\n"
   1055         + str(e)
   1056     ) from None

File ~/anaconda3/lib/python3.10/site-packages/datasets/builder.py:1813, in ArrowBasedBuilder._prepare_split(self, split_generator, file_format, num_proc, max_shard_size)
   1811 job_id = 0
   1812 with pbar:
-> 1813     for job_id, done, content in self._prepare_split_single(
   1814         gen_kwargs=gen_kwargs, job_id=job_id, **_prepare_split_args
   1815     ):
   1816         if done:
   1817             result = content

File ~/anaconda3/lib/python3.10/site-packages/datasets/builder.py:1958, in ArrowBasedBuilder._prepare_split_single(self, gen_kwargs, fpath, file_format, max_shard_size, job_id)
   1956     if isinstance(e, SchemaInferenceError) and e.__context__ is not None:
   1957         e = e.__context__
-> 1958     raise DatasetGenerationError("An error occurred while generating the dataset") from e
   1960 yield job_id, True, (total_num_examples, total_num_bytes, writer._features, num_shards, shard_lengths)

DatasetGenerationError: An error occurred while generating the dataset

I get the same error @marksverdhei - would be great if you could fix this! πŸ˜€
However, I downloaded the .arrow files from test, train, and validation and got it to work. You would just need to find a new way to split the data:
Ex. of how I did this for the train set:
train_dataset = load_arrow_file('/PATH/train.arrow')
train_dataset = Dataset.from_pandas(train_dataset)
tokenized_train_dataset = train_dataset.map(preprocess_function, batched=True)

Now it is preprocessed and tokenized according to the summarization task guide from HF: https://huggingface.co/docs/transformers/tasks/summarization

Sign up or log in to comment