Upload folder using huggingface_hub
Browse files- .idea/workspace.xml +1 -1
- README.md +20 -3
- pl_debates_test.py +84 -41
.idea/workspace.xml
CHANGED
|
@@ -59,7 +59,7 @@
|
|
| 59 |
<option name="number" value="Default" />
|
| 60 |
<option name="presentableId" value="Default" />
|
| 61 |
<updated>1748334702944</updated>
|
| 62 |
-
<workItem from="1748334704041" duration="
|
| 63 |
</task>
|
| 64 |
<servers />
|
| 65 |
</component>
|
|
|
|
| 59 |
<option name="number" value="Default" />
|
| 60 |
<option name="presentableId" value="Default" />
|
| 61 |
<updated>1748334702944</updated>
|
| 62 |
+
<workItem from="1748334704041" duration="4123000" />
|
| 63 |
</task>
|
| 64 |
<servers />
|
| 65 |
</component>
|
README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Polish Politicians Speech
|
| 2 |
+
|
| 3 |
+
**Dataset in the public domain (2025)**
|
| 4 |
+
|
| 5 |
+
## Description
|
| 6 |
+
|
| 7 |
+
Studio-recorded short utterances by 16 Polish political figures (e.g. “Bartoszewicz Artur”, “Zandberg Adrian”), each reading ~15 sentences. Audio in `.wav` (16 kHz).
|
| 8 |
+
|
| 9 |
+
## Files
|
| 10 |
+
|
| 11 |
+
- `audio/` – per-speaker WAV files
|
| 12 |
+
- `transcript/pl/test.tsv` – tabular metadata & transcripts
|
| 13 |
+
|
| 14 |
+
## Usage
|
| 15 |
+
|
| 16 |
+
```py
|
| 17 |
+
from datasets import load_dataset
|
| 18 |
+
ds = load_dataset("USERNAME/pl-politicians-speech", "plain_audio")
|
| 19 |
+
print(ds["train"][0])
|
| 20 |
+
# {'path': ..., 'audio': {...}, 'sentence': ..., 'age': ..., 'gender': ...}
|
pl_debates_test.py
CHANGED
|
@@ -13,7 +13,7 @@ _CITATION = """
|
|
| 13 |
}
|
| 14 |
"""
|
| 15 |
|
| 16 |
-
#
|
| 17 |
_BASE_URL = "https://huggingface.co/datasets/directtt/pl_debates_test/resolve/main/"
|
| 18 |
_TRANSCRIPT_URL = _BASE_URL + "transcript/pl/test.tsv"
|
| 19 |
_AUDIO_TAR_URL = _BASE_URL + "audio_pl.tar"
|
|
@@ -38,7 +38,7 @@ class PlDebatesTest(datasets.GeneratorBasedBuilder):
|
|
| 38 |
"audio": datasets.Audio(sampling_rate=16_000),
|
| 39 |
"sentence": datasets.Value("string"),
|
| 40 |
"age": datasets.Value("int32"),
|
| 41 |
-
"gender": datasets.
|
| 42 |
"speech_type": datasets.Value("string"),
|
| 43 |
"source": datasets.Value("string"),
|
| 44 |
}),
|
|
@@ -48,51 +48,94 @@ class PlDebatesTest(datasets.GeneratorBasedBuilder):
|
|
| 48 |
)
|
| 49 |
|
| 50 |
def _split_generators(self, dl_manager):
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
def _generate_examples(self, tsv_path, audio_root):
|
| 67 |
-
# 1)
|
| 68 |
meta = {}
|
| 69 |
with open(tsv_path, encoding="utf-8") as f:
|
| 70 |
reader = csv.DictReader(f, delimiter="\t")
|
| 71 |
for row in reader:
|
| 72 |
meta[row["path"]] = row
|
| 73 |
|
| 74 |
-
# 2) Walk the unpacked audio directory
|
| 75 |
key = 0
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
continue
|
| 89 |
-
|
| 90 |
-
"
|
| 91 |
-
|
| 92 |
-
"
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
"""
|
| 15 |
|
| 16 |
+
# Base URLs on the Hub — replace YOUR-USER/YOUR-REPO accordingly
|
| 17 |
_BASE_URL = "https://huggingface.co/datasets/directtt/pl_debates_test/resolve/main/"
|
| 18 |
_TRANSCRIPT_URL = _BASE_URL + "transcript/pl/test.tsv"
|
| 19 |
_AUDIO_TAR_URL = _BASE_URL + "audio_pl.tar"
|
|
|
|
| 38 |
"audio": datasets.Audio(sampling_rate=16_000),
|
| 39 |
"sentence": datasets.Value("string"),
|
| 40 |
"age": datasets.Value("int32"),
|
| 41 |
+
"gender": datasets.Value("string"),
|
| 42 |
"speech_type": datasets.Value("string"),
|
| 43 |
"source": datasets.Value("string"),
|
| 44 |
}),
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
def _split_generators(self, dl_manager):
|
| 51 |
+
if dl_manager.is_streaming:
|
| 52 |
+
# streaming: download the tar and the TSV, but don't extract to disk
|
| 53 |
+
tsv_path = dl_manager.download(_TRANSCRIPT_URL)
|
| 54 |
+
tar_path = dl_manager.download(_AUDIO_TAR_URL)
|
| 55 |
+
archives = [dl_manager.iter_archive(tar_path)]
|
| 56 |
+
return [
|
| 57 |
+
datasets.SplitGenerator(
|
| 58 |
+
name=datasets.Split.TEST,
|
| 59 |
+
gen_kwargs={
|
| 60 |
+
"tsv_path": tsv_path,
|
| 61 |
+
"archives": archives,
|
| 62 |
+
"streaming": True,
|
| 63 |
+
},
|
| 64 |
+
),
|
| 65 |
+
]
|
| 66 |
+
else:
|
| 67 |
+
# eager: download & extract everything
|
| 68 |
+
downloaded = dl_manager.download_and_extract({
|
| 69 |
+
"tsv": _TRANSCRIPT_URL,
|
| 70 |
+
"tar": _AUDIO_TAR_URL,
|
| 71 |
+
})
|
| 72 |
+
return [
|
| 73 |
+
datasets.SplitGenerator(
|
| 74 |
+
name=datasets.Split.TEST,
|
| 75 |
+
gen_kwargs={
|
| 76 |
+
"tsv_path": downloaded["tsv"],
|
| 77 |
+
"audio_root": downloaded["tar"],
|
| 78 |
+
"streaming": False,
|
| 79 |
+
},
|
| 80 |
+
),
|
| 81 |
+
]
|
| 82 |
|
| 83 |
+
def _generate_examples(self, tsv_path, streaming, archives=None, audio_root=None):
|
| 84 |
+
# 1) load metadata
|
| 85 |
meta = {}
|
| 86 |
with open(tsv_path, encoding="utf-8") as f:
|
| 87 |
reader = csv.DictReader(f, delimiter="\t")
|
| 88 |
for row in reader:
|
| 89 |
meta[row["path"]] = row
|
| 90 |
|
|
|
|
| 91 |
key = 0
|
| 92 |
+
|
| 93 |
+
if streaming:
|
| 94 |
+
# iterate inside the tar archive without extracting
|
| 95 |
+
for archive in archives:
|
| 96 |
+
for path_in_tar, fileobj in archive:
|
| 97 |
+
# path_in_tar looks like "audio/pl/<speaker>/<fname>.wav"
|
| 98 |
+
if not path_in_tar.endswith(".wav"):
|
| 99 |
+
continue
|
| 100 |
+
# build the rel_path for lookup
|
| 101 |
+
rel_path = path_in_tar.replace("\\", "/") # normalize on Windows
|
| 102 |
+
row = meta.get(rel_path)
|
| 103 |
+
if row is None:
|
| 104 |
+
continue
|
| 105 |
+
# read the bytes and yield them
|
| 106 |
+
audio_bytes = fileobj.read()
|
| 107 |
+
yield key, {
|
| 108 |
+
"path": rel_path,
|
| 109 |
+
"audio": {"path": None, "bytes": audio_bytes},
|
| 110 |
+
"sentence": row["sentence"],
|
| 111 |
+
"age": int(row.get("age", -1)),
|
| 112 |
+
"gender": row["gender"],
|
| 113 |
+
"speech_type": row["speech_type"],
|
| 114 |
+
"source": row["source"],
|
| 115 |
+
}
|
| 116 |
+
key += 1
|
| 117 |
+
|
| 118 |
+
else:
|
| 119 |
+
# eager: walk the extracted folder on disk
|
| 120 |
+
pl_root = os.path.join(audio_root, "audio", "pl")
|
| 121 |
+
for speaker in sorted(os.listdir(pl_root)):
|
| 122 |
+
sp_dir = os.path.join(pl_root, speaker)
|
| 123 |
+
if not os.path.isdir(sp_dir):
|
| 124 |
continue
|
| 125 |
+
for fname in sorted(os.listdir(sp_dir)):
|
| 126 |
+
if not fname.endswith(".wav"):
|
| 127 |
+
continue
|
| 128 |
+
rel_path = os.path.join("audio", "pl", speaker, fname)
|
| 129 |
+
row = meta.get(rel_path)
|
| 130 |
+
if row is None:
|
| 131 |
+
continue
|
| 132 |
+
yield key, {
|
| 133 |
+
"path": rel_path,
|
| 134 |
+
"audio": os.path.join(sp_dir, fname),
|
| 135 |
+
"sentence": row["sentence"],
|
| 136 |
+
"age": int(row.get("age", -1)),
|
| 137 |
+
"gender": row.get("gender", "unknown") or "unknown",
|
| 138 |
+
"speech_type": row["speech_type"],
|
| 139 |
+
"source": row["source"],
|
| 140 |
+
}
|
| 141 |
+
key += 1
|