SergeiGKS/huggingface-dataset-issues huggingface dataset:
Issue: Can't import datasets AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import)

Comment:
i am also facing this issue


```
----> 1 import datasets
      3 dataset = datasets.load_dataset("ucberkeley-dlab/measuring-hate-speech", "binary")
      4 df = dataset["train"].to_pandas()

File ~/.pyenv/versions/3.10.9/lib/python3.10/site-packages/datasets/__init__.py:52
     50 from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
     51 from .info import DatasetInfo, MetricInfo
---> 52 from .inspect import (
     53     get_dataset_config_info,
     54     get_dataset_config_names,
     55     get_dataset_infos,
     56     get_dataset_split_names,
     57     inspect_dataset,
     58     inspect_metric,
     59     list_datasets,
     60     list_metrics,
     61 )
     62 from .iterable_dataset import IterableDataset
     63 from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric

File ~/.pyenv/versions/3.10.9/lib/python3.10/site-packages/datasets/inspect.py:30
     28 from .download.streaming_download_manager import StreamingDownloadManager
...
---> 16 logger = datasets.utils.logging.get_logger(__name__)
     19 if datasets.config.PYARROW_VERSION.major >= 7:
     21     def pa_table_to_pylist(table):
```
Issue: Can't import datasets AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import)

Comment:
I am facing the same question. And this happens when i installing `evaluate` package while `jupyter notebook` running. I'm not sure if the error occured because of trying to import the package installed when the notebook is running.  Surpringly when i stop the notebook and rerun, the issue has been solved itself. Hope this will be helpful : )
Issue: Can't import datasets AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import)

Comment:
I also got this error.
It helped me to find the python process and kill it, then restart the kernel and the error disappeared.
Issue: Can't import datasets AttributeError: partially initialized module 'datasets' has no attribute 'utils' (most likely due to a circular import)

Comment:
> I also got this error. It helped me to find the python process and kill it, then restart the kernel and the error disappeared.

Yes!
Issue: Dataset Viewer issue for asaxena1990/Dummy_dataset

Comment:
Seems to be linked to the use of the undocumented `_resolve_features` method in the dataset viewer backend:

```
>>> from datasets import load_dataset
>>> dataset = load_dataset("asaxena1990/Dummy_dataset", name="asaxena1990--Dummy_dataset", split="train", streaming=True)
Using custom data configuration asaxena1990--Dummy_dataset-4a704ed7e5627563
>>> dataset._resolve_features()
Failed to read file 'https://huggingface.co/datasets/asaxena1990/Dummy_dataset/resolve/06885879a8bdd767d2d27695484fc6c83244617a/dummy_dataset_train.json' with error <class 'pyarrow.lib.ArrowInvalid'>: JSON parse error: Column() changed from object to array in row 0
Traceback (most recent call last):
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 109, in _generate_tables
    pa_table = paj.read_json(
  File "pyarrow/_json.pyx", line 246, in pyarrow._json.read_json
  File "pyarrow/error.pxi", line 143, in pyarrow.lib.pyarrow_internal_check_status
  File "pyarrow/error.pxi", line 99, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: JSON parse error: Column() changed from object to array in row 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 1261, in _resolve_features
    features = _infer_features_from_batch(self._head())
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 686, in _head
    return _examples_to_batch([x for key, x in islice(self._iter(), n)])
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 686, in <listcomp>
    return _examples_to_batch([x for key, x in islice(self._iter(), n)])
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 708, in _iter
    yield from ex_iterable
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 112, in __iter__
    yield from self.generate_examples_fn(**self.kwargs)
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/iterable_dataset.py", line 651, in wrapper
    for key, table in generate_tables_fn(**kwargs):
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/packaged_modules/json/json.py", line 137, in _generate_tables
    f"This JSON file contain the following fields: {str(list(dataset.keys()))}. "
AttributeError: 'list' object has no attribute 'keys'
```

Pinging @huggingface/datasets
Issue: Dataset Viewer issue for asaxena1990/Dummy_dataset

Comment:
Hi ! JSON files containing a list of object are not supported yet, you can use JSON Lines files instead in the meantime
```json
{"text": "can I know this?", "intent": "Know", "type": "Test"}
{"text": "can I know this?", "intent": "Know", "type": "Test"}
...
```
Issue: Dataset Viewer issue for timit_asr

Comment:
Yes, the dataset viewer is based on `datasets`, and the following does not work:

```
>>> from datasets import get_dataset_split_names
>>> get_dataset_split_names('timit_asr')
Downloading builder script: 7.48kB [00:00, 6.69MB/s]
Traceback (most recent call last):
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 354, in get_dataset_config_info
    for split_generator in builder._split_generators(
  File "/home/slesage/.cache/huggingface/modules/datasets_modules/datasets/timit_asr/43f9448dd5db58e95ee48a277f466481b151f112ea53e27f8173784da9254fb2/timit_asr.py", line 117, in _split_generators
    data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
  File "/home/slesage/.pyenv/versions/3.9.6/lib/python3.9/posixpath.py", line 231, in expanduser
    path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not NoneType

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 404, in get_dataset_split_names
    info = get_dataset_config_info(
  File "/home/slesage/hf/datasets-server/services/worker/.venv/lib/python3.9/site-packages/datasets/inspect.py", line 359, in get_dataset_config_info
    raise SplitsNotFoundError("The split names could not be parsed from the dataset config.") from err
datasets.inspect.SplitsNotFoundError: The split names could not be parsed from the dataset config.
```

cc @huggingface/datasets
Issue: Dataset Viewer issue for timit_asr

Comment:
Due to license restriction, this dataset needs manual downloading of the original data.

This information is in the dataset card: https://huggingface.co/datasets/timit_asr
> The dataset needs to be downloaded manually from https://catalog.ldc.upenn.edu/LDC93S1
Issue: Dataset Viewer issue for timit_asr

Comment:
Maybe a better error message for datasets that need manual downloading? @severo 

Maybe we can raise a specific excpetion as done from `load_dataset`...
Issue: Dataset Viewer issue for timit_asr

Comment:
The preview is now disabled (and a descriptive warning is displayed) for datasets requiring manual download. See:

![timit_asr-manual-download](https://user-images.githubusercontent.com/8515462/193578572-3d21b790-f848-4257-9e9b-7cab3d76a269.png)
Issue: datasets generate large arrow file

Comment:
Hi ! The cache files are the results of all the transforms you applied to the dataset using `map` for example.
Did you run a transform that could potentially blow up the size of the dataset ?
Issue: datasets generate large arrow file

Comment:
@lhoestq,
I don't remember, but I can't imagine what kind of transform may generate data that grow over 200 times in size. 
I think maybe it doesn' matter, it's just cache after all.
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
I don't know the main problem but it looks like, it is ignoring the last directory in your case. So, create a directory called 'zzz' in the same folder as train, validation and test. if it doesn't work, create a directory called "aaa". It worked for me.
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@SamSamhuns could you please try to load it with the current main-branch version of `datasets`? I suppose the problem is that it tries to get splits names from filenames in this case, ignoring directories names,  but `val` wasn't in keywords at that time, but it was fixed recently in this PR  https://github.com/huggingface/datasets/pull/4844.
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
I have a similar problem.
When I try to create `data_infos.json` using `datasets-cli test Peter.py --save_infos --all_configs` I get an error:
`ValueError: Unknown split "test". Should be one of ['train'].`

The `data_infos.json` is created perfectly fine when I use only one split - `datasets.Split.TRAIN`

@polinaeterna  Could you help here please?

You can find the code here: https://huggingface.co/datasets/sberbank-ai/Peter/tree/add_splits (add_splits branch)
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@skalinin It seems the `dataset_infos.json` of your dataset is missing the info on the test split (and `datasets-cli` doesn't ignore the cached infos at the moment, which is a known bug), so your issue is not related to this one. I think you can fix your issue by deleting all the cached `dataset_infos.json` (in the local repo and in `~/.cache/huggingface/modules`) before running the `datasets-cli test` command. Let us know if that doesn't help, and I can try to generate it myself.
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
This code indeed behaves as expected on `main`. But suppose the `val_234.png` is renamed to some other value not containing one of [these](https://github.com/huggingface/datasets/blob/38c8c725f3996ff1ff03f6fd461aa6d645321034/src/datasets/data_files.py#L31) keywords, in that case, this issue becomes relevant again because the real cause of it is the order in which we check the predefined split patterns to assign data files to each split - first we assign data files based on filenames, and only if this fails meaning not a single split found (`val` is not recognized here in the older versions of `datasets`, which results in an empty `validation` split), do we assign based on directory names.

@polinaeterna @lhoestq Perhaps one way to fix this would be to swap the [order](https://github.com/huggingface/datasets/blob/38c8c725f3996ff1ff03f6fd461aa6d645321034/src/datasets/data_files.py#L78-L79) of the patterns if `data_dir` is specified (or if `load_dataset(data_dir)` is called)?
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
> @polinaeterna @lhoestq Perhaps one way to fix this would be to swap the [order](https://github.com/huggingface/datasets/blob/38c8c725f3996ff1ff03f6fd461aa6d645321034/src/datasets/data_files.py#L78-L79) of the patterns if data_dir is specified (or if load_dataset(data_dir) is called)?

yes that makes sense !
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
Looks like the `val/validation` dir name issue is fixed with the current main-branch version of the `datasets` repository. 

> @polinaeterna @lhoestq Perhaps one way to fix this would be to swap the [order](https://github.com/huggingface/datasets/blob/38c8c725f3996ff1ff03f6fd461aa6d645321034/src/datasets/data_files.py#L78-L79) of the patterns if data_dir is specified (or if load_dataset(data_dir) is called)?

I agree with this as well. I would expect higher precedence to the directory name over the file name. Right now if I place a single file named `train_00001.jpg` under the `validation` directory, `load_dataset` cannot find the validation split.
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
> @polinaeterna @lhoestq Perhaps one way to fix this would be to swap the [order](https://github.com/huggingface/datasets/blob/38c8c725f3996ff1ff03f6fd461aa6d645321034/src/datasets/data_files.py#L78-L79) of the patterns if data_dir is specified (or if load_dataset(data_dir) is called)?

Sounds good to me! opened a PR: https://github.com/huggingface/datasets/pull/4985
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
Hi there @polinaeterna @mariosasko ! I have installed 5.2.3.dev0, which should have this fix. Unfortunately, I am still getting the error:
`ValueError: Unknown split "validation". Should be one of ['train'].` When I call `load_dataset("csv", data_files=files, split=split)`

Any help would be greatly appreciated!
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
Hi there @polinaeterna . My local CSV files are stored as follows:
binding:
---------- tune.csv
---------- public_data:
--------------------------- train.csv

`self.list_shards(split)` sucessfully finds the relevant data files
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@shaneacton do you have `validation.csv`/`val.csv`/`valid.csv`/`dev.csv` file in your data folder? I can't find it in the structure you provided
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@polinaeterna no, does the name of the split need to match the name of the file exactly?

But my train file is not actually named 'train.py' its called 'XXXXXXXXX_train_XXXXXXXX.csv'
And the code works fine for train, but fails for validation.
Does the file name need to _contain_ the split name?
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@shaneacton what files do you expect to be included in "validation" split? yes, you should somehow indicate that a file belongs to a certain split - either by including split name in a filename or by putting it into a folder with split name, you can also check out [this documentation page](https://huggingface.co/docs/datasets/main/en/repository_structure) :)
by default all the data goes to a single `train` split
Issue: load_dataset method returns Unknown split "validation" even if this dir exists

Comment:
@polinaeterna I have specified my train/test/tune files via the `split_to_filepattern` argument when initialising my `FileDataSource` class.  This is how `list_shards` is able to find the right files.
After your last message, I have tried renaminig my data files to simply `train.csv` and `validation.csv`, however I am still getting the same error: `Unknown split "validation". Should be one of ['train']`
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Hi @lhoestq,
I plunged into the code and it should be manageable for me to work on it!
#take

Also, setting `d1`, `d2` and `d3` as you did raised a `SyntaxError: 'yield' inside list comprehension` for me, on Python 3.8.10.
The following snippet works for me though:
```
d1 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [0, 1, 2]])), {}))
d2 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [10, 11, 12, 13]])), {}))
d3 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [20, 21, 22, 23, 24]])), {}))
```
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Hi @ylacombe :) Is there anything I can do to help ? Feel free to ping me if you have any question :)
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Hi @lhoestq,

I actually have already wrote the code last time [on this commit](https://github.com/ylacombe/datasets/commit/84769db97facc78a33ec53f7b1b395951e1804df) but I still have to change the docs and write some tests though. I'm working on it.

However, I still your advice on one matter. 
In #4831, when using a `Dataset` list with probabilities, I had change the original behavior so that it stops as soon as one or all datasets are out of samples. By nature, this behavior can't be applied with an `IterableDataset` because one only knows an iterable dataset is out of sample when receiving a StopIteration error after calling the iterator once again. 
To sum up, as it is right know, the behavior is not consistent with an `IterableDataset`  list or a `Dataset` list, when using probabilities.
To be honest, I think that the current behavior with a `Dataset` list is desirable and avoid having too many samples, so I would recommand keeping that as it is, but I can understand the desire to have the same behavior for both classes. 
What do you think ? Please let me know if you need more details.


EDIT:
Here is an example:
```
>>> from tests.test_iterable_dataset import *
>>> d1 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [0, 1, 2]])), {}))
>>> d2 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [10, 11, 12, 13]])), {}))
>>> d3 = IterableDataset(ExamplesIterable((lambda: (yield from [(i, {"a": i}) for i in [20, 21, 22, 23, 24]])), {}))
>>> dataset = interleave_datasets([d1, d2, d3], probabilities=[0.7, 0.2, 0.1], seed=42)
>>> [x["a"] for x in dataset]
[10, 0, 11, 1, 2, 20, 12, 13]
>>> from tests.test_arrow_dataset import *
>>> d1 = Dataset.from_dict({"a": [0, 1, 2]})
>>> d2 = Dataset.from_dict({"a": [10, 11, 12]})
>>> d3 = Dataset.from_dict({"a": [20, 21, 22]})
>>> interleave_datasets([d1, d2, d3], probabilities=[0.7, 0.2, 0.1], seed=42)["a"]
[10, 0, 11, 1, 2]
[10, 0, 11, 1, 2]
```
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Hi ! Awesome :) 

Maybe you can pre-load the next sample to know if the dataset is empty or not ?
This way it should be possible to have the same behavior for `IterableDataset`
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Hi @lhoestq, I've finally made some advances in the matter. I've modified the `IterableDataset` behavior so that it aligns with the `Dataset` behavior as we have discussed. The documentation has been dealt with too. 
It works as expected on my examples. However I'm having trouble figuring out how to test `interleave_datasets` on `test_iterable_datasets.py` as I have never worked with pytest. Could you help me on that or give me some indications?
Issue: Oversampling strategy for iterable datasets in `interleave_datasets`

Comment:
Thanks @ylacombe :)

Using the `pytest` command, you can run all the functions in a python file that start with "test_*" and make sure they return not errors:
```
pytest tests/test_iterable_dataset.py
```

In our case it can be nice to define a `test_interleave_datasets_with_oversampling` function. This function can contain the code example that we mentioned earlier in this github issue to make sure it works as expected.
Issue: torchaudio 11.0 yields different results than torchaudio 12.1 when loading MP3

Comment:
Maybe we can just pass this along to torchaudio @lhoestq @albertvillanova ? It be great if you could investigate if the errors lies in datasets or in torchaudio.
Issue: torchaudio 11.0 yields different results than torchaudio 12.1 when loading MP3

Comment:
torchaudio did a change in [0.12](https://github.com/pytorch/audio/releases/tag/v0.12.0) on MP3 decoding (which affects common voice):
> MP3 decoding is now handled by FFmpeg in sox_io backend. (https://github.com/pytorch/audio/pull/2419, https://github.com/pytorch/audio/pull/2428)
> - FFmpeg is now used as fallback in sox_io backend, and now MP3 decoding is handled by FFmpeg. To load MP3 audio with torchaudio.load, please install a compatible version of FFmpeg (Version 4 when using an official binary distribution).
> - Note that, whereas the previous MP3 decoding scheme pads the output audio, the new scheme does not. As a consequence, the new version returns shorter audio tensors.
Issue: torchaudio 11.0 yields different results than torchaudio 12.1 when loading MP3

Comment:
Do we have a solution for this now? Should we just upgrade to `torchaudio 0.12.0` then?
Issue: torchaudio 11.0 yields different results than torchaudio 12.1 when loading MP3

Comment:
`datasets` supports `torchaudio` 0.12 if you have an environment that supports reading MP3 with `torchaudio`, i.e. if you have `ffmpeg>=4`
Issue: Dataset Viewer issue for subjqa

Comment:
It's a bug in the viewer, thanks for reporting it. We're hoping to update to a new version in the next few days which should fix it.
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Hi! IIRC one of the files in this dataset is corrupted due to https://github.com/huggingface/datasets/pull/4081 (fixed now).

@NielsRogge Could you please re-generate and re-push this dataset (or I can do it if you share the generation script)?
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Could you put something in place to catch these problems?  I'm seeing this on another dataset consistently too and I guess I can't fix it in code?
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Hey,

Yes the notebook I used to upload this dataset can be found here: https://colab.research.google.com/drive/141LJCcM2XyqprPY83nIQ-Zk3BbxWeahq?usp=sharing.

If you have time to regenerate the dataset, would be great.
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Sorry, maybe I wasn't clear enough that it's a different dataset `laion2B-multi-joined-translated-to-en`.  I think there should be checks in the upload, tests on the server, or validation after download (hashes) to catch these problems.

Lots of bandwidth wasted otherwise! /cc @mariosasko
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Yes @alexjc sorry was more a reply to @JeanKaddour.

And indeed it'd be great to have additional checks to avoid these errors.
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Hi,

It seems the problem is still persist. I have encountered the exact same problem using just 2 line of code above. 

The error code is as follows:

```
發生例外狀況: DatasetGenerationError
An error occurred while generating the dataset
pyarrow.lib.ArrowInvalid: Parquet magic bytes not found in footer. Either the file is corrupted or this is not a parquet file.

The above exception was the direct cause of the following exception:

  File "/code/ddpm_learn/train.py", line 65, in <module>
    dataset = load_dataset("huggan/CelebA-HQ", cache_dir="./CelebA-HQ"
datasets.builder.DatasetGenerationError: An error occurred while generating the dataset
```
Issue: Loading huggan/CelebA-HQ throws pyarrow.lib.ArrowInvalid

Comment:
Yes for the moment refer to the notebook linked above if you want to create a HF dataset yourself