Datasets:
update dataset
Browse files- libris2s/libris2s.py +22 -10
libris2s/libris2s.py
CHANGED
|
@@ -18,30 +18,42 @@ class Libris2s(GeneratorBasedBuilder):
|
|
| 18 |
|
| 19 |
def _split_generators(self, dl_manager):
|
| 20 |
"""Returns SplitGenerators."""
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
return [
|
| 24 |
SplitGenerator(
|
| 25 |
name=Split.TRAIN,
|
| 26 |
gen_kwargs={
|
| 27 |
-
"filepath": os.path.join(data_dir, "alignments/all_de_en_alligned_cleaned.csv"),
|
| 28 |
-
"
|
| 29 |
}
|
| 30 |
),
|
| 31 |
]
|
| 32 |
|
| 33 |
-
def _generate_examples(self, filepath,
|
|
|
|
| 34 |
with open(filepath, encoding="utf-8") as f:
|
| 35 |
reader = csv.DictReader(f)
|
| 36 |
for idx, row in enumerate(reader):
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
yield idx, {
|
| 42 |
"book_id": int(row["book_id"]),
|
| 43 |
-
"DE_audio":
|
| 44 |
-
"EN_audio":
|
| 45 |
"score": float(row["score"]),
|
| 46 |
"DE_transcript": row["DE_transcript"],
|
| 47 |
"EN_transcript": row["EN_transcript"],
|
|
|
|
| 18 |
|
| 19 |
def _split_generators(self, dl_manager):
|
| 20 |
"""Returns SplitGenerators."""
|
| 21 |
+
if self.config.data_dir is None:
|
| 22 |
+
raise ValueError(
|
| 23 |
+
"This dataset requires you to specify the data_dir parameter in the config. "
|
| 24 |
+
"You can do this by passing --data_dir when loading the dataset."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
return [
|
| 28 |
SplitGenerator(
|
| 29 |
name=Split.TRAIN,
|
| 30 |
gen_kwargs={
|
| 31 |
+
"filepath": os.path.join(self.config.data_dir, "alignments/all_de_en_alligned_cleaned.csv"),
|
| 32 |
+
"audio_dir": self.config.data_dir,
|
| 33 |
}
|
| 34 |
),
|
| 35 |
]
|
| 36 |
|
| 37 |
+
def _generate_examples(self, filepath, audio_dir):
|
| 38 |
+
"""Yields examples."""
|
| 39 |
with open(filepath, encoding="utf-8") as f:
|
| 40 |
reader = csv.DictReader(f)
|
| 41 |
for idx, row in enumerate(reader):
|
| 42 |
+
# Handle paths for both DE and EN audio
|
| 43 |
+
de_audio_path = os.path.join(audio_dir, row["DE_audio"])
|
| 44 |
+
en_audio_path = os.path.join(audio_dir, row["EN_audio"])
|
| 45 |
+
|
| 46 |
+
# Check if files exist
|
| 47 |
+
if not os.path.exists(de_audio_path) or not os.path.exists(en_audio_path):
|
| 48 |
+
print(f"Warning: Missing audio file(s) for index {idx}")
|
| 49 |
+
print(f"DE audio path: {de_audio_path}")
|
| 50 |
+
print(f"EN audio path: {en_audio_path}")
|
| 51 |
+
continue
|
| 52 |
|
| 53 |
yield idx, {
|
| 54 |
"book_id": int(row["book_id"]),
|
| 55 |
+
"DE_audio": de_audio_path,
|
| 56 |
+
"EN_audio": en_audio_path,
|
| 57 |
"score": float(row["score"]),
|
| 58 |
"DE_transcript": row["DE_transcript"],
|
| 59 |
"EN_transcript": row["EN_transcript"],
|