|
|
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"), |
|
|
"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"], |
|
|
"label": row["label"].lower(), |
|
|
} |
|
|
|