Unable to load multi class classification datasets
Opened by ysahil97 (closed)

### Describe the bug

I've been playing around with huggingface library, mostly with `datasets` and wanted to download the multi class classification datasets to fine tune BERT on this task. ([link](https://huggingface.co/docs/transformers/training#train-with-pytorch-trainer)).

While loading the dataset, I'm getting the following error snippet.
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[44], line 3
      1 from datasets import load_dataset
----> 3 imdb_dataset = load_dataset("yelp_review_full")
      4 imdb_dataset

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/load.py:1719, in load_dataset(path, name, data_dir, data_files, split, cache_dir, features, download_config, download_mode, ignore_verifications, keep_in_memory, save_infos, revision, use_auth_token, task, streaming, **config_kwargs)
   1716 ignore_verifications = ignore_verifications or save_infos
   1718 # Create a dataset builder
-> 1719 builder_instance = load_dataset_builder(
   1720     path=path,
   1721     name=name,
   1722     data_dir=data_dir,
   1723     data_files=data_files,
   1724     cache_dir=cache_dir,
   1725     features=features,
   1726     download_config=download_config,
   1727     download_mode=download_mode,
   1728     revision=revision,
   1729     use_auth_token=use_auth_token,
   1730     **config_kwargs,
   1731 )
   1733 # Return iterable dataset in case of streaming
   1734 if streaming:

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/load.py:1523, in load_dataset_builder(path, name, data_dir, data_files, cache_dir, features, download_config, download_mode, revision, use_auth_token, **config_kwargs)
   1520     raise ValueError(error_msg)
   1522 # Instantiate the dataset builder
-> 1523 builder_instance: DatasetBuilder = builder_cls(
   1524     cache_dir=cache_dir,
   1525     config_name=config_name,
   1526     data_dir=data_dir,
   1527     data_files=data_files,
   1528     hash=hash,
   1529     features=features,
   1530     use_auth_token=use_auth_token,
   1531     **builder_kwargs,
   1532     **config_kwargs,
   1533 )
   1535 return builder_instance

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/builder.py:1292, in GeneratorBasedBuilder.__init__(self, writer_batch_size, *args, **kwargs)
   1291 def __init__(self, *args, writer_batch_size=None, **kwargs):
-> 1292     super().__init__(*args, **kwargs)
   1293     # Batch size used by the ArrowWriter
   1294     # It defines the number of samples that are kept in memory before writing them
   1295     # and also the length of the arrow chunks
   1296     # None means that the ArrowWriter will use its default value
   1297     self._writer_batch_size = writer_batch_size or self.DEFAULT_WRITER_BATCH_SIZE

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/builder.py:312, in DatasetBuilder.__init__(self, cache_dir, config_name, hash, base_path, info, features, use_auth_token, repo_id, data_files, data_dir, name, **config_kwargs)
    309 # prepare info: DatasetInfo are a standardized dataclass across all datasets
    310 # Prefill datasetinfo
    311 if info is None:
--> 312     info = self.get_exported_dataset_info()
    313     info.update(self._info())
    314     info.builder_name = self.name

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/builder.py:412, in DatasetBuilder.get_exported_dataset_info(self)
    400 def get_exported_dataset_info(self) -> DatasetInfo:
    401     """Empty DatasetInfo if doesn't exist
    402 
    403     Example:
   (...)
    410     ```
    411     """
--> 412     return self.get_all_exported_dataset_infos().get(self.config.name, DatasetInfo())

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/builder.py:398, in DatasetBuilder.get_all_exported_dataset_infos(cls)
    385 @classmethod
    386 def get_all_exported_dataset_infos(cls) -> DatasetInfosDict:
    387     """Empty dict if doesn't exist
    388 
    389     Example:
   (...)
    396     ```
    397     """
--> 398     return DatasetInfosDict.from_directory(cls.get_imported_module_dir())

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/info.py:370, in DatasetInfosDict.from_directory(cls, dataset_infos_dir)
    368     dataset_metadata = DatasetMetadata.from_readme(Path(dataset_infos_dir) / "README.md")
    369     if "dataset_info" in dataset_metadata:
--> 370         return cls.from_metadata(dataset_metadata)
    371 if os.path.exists(os.path.join(dataset_infos_dir, config.DATASETDICT_INFOS_FILENAME)):
    372     # this is just to have backward compatibility with dataset_infos.json files
    373     with open(os.path.join(dataset_infos_dir, config.DATASETDICT_INFOS_FILENAME), encoding="utf-8") as f:

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/info.py:396, in DatasetInfosDict.from_metadata(cls, dataset_metadata)
    387     return cls(
    388         {
    389             dataset_info_yaml_dict.get("config_name", "default"): DatasetInfo._from_yaml_dict(
   (...)
    393         }
    394     )
    395 else:
--> 396     dataset_info = DatasetInfo._from_yaml_dict(dataset_metadata["dataset_info"])
    397     dataset_info.config_name = dataset_metadata["dataset_info"].get("config_name", "default")
    398     return cls({dataset_info.config_name: dataset_info})

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/info.py:332, in DatasetInfo._from_yaml_dict(cls, yaml_data)
    330 yaml_data = copy.deepcopy(yaml_data)
    331 if yaml_data.get("features") is not None:
--> 332     yaml_data["features"] = Features._from_yaml_list(yaml_data["features"])
    333 if yaml_data.get("splits") is not None:
    334     yaml_data["splits"] = SplitDict._from_yaml_list(yaml_data["splits"])

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1745, in Features._from_yaml_list(cls, yaml_data)
   1742     else:
   1743         raise TypeError(f"Expected a dict or a list but got {type(obj)}: {obj}")
-> 1745 return cls.from_dict(from_yaml_inner(yaml_data))

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1741, in Features._from_yaml_list.<locals>.from_yaml_inner(obj)
   1739 elif isinstance(obj, list):
   1740     names = [_feature.pop("name") for _feature in obj]
-> 1741     return {name: from_yaml_inner(_feature) for name, _feature in zip(names, obj)}
   1742 else:
   1743     raise TypeError(f"Expected a dict or a list but got {type(obj)}: {obj}")

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1741, in <dictcomp>(.0)
   1739 elif isinstance(obj, list):
   1740     names = [_feature.pop("name") for _feature in obj]
-> 1741     return {name: from_yaml_inner(_feature) for name, _feature in zip(names, obj)}
   1742 else:
   1743     raise TypeError(f"Expected a dict or a list but got {type(obj)}: {obj}")

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1736, in Features._from_yaml_list.<locals>.from_yaml_inner(obj)
   1734             return {"_type": snakecase_to_camelcase(obj["dtype"])}
   1735     else:
-> 1736         return from_yaml_inner(obj["dtype"])
   1737 else:
   1738     return {"_type": snakecase_to_camelcase(_type), **unsimplify(obj)[_type]}

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1738, in Features._from_yaml_list.<locals>.from_yaml_inner(obj)
   1736             return from_yaml_inner(obj["dtype"])
   1737     else:
-> 1738         return {"_type": snakecase_to_camelcase(_type), **unsimplify(obj)[_type]}
   1739 elif isinstance(obj, list):
   1740     names = [_feature.pop("name") for _feature in obj]

File /work/pi_adrozdov_umass_edu/syerawar_umass_edu/envs/vadops/lib/python3.10/site-packages/datasets/features/features.py:1706, in Features._from_yaml_list.<locals>.unsimplify(feature)
   1704 if isinstance(feature.get("class_label"), dict) and isinstance(feature["class_label"].get("names"), dict):
   1705     label_ids = sorted(feature["class_label"]["names"])
-> 1706     if label_ids and label_ids != list(range(label_ids[-1] + 1)):
   1707         raise ValueError(
   1708             f"ClassLabel expected a value for all label ids [0:{label_ids[-1] + 1}] but some ids are missing."
   1709         )
   1710     feature["class_label"]["names"] = [feature["class_label"]["names"][label_id] for label_id in label_ids]

TypeError: can only concatenate str (not "int") to str
```

The same issue happens when I try to load `go-emotions` multi class classification dataset. Could somebody guide me on how to fix this issue?


### Steps to reproduce the bug

Run the following code snippet in a python script/ notebook cell:

```
from datasets import load_dataset

yelp_dataset = load_dataset("yelp_review_full")
yelp_dataset
```

### Expected behavior

The dataset should be loaded perfectly, which showing the train, test and unsupervised splits with the basic data statistics

### Environment info

- `datasets` version: 2.6.1
- Platform: Linux-5.4.0-124-generic-x86_64-with-glibc2.31
- Python version: 3.10.9
- PyArrow version: 8.0.0
- Pandas version: 1.5.3

Comments: Hi ! This sounds related to https://github.com/huggingface/datasets/issues/5406

Updating `datasets` fixes the issue ;)

Thanks @lhoestq!

I'll close this issue now.