Datasets:
License:
Upload mumospee_small.py with huggingface_hub
Browse files- mumospee_small.py +69 -0
mumospee_small.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
# Define the dataset to Hugging Face standard so users can access it via load_dataset
|
7 |
+
class MumospeeSmall(datasets.GeneratorBasedBuilder):
|
8 |
+
def _info(self):
|
9 |
+
return datasets.DatasetInfo(
|
10 |
+
description="Mumospee is a continuously growing, comprehensive, multilingual dataset across different modalities. This is the small version include no more 1000 rows.",
|
11 |
+
features=datasets.Features(
|
12 |
+
{
|
13 |
+
"path": datasets.Value("string"),
|
14 |
+
"url": datasets.Value("string"),
|
15 |
+
"type": datasets.Value("string"),
|
16 |
+
"duration": datasets.Value("float32"),
|
17 |
+
"language": datasets.Value("string"),
|
18 |
+
"transcript": datasets.Value("string"),
|
19 |
+
"tag": datasets.Value("string"),
|
20 |
+
"split": datasets.Value("string"),
|
21 |
+
"license": datasets.Value("string"),
|
22 |
+
}
|
23 |
+
),
|
24 |
+
supervised_keys=None,
|
25 |
+
license="CC-BY-4.0",
|
26 |
+
)
|
27 |
+
|
28 |
+
def _split_generators(self, dl_manager):
|
29 |
+
# Specify the CSV path
|
30 |
+
csv_path = self.config.data_files["csv"]
|
31 |
+
|
32 |
+
return [
|
33 |
+
datasets.SplitGenerator(
|
34 |
+
name=datasets.Split.TRAIN,
|
35 |
+
gen_kwargs={"csv_path": csv_path, "split": "train"},
|
36 |
+
),
|
37 |
+
datasets.SplitGenerator(
|
38 |
+
name=datasets.Split.TEST,
|
39 |
+
gen_kwargs={"csv_path": csv_path, "split": "test"},
|
40 |
+
),
|
41 |
+
datasets.SplitGenerator(
|
42 |
+
name=datasets.Split.VALIDATION,
|
43 |
+
gen_kwargs={"csv_path": csv_path, "split": "validation"},
|
44 |
+
),
|
45 |
+
]
|
46 |
+
|
47 |
+
|
48 |
+
def _generate_examples(self, csv_path, split, language=None, tag=None):
|
49 |
+
"""
|
50 |
+
Generates examples from the CSV file, applying filters based on split, language, and tag.
|
51 |
+
"""
|
52 |
+
|
53 |
+
# Read the CSV file in chunks to handle large datasets
|
54 |
+
for chunk in pd.read_csv(csv_path, chunksize=10_000):
|
55 |
+
# Filter by split if specified
|
56 |
+
if split:
|
57 |
+
chunk = chunk[chunk["split"] == split]
|
58 |
+
|
59 |
+
# Apply language filter if provided
|
60 |
+
if language:
|
61 |
+
chunk = chunk[chunk["language"] == language]
|
62 |
+
|
63 |
+
# Apply tag filter if provided
|
64 |
+
if tag:
|
65 |
+
chunk = chunk[chunk["tag"] == tag]
|
66 |
+
|
67 |
+
# Yield examples one by one
|
68 |
+
for idx, record in chunk.iterrows():
|
69 |
+
yield idx, record.to_dict()
|