|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""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 = os.path.join(path, split, f'{key}.wav') |
|
yield key, { |
|
'id': key, |
|
'text': text, |
|
'audio': audio_path, |
|
'file': audio_path, |
|
} |
|
|