Datasets:

ArXiv:
License:
File size: 4,459 Bytes
01eb33d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8d17d9
 
01eb33d
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 2022 The CVSS Dataset Authors and the dataset script contributor.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""CVSS speech-to-speech translation corpus."""

import os
import datasets

_HOMEPAGE = 'https://github.com/google-research-datasets/cvss'

_DESCRIPTION = """\
CVSS is a massively multilingual-to-English speech-to-speech translation corpus,
covering sentence-level parallel speech-to-speech translation pairs from 21
languages into English.
"""

_CITATION = """\
@inproceedings{jia2022cvss,
    title={{CVSS} Corpus and Massively Multilingual Speech-to-Speech Translation},
    author={Jia, Ye and Tadmor Ramanovich, Michelle and Wang, Quan and Zen, Heiga},
    booktitle={Proceedings of Language Resources and Evaluation Conference (LREC)},
    pages={6691--6703},
    year={2022}
}
"""

_ROOT_URL = 'https://storage.googleapis.com/cvss'

_ALL_LANGUAGES = ('de', 'fr', 'es', 'ca', 'it', 'ru', 'zh', 'pt', 'fa', 'et',
                  'mn', 'nl', 'tr', 'ar', 'sv', 'lv', 'sl', 'ta', 'ja', 'id',
                  'cy')


def _get_download_urls(name='cvss_c', languages=_ALL_LANGUAGES, version='1.0'):
  """Gets URLs for downloading data.

  Args:
    name: 'cvss_c' or 'cvss_t'.
    languages: An iterable of source languages.
    version: Only '1.0' available.

  Returns:
    A list of URL strs.
  """
  return [
      f'{_ROOT_URL}/{name}_v{version}/{name}_{x}_en_v{version}.tar.gz'
      for x in languages
  ]


class CVSSConfig(datasets.BuilderConfig):
  """BuilderConfig for CVSS."""

  def __init__(self, name, languages='all', **kwargs):
    """BuilderConfig for CVSS.

    Args:
      name: 'cvss_c' or 'cvss_t'.
      languages: A list of source languages.
      **kwargs: keyword arguments forwarded to super.
    """
    super().__init__(name=name, **kwargs)
    if languages == 'all':
      self.languages = _ALL_LANGUAGES
    elif isinstance(languages, str):
      self.languages = [languages]
    else:
      self.languages = languages


class CVSS(datasets.GeneratorBasedBuilder):
  """CVSS dataset. Version 1.0."""

  BUILDER_CONFIG_CLASS = CVSSConfig

  VERSION = '1.0.0'

  DEFAULT_WRITER_BATCH_SIZE = 256

  def _info(self):
    return datasets.DatasetInfo(
        description=_DESCRIPTION,
        homepage=_HOMEPAGE,
        citation=_CITATION,
        features=datasets.Features({
            'id': datasets.Value('string'),
            'file': datasets.Value('string'),
            'audio': datasets.Audio(sampling_rate=24_000),
            'text': datasets.Value('string'),
        }))

  def _split_generators(self, dl_manager):
    print(self.config)
    downloaded_files = dl_manager.download_and_extract(
        _get_download_urls(self.config.name, self.config.languages))
    return [
        datasets.SplitGenerator(
            name=datasets.Split.TRAIN,
            gen_kwargs={
                'files': downloaded_files,
                'split': 'train'
            }),
        datasets.SplitGenerator(
            name=datasets.Split.VALIDATION,
            gen_kwargs={
                'files': downloaded_files,
                'split': 'dev'
            }),
        datasets.SplitGenerator(
            name=datasets.Split.TEST,
            gen_kwargs={
                'files': downloaded_files,
                'split': 'test'
            }),
    ]

  def _generate_examples(self, files, split):
    """Generates examples for each SplitGenerator."""
    for path in files:
      with open(os.path.join(path, f'{split}.tsv'), 'r', encoding='utf-8') as f:
        for line in f:
          cols = line.rstrip().split('\t')
          assert len(cols) == 2, cols
          key, text = cols
          audio = {'path': audio_path}
          
          yield key, {
              'id': key,
              'text': text,
              'audio': audio,
              'file': audio_path,
          }