File size: 1,853 Bytes
ea345a9 |
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 |
import csv
import datasets
_CITATION = """\
@dataset{qasim2025animalsounds,
title = {Animal Sound Classification Dataset},
author = {Muhammad Qasim},
year = {2025},
url = {https://huggingface.co/datasets/MuhammadQASIM111/Animal_Sound_Classification}
}
"""
_DESCRIPTION = """\
A meticulously curated dataset of labeled animal sounds (dogs, cats, cows) for audio classification tasks. The dataset contains trimmed and cleaned audio clips with labels.
"""
_HOMEPAGE = "https://huggingface.co/datasets/MuhammadQASIM111/Animal_Sound_Classification"
_LICENSE = "mit"
_URLS = {
"train": "ML1_features.csv"
}
class AnimalSoundClassification(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"audio": datasets.Value("string"), # path to audio file or URL
"label": datasets.ClassLabel(names=["dog", "cat", "cow"]),
}),
supervised_keys=("audio", "label"),
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
data_path = dl_manager.download_and_extract(_URLS["train"])
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"filepath": data_path},
),
]
def _generate_examples(self, filepath):
with open(filepath, encoding="utf-8") as csv_file:
reader = csv.DictReader(csv_file)
for id_, row in enumerate(reader):
yield id_, {
"audio": row["audio"], # Make sure column name matches your CSV
"label": row["label"].lower(), # Lowercasing to match ClassLabel names
}
|