---
configs:
- config_name: 20k
  data_files:
  - split: train
    path: 20k/train/*.tar
  - split: test
    path: 20k/test/*.tar
- config_name: 500k
  data_files:
  - split: train
    path: 500k/train/*.tar
  - split: test
    path: 500k/test/*.tar
- config_name: 2m
  data_files:
  - split: train
    path: 2m/train/*.tar
  - split: test
    path: 2m/test/*.tar
task_categories:
- audio-classification
tags:
- audio
- multi-label
- webdataset
size_categories:
- 1M<n<10M
---

# AudioSet

AudioSet<sup>[1]</sup> is a large-scale dataset comprising approximately 2 million 10-second YouTube audio clips, categorised into 527 sound classes. 
We have pre-processed all audio files to a 16 kHz sampling rate and stored them in the WebDataset format for efficient large-scale training and retrieval.

## Download

We recommend using the following commands to download the `confit/audioset-16khz-wds` dataset from HuggingFace. 
The dataset is available in two versions:

 - train:
   - 20k: A smaller balanced version with 20,550 clips for quick experimentation.
   - 500k<sup>[2]</sup>: A (slightly more) balanced version with 497,982 clips for quick experimentation.
   - 2m: The complete unbalanced dataset with 1,912,024 clips.
 - test: The eval set with 18,886 clips.

```bash
# For the 20k version
huggingface-cli download confit/audioset-16khz-wds --include 20k/train/*.tar  --repo-type=dataset --local-dir /path/to/store
huggingface-cli download confit/audioset-16khz-wds --include 20k/test/*.tar  --repo-type=dataset --local-dir /path/to/store

# For the 500k version
huggingface-cli download confit/audioset-16khz-wds --include 500k/train/*.tar  --repo-type=dataset --local-dir /path/to/store
huggingface-cli download confit/audioset-16khz-wds --include 500k/test/*.tar  --repo-type=dataset --local-dir /path/to/store

# For the 2m version
huggingface-cli download confit/audioset-16khz-wds --include 2m/train/*.tar  --repo-type=dataset --local-dir /path/to/store
huggingface-cli download confit/audioset-16khz-wds --include 2m/test/*.tar  --repo-type=dataset --local-dir /path/to/store
```

> **_NOTE:_** The `--local-dir /path/to/store` argument specifies the root directory where the dataset will be stored. You do not need to manually create subdirectories (e.g., `/path/to/store/20k/train`). The command will automatically create the required folder structure.

| split | #shards | #clips | total duration | avg duration |
| :---: | :---: | :---: | :---: | :---: |
| 20k | 7 | 20,550 | 56 hours | 9.90 seconds |
| 500k | 147 | 497,982 | 1,371 hours | 9.91 seconds |
| 2m | 565 | 1,912,024 | 5,264 hours | 9.91 seconds |
| test | 6 | 18,886 | 51 hours | 9.89 seconds |

## Format and Usage

The dataset is stored in the WebDataset (WDS) format, which is optimised for distributed training and streaming. 
Each `.tar` archive contains audio files and corresponding metadata.

To load the dataset in Python using webdataset:

```python
from glob import glob
from datasets import load_dataset

train_urls = glob('/path/to/20k/train/*.tar')
test_urls = glob('/path/to/20k/test/*.tar')

raw_datasets = load_dataset(
    "webdataset",
    data_files={"train": train_urls, "test": test_urls},
    streaming=False
)
```

Each sample in the dataset follows the WebDataset format, which includes the following fields:

```plain
{
    '__key__': 'sample-000000000',
    '__url__': '/path/to/20k/train/shard-00000.tar',
    'wav': {
        'path': 'sample-000000000.wav',
        'array': array([ 0., ..., -0.00256348]),
        'sampling_rate': 16000
    },
    'json': {
        'id': 'YUJxAKoY0gRM',
        'label': ['Clarinet'],
        'label_id': [198]
    }
}
```

## References

[1] Gemmeke, J. F., Ellis, D. P., Freedman, D., Jansen, A., Lawrence, W., Moore, R. C., ... & Ritter, M. (2017, March). Audio set: An ontology and human-labeled dataset for audio events. In 2017 IEEE international conference on acoustics, speech and signal processing (ICASSP) (pp. 776-780). IEEE.

[2] Nagrani, A., Yang, S., Arnab, A., Jansen, A., Schmid, C., & Sun, C. (2021). Attention bottlenecks for multimodal fusion. Advances in neural information processing systems, 34, 14200-14213.

## License and Usage Restrictions

We downloaded the dataset from qiuqiangkong's [GitHub](https://github.com/qiuqiangkong/audioset_tagging_cnn) and pre-processed it into WebDataset format. 
Please ensure compliance with YouTube's terms of service when using this dataset. 
Some clips may no longer be available if the original videos have been removed or made private.