anya-ji commited on
Commit
2f7a34f
·
1 Parent(s): 3020f38

dataset script

Browse files
Files changed (1) hide show
  1. dataset.py +84 -0
dataset.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import csv
2
+ import os
3
+ from pathlib import Path
4
+ from typing import Dict, Iterable, Any, Tuple
5
+
6
+ import datasets
7
+
8
+ # -------- CONFIG -------- #
9
+ CSV_AUDIO_COL = "audio_segment_path"
10
+ CSV_VIDEO_NO_AUDIO_COL = "video_noaudio_segment_path"
11
+ CSV_VIDEO_WITH_AUDIO_COL = "video_withaudio_segment_path"
12
+
13
+ _DESCRIPTION = """\
14
+ VADA-AVSR: an audio-visual dataset of non-native English ("accents") and English varieties ("dialects")
15
+ """
16
+
17
+ _LICENSE = ""
18
+
19
+ # ------------------------ #
20
+
21
+ class VisualAccentDialectArchive(datasets.GeneratorBasedBuilder):
22
+ """DatasetBuilder for VADA (with audio + two video fields)."""
23
+
24
+ VERSION = datasets.Version("1.0.0")
25
+
26
+ def _info(self) -> datasets.DatasetInfo:
27
+ return datasets.DatasetInfo(
28
+ description=_DESCRIPTION,
29
+ features=datasets.Features(
30
+ {
31
+ "utt_id": datasets.Value("string"),
32
+ "filename": datasets.Value("string"),
33
+ "segment_id": datasets.Value("int64"),
34
+ "start": datasets.Value("float64"),
35
+ "end": datasets.Value("float64"),
36
+ "confidence": datasets.Value("float64"),
37
+ "text": datasets.Value("string"),
38
+ "audio": datasets.Audio(),
39
+ "video_no_audio": datasets.Video(),
40
+ "video_with_audio": datasets.Video(),
41
+ }
42
+ ),
43
+ homepage="https://huggingface.co/datasets/Berkeley-NLP/visual_accent_dialect_archive",
44
+ license=_LICENSE,
45
+ )
46
+
47
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
48
+ # Paths are relative inside the repo snapshot
49
+ # This loads them via dl_manager even if local or hub
50
+ base_dir = Path(dl_manager.download_config.dataset_path or "")
51
+
52
+ csv_file = base_dir / "test.csv"
53
+ return [
54
+ datasets.SplitGenerator(
55
+ name=datasets.Split.TEST,
56
+ gen_kwargs={"csv_file": str(csv_file), "base_path": str(base_dir)},
57
+ ),
58
+ ]
59
+
60
+ def _generate_examples(
61
+ self, csv_file: str, base_path: str
62
+ ) -> Iterable[Tuple[int, Dict[str, Any]]]:
63
+ base = Path(base_path)
64
+
65
+ with open(csv_file, encoding="utf-8") as f:
66
+ reader = csv.DictReader(f)
67
+ for idx, row in enumerate(reader):
68
+ # Make local absolute path for each media reference
69
+ audio_path = str(base / row[CSV_AUDIO_COL])
70
+ noaudio_path = str(base / row[CSV_VIDEO_NO_AUDIO_COL])
71
+ withaudio_path = str(base / row[CSV_VIDEO_WITH_AUDIO_COL])
72
+
73
+ yield idx, {
74
+ "utt_id": str(row["utt_id"]),
75
+ "filename": str(row["filename"]),
76
+ "segment_id": int(float(row["segment_id"])),
77
+ "start": float(row["start"]),
78
+ "end": float(row["end"]),
79
+ "confidence": float(row["confidence"]),
80
+ "text": str(row["text"]),
81
+ "audio": audio_path,
82
+ "video_no_audio": noaudio_path,
83
+ "video_with_audio": withaudio_path,
84
+ }