Datasets:
Size:
10K<n<100K
License:
File size: 5,914 Bytes
ddcd5b4 848ef96 ddcd5b4 f36edf6 ddcd5b4 f36edf6 ddcd5b4 848ef96 ddcd5b4 848ef96 ddcd5b4 848ef96 ddcd5b4 848ef96 ddcd5b4 848ef96 ddcd5b4 0db8aaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
import pandas as pd
import datasets
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """
@conference {bogdanov2019mtg,
author = "Bogdanov, Dmitry and Won, Minz and Tovstogan, Philip and Porter, Alastair and Serra, Xavier",
title = "The MTG-Jamendo Dataset for Automatic Music Tagging",
booktitle = "Machine Learning for Music Discovery Workshop, International Conference on Machine Learning (ICML 2019)",
year = "2019",
address = "Long Beach, CA, United States",
url = "http://hdl.handle.net/10230/42015"
}
"""
_DESCRIPTION = """
Repackaging of the MTG Jamendo dataset.
We present the MTG-Jamendo Dataset, a new open dataset for music auto-tagging.
It is built using music available at Jamendo under Creative Commons licenses and tags provided by content creators.
The dataset contains over 55,000 full audio tracks with 195 tags from genre, instrument, and mood/theme categories.
"""
_HOMEPAGE = "https://github.com/MTG/mtg-jamendo-dataset"
_LICENSE = "Apache License 2.0"
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
_URLS_DATA = {
"train": {
i: f"https://huggingface.co/datasets/rkstgr/mtg-jamendo/resolve/main/data/train/{i}.tar" for i in range(200)
},
"val": {
i: f"https://huggingface.co/datasets/rkstgr/mtg-jamendo/resolve/main/data/val/{i}.tar" for i in range(22)
}
}
_URLS_TRACKS = {
"train": "https://huggingface.co/datasets/rkstgr/mtg-jamendo/raw/main/train.tsv",
"valid": "https://huggingface.co/datasets/rkstgr/mtg-jamendo/raw/main/valid.tsv"
}
class MtgJamendo(datasets.GeneratorBasedBuilder):
"""
Audio dataset containing over 55,000 full audio tracks with
195 tags from genre, instrument, and mood/theme categories
"""
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features(
{
"id": datasets.Value("int32"),
"artist_id": datasets.Value("int32"),
"album_id": datasets.Value("int32"),
"durationInSec": datasets.Value("float"),
"genres": datasets.Sequence(datasets.Value("string")),
"instruments": datasets.Sequence(datasets.Value("string")),
"moods": datasets.Sequence(datasets.Value("string")),
"audio": datasets.Audio(sampling_rate=22_050),
}
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
archive_path = dl_manager.download(_URLS_DATA)
tracks_path = dl_manager.download(_URLS_TRACKS)
# (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
def to_dict(xs: list) -> dict:
return {x["id"]: x for x in xs}
train_tracks = to_dict(
pd.read_csv(tracks_path["train"], sep="\t").to_dict("records")
)
valid_tracks = to_dict(
pd.read_csv(tracks_path["valid"], sep="\t").to_dict("records")
)
train_splits = [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"local_extracted_archive": local_extracted_archive.get("train"),
"files": dl_manager.iter_archive(archive_path["train"]),
"tracks": train_tracks,
},
)
]
val_splits = [
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"local_extracted_archive": local_extracted_archive.get("val"),
"files": dl_manager.iter_archive(archive_path["val"]),
"tracks": valid_tracks,
},
)
]
return train_splits + val_splits
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, files, local_extracted_archive, tracks):
"""Generate examples from archive_path."""
audio_paths = {}
for _, directory in local_extracted_archive.items():
for f in Path(directory).iterdir():
if f.suffix == ".opus":
_id = int(f.stem)
audio_paths[_id] = str(f)
for _id, audio_path in audio_paths.items():
data = {
"id": _id,
"artist_id": tracks[_id]["artist_id"],
"album_id": tracks[_id]["album_id"],
"durationInSec": tracks[_id]["durationInSec"],
"genres": eval(tracks[_id]["genres"]),
"instruments": eval(tracks[_id]["instruments"]),
"moods": eval(tracks[_id]["moods"]),
"audio": audio_path
}
yield _id, data
if __name__ == '__main__':
mtg = MtgJamendo()
mtg.download_and_prepare()
|