Datasets:

ArXiv:
License:
jiaye commited on
Commit
01eb33d
1 Parent(s): 11fb4a0

Add an initial version of the CVSS datasets loading script.

Browse files
Files changed (1) hide show
  1. cvss.py +148 -0
cvss.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2022 The CVSS Dataset Authors and the dataset script contributor.
2
+ # All Rights Reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ # ==============================================================================
16
+ """CVSS speech-to-speech translation corpus."""
17
+
18
+ import os
19
+ import datasets
20
+
21
+ _HOMEPAGE = 'https://github.com/google-research-datasets/cvss'
22
+
23
+ _DESCRIPTION = """\
24
+ CVSS is a massively multilingual-to-English speech-to-speech translation corpus,
25
+ covering sentence-level parallel speech-to-speech translation pairs from 21
26
+ languages into English.
27
+ """
28
+
29
+ _CITATION = """\
30
+ @inproceedings{jia2022cvss,
31
+ title={{CVSS} Corpus and Massively Multilingual Speech-to-Speech Translation},
32
+ author={Jia, Ye and Tadmor Ramanovich, Michelle and Wang, Quan and Zen, Heiga},
33
+ booktitle={Proceedings of Language Resources and Evaluation Conference (LREC)},
34
+ pages={6691--6703},
35
+ year={2022}
36
+ }
37
+ """
38
+
39
+ _ROOT_URL = 'https://storage.googleapis.com/cvss'
40
+
41
+ _ALL_LANGUAGES = ('de', 'fr', 'es', 'ca', 'it', 'ru', 'zh', 'pt', 'fa', 'et',
42
+ 'mn', 'nl', 'tr', 'ar', 'sv', 'lv', 'sl', 'ta', 'ja', 'id',
43
+ 'cy')
44
+
45
+
46
+ def _get_download_urls(name='cvss_c', languages=_ALL_LANGUAGES, version='1.0'):
47
+ """Gets URLs for downloading data.
48
+
49
+ Args:
50
+ name: 'cvss_c' or 'cvss_t'.
51
+ languages: An iterable of source languages.
52
+ version: Only '1.0' available.
53
+
54
+ Returns:
55
+ A list of URL strs.
56
+ """
57
+ return [
58
+ f'{_ROOT_URL}/{name}_v{version}/{name}_{x}_en_v{version}.tar.gz'
59
+ for x in languages
60
+ ]
61
+
62
+
63
+ class CVSSConfig(datasets.BuilderConfig):
64
+ """BuilderConfig for CVSS."""
65
+
66
+ def __init__(self, name, languages='all', **kwargs):
67
+ """BuilderConfig for CVSS.
68
+
69
+ Args:
70
+ name: 'cvss_c' or 'cvss_t'.
71
+ languages: A list of source languages.
72
+ **kwargs: keyword arguments forwarded to super.
73
+ """
74
+ super().__init__(name=name, **kwargs)
75
+ if languages == 'all':
76
+ self.languages = _ALL_LANGUAGES
77
+ elif isinstance(languages, str):
78
+ self.languages = [languages]
79
+ else:
80
+ self.languages = languages
81
+
82
+
83
+ class CVSS(datasets.GeneratorBasedBuilder):
84
+ """CVSS dataset. Version 1.0."""
85
+
86
+ BUILDER_CONFIG_CLASS = CVSSConfig
87
+
88
+ VERSION = '1.0.0'
89
+
90
+ DEFAULT_WRITER_BATCH_SIZE = 256
91
+
92
+ def _info(self):
93
+ return datasets.DatasetInfo(
94
+ description=_DESCRIPTION,
95
+ homepage=_HOMEPAGE,
96
+ citation=_CITATION,
97
+ features=datasets.Features({
98
+ 'id': datasets.Value('string'),
99
+ 'file': datasets.Value('string'),
100
+ 'audio': datasets.Audio(sampling_rate=24_000),
101
+ 'text': datasets.Value('string'),
102
+ }))
103
+
104
+ def _split_generators(self, dl_manager):
105
+ print(self.config)
106
+ downloaded_files = dl_manager.download_and_extract(
107
+ _get_download_urls(self.config.name, self.config.languages))
108
+ return [
109
+ datasets.SplitGenerator(
110
+ name=datasets.Split.TRAIN,
111
+ gen_kwargs={
112
+ 'files': downloaded_files,
113
+ 'split': 'train'
114
+ }),
115
+ datasets.SplitGenerator(
116
+ name=datasets.Split.VALIDATION,
117
+ gen_kwargs={
118
+ 'files': downloaded_files,
119
+ 'split': 'dev'
120
+ }),
121
+ datasets.SplitGenerator(
122
+ name=datasets.Split.TEST,
123
+ gen_kwargs={
124
+ 'files': downloaded_files,
125
+ 'split': 'test'
126
+ }),
127
+ ]
128
+
129
+ def _generate_examples(self, files, split):
130
+ """Generates examples for each SplitGenerator."""
131
+ for path in files:
132
+ with open(os.path.join(path, f'{split}.tsv'), 'r', encoding='utf-8') as f:
133
+ for line in f:
134
+ cols = line.rstrip().split('\t')
135
+ assert len(cols) == 2, cols
136
+ key, text = cols
137
+
138
+ audio_path = os.path.join(path, split, f'{key}.wav')
139
+ with open(audio_path, 'rb') as audio_f:
140
+ audio_bytes = audio_f.read()
141
+
142
+ audio = {'path': audio_path, 'bytes': audio_bytes}
143
+ yield key, {
144
+ 'id': key,
145
+ 'text': text,
146
+ 'audio': audio,
147
+ 'file': audio_path,
148
+ }