PedroDKE commited on
Commit
11eba43
·
1 Parent(s): 048710c

update dataset

Browse files
Files changed (1) hide show
  1. libris2s/libris2s.py +79 -0
libris2s/libris2s.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """LibriS2S dataset."""
2
+
3
+ import csv
4
+ import os
5
+ from typing import Dict, List, Tuple
6
+
7
+ import datasets
8
+
9
+
10
+ _CITATION = """@inproceedings{jeuris-niehues-2022-libris2s,
11
+ title = "{L}ibri{S}2{S}: A {G}erman-{E}nglish Speech-to-Speech Translation Corpus",
12
+ author = "Jeuris, Pedro and Niehues, Jan",
13
+ booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
14
+ year = "2022",
15
+ url = "https://aclanthology.org/2022.lrec-1.98",
16
+ pages = "928--935"
17
+ }"""
18
+
19
+ _DESCRIPTION = """LibriS2S: A German-English Speech-to-Speech Translation Corpus"""
20
+
21
+ _HOMEPAGE = "https://huggingface.co/datasets/PedroDKE/LibriS2S"
22
+
23
+ _LICENSE = "cc-by-nc-sa-4.0"
24
+
25
+
26
+ class LibriS2S(datasets.GeneratorBasedBuilder):
27
+ """LibriS2S dataset."""
28
+
29
+ VERSION = datasets.Version("1.0.0")
30
+
31
+ def _info(self) -> datasets.DatasetInfo:
32
+ return datasets.DatasetInfo(
33
+ description=_DESCRIPTION,
34
+ features=datasets.Features(
35
+ {
36
+ "book_id": datasets.Value("int64"),
37
+ "DE_audio": datasets.Audio(),
38
+ "EN_audio": datasets.Audio(),
39
+ "score": datasets.Value("float32"),
40
+ "DE_transcript": datasets.Value("string"),
41
+ "EN_transcript": datasets.Value("string"),
42
+ }
43
+ ),
44
+ homepage=_HOMEPAGE,
45
+ license=_LICENSE,
46
+ citation=_CITATION,
47
+ )
48
+
49
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
50
+ """Returns SplitGenerators."""
51
+ return [
52
+ datasets.SplitGenerator(
53
+ name=datasets.Split.TRAIN,
54
+ gen_kwargs={
55
+ "split": "train",
56
+ "data_dir": ".",
57
+ },
58
+ ),
59
+ ]
60
+
61
+ def _generate_examples(self, split: str, data_dir: str) -> Tuple[int, Dict]:
62
+ """Yields examples."""
63
+ csv_path = os.path.join(data_dir, "alignments", "all_de_en_alligned_cleaned.csv")
64
+
65
+ with open(csv_path, encoding="utf-8") as f:
66
+ reader = csv.DictReader(f)
67
+ for idx, row in enumerate(reader):
68
+ # Handle paths for both DE and EN audio
69
+ de_audio_path = os.path.join(data_dir, row["DE_audio"])
70
+ en_audio_path = os.path.join(data_dir, row["EN_audio"])
71
+
72
+ yield idx, {
73
+ "book_id": int(row["book_id"]),
74
+ "DE_audio": de_audio_path,
75
+ "EN_audio": en_audio_path,
76
+ "score": float(row["score"]),
77
+ "DE_transcript": row["DE_transcript"],
78
+ "EN_transcript": row["EN_transcript"],
79
+ }