Datasets:

Languages:
English
ArXiv:
License:
SeJinPark commited on
Commit
976ddd0
·
1 Parent(s): 70868b8

Dataloader

Browse files
Files changed (1) hide show
  1. MultiDialog.py +75 -0
MultiDialog.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from datasets import load_dataset, DatasetInfo, DatasetDict, SplitGenerator, Split, Features, Value, Audio
4
+
5
+ _DESCRIPTION = """
6
+ Custom version of the Common Voice dataset with additional test_freq split including custom audio and metadata.
7
+ """
8
+
9
+ _CITATION = """
10
+ @inproceedings{commonvoice:2020,
11
+ author = {Ardila, R. and Branson, M. and Davis, K. and Henretty, M. and Kohler, M. and Meyer, J. and Morais, R. and Saunders, L. and Tyers, F. M. and Weber, G.},
12
+ title = {Common Voice: A Massively-Multilingual Speech Corpus},
13
+ booktitle = {Proceedings of the 12th Conference on Language Resources and Evaluation (LREC 2020)},
14
+ year = 2020
15
+ }
16
+ """
17
+
18
+ _HOMEPAGE = "https://commonvoice.mozilla.org/en/datasets"
19
+ _LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
20
+
21
+ class CustomCommonVoice(datasets.GeneratorBasedBuilder):
22
+ """Builder for a modified Common Voice dataset including a custom test_freq split."""
23
+
24
+ VERSION = datasets.Version("1.0.0")
25
+
26
+ BUILDER_CONFIGS = [
27
+ datasets.BuilderConfig(name="test_freq", description="Custom rare test split of the Common Voice dataset."),
28
+ ]
29
+
30
+ DEFAULT_CONFIG_NAME = "test_freq" # Default configuration to use if none specified.
31
+
32
+ def _info(self):
33
+ return DatasetInfo(
34
+ description=_DESCRIPTION,
35
+ features=Features({
36
+ "id": Value("string"),
37
+ "utterance": Value("int32"),
38
+ "from": Value("string"),
39
+ "value": Value("string"),
40
+ "emotion": Value("string"),
41
+ "file_name": Value("string"),
42
+ "audio": Audio(sampling_rate=16_000),
43
+ }),
44
+ supervised_keys=("audio", "value"),
45
+ homepage=_HOMEPAGE,
46
+ citation=_CITATION,
47
+ license=_LICENSE,
48
+ )
49
+
50
+ def _split_generators(self, dl_manager):
51
+ """Returns SplitGenerators."""
52
+ test_freq_dir = os.path.abspath("test_freq") # Adjust path as needed
53
+ test_freq_metadata = os.path.join(test_freq_dir, "metadata.jsonl")
54
+
55
+ return [
56
+ SplitGenerator(
57
+ name=Split.TEST,
58
+ gen_kwargs={"metadata_path": test_freq_metadata, "audio_dir": test_freq_dir}),
59
+ ]
60
+
61
+ def _generate_examples(self, metadata_path, audio_dir):
62
+ """Yields examples."""
63
+ with open(metadata_path, 'r', encoding='utf-8') as f:
64
+ for line in f:
65
+ metadata = json.loads(line)
66
+ audio_path = os.path.join(audio_dir, metadata['file_name'])
67
+ yield metadata['id'], {
68
+ "id": metadata['id'],
69
+ "utterance": metadata['utterance'],
70
+ "from": metadata['from'],
71
+ "value": metadata['value'],
72
+ "emotion": metadata['emotion'],
73
+ "file_name": metadata['file_name'],
74
+ "audio": audio_path,
75
+ }