holylovenia commited on
Commit
9a62a5c
·
verified ·
1 Parent(s): cfd8065

Upload msl4emergency.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. msl4emergency.py +161 -0
msl4emergency.py ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ SEA Crowd Data Loader for MSL4Emergency.
3
+ """
4
+ import os
5
+ from typing import Dict, Generator, List, Tuple
6
+
7
+ import datasets
8
+ from datasets.download.download_manager import DownloadManager
9
+
10
+ from seacrowd.utils import schemas
11
+ from seacrowd.utils.configs import SEACrowdConfig
12
+ from seacrowd.utils.constants import TASK_TO_SCHEMA, Licenses, Tasks
13
+
14
+ _CITATION = """
15
+ @article{
16
+ msl4emergency,
17
+ title={Statistical Machine Translation between Myanmar Sign Language and Myanmar Written Text},
18
+ url={https://core.ac.uk/outputs/489828410?source=oai},
19
+ journal={CORE},
20
+ author={Moe, Swe Zin and Thu, Ye Kyaw and Hlaing, Hnin Wai Wai and Nwe, Hlaing Myat and Aung, Ni Htwe and Thant, Hnin Aye and Min, Nandar Win},
21
+ year={2018},
22
+ month={Mar}
23
+ }
24
+ """
25
+
26
+ logger = datasets.logging.get_logger(__name__)
27
+
28
+ _LOCAL = False
29
+ _LANGUAGES = ["ysm", "mya"]
30
+
31
+ _DATASETNAME = "msl4emergency"
32
+ _DESCRIPTION = """
33
+ The MSL4Emergency corpus is part of a larger Myanmar sign language (MSL) corpus that specifically contains sign language videos for the emergency domain.
34
+ Each signing video is annotated with both its transcription and its Burmese written translation, which may differ from each other due to grammar, syntax and vocabulary differences between MSL and Burmese.
35
+ Signing videos were made by sign language trainers and deaf trainees.
36
+ """
37
+
38
+ _HOMEPAGE = "https://github.com/ye-kyaw-thu/MSL4Emergency/tree/master"
39
+ _LICENSE = Licenses.CC_BY_NC_SA_4_0.value
40
+
41
+ _URL = "https://github.com/ye-kyaw-thu/MSL4Emergency/archive/refs/heads/master.zip"
42
+
43
+ _SUPPORTED_TASKS = [Tasks.MACHINE_TRANSLATION, Tasks.SIGN_LANGUAGE_RECOGNITION]
44
+ _SOURCE_VERSION = "1.0.0"
45
+ _SEACROWD_VERSION = "2024.06.20"
46
+
47
+ _CONFIG_SUFFIXES_FOR_TASK = [TASK_TO_SCHEMA.get(task).lower() for task in _SUPPORTED_TASKS]
48
+
49
+
50
+ class MSL4EmergencyDataset(datasets.GeneratorBasedBuilder):
51
+ """MSL4Emergency dataset"""
52
+
53
+ BUILDER_CONFIGS = [
54
+ SEACrowdConfig(
55
+ name=f"{_DATASETNAME}_source",
56
+ version=datasets.Version(_SOURCE_VERSION),
57
+ description=f"{_DATASETNAME} source schema",
58
+ schema="source",
59
+ subset_id=_DATASETNAME)
60
+ ] + [
61
+ SEACrowdConfig(
62
+ name=f"{_DATASETNAME}_seacrowd_{cfg_sufix}",
63
+ version=datasets.Version(_SEACROWD_VERSION),
64
+ description=f"{_DATASETNAME} seacrowd schema for {task.name}",
65
+ schema=f"seacrowd_{cfg_sufix}",
66
+ subset_id=_DATASETNAME)
67
+ for task, cfg_sufix in zip(_SUPPORTED_TASKS, _CONFIG_SUFFIXES_FOR_TASK)
68
+ ]
69
+
70
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
71
+
72
+ def _info(self) -> datasets.DatasetInfo:
73
+ _config_schema_name = self.config.schema
74
+ logger.info(f"Received schema name: {self.config.schema}")
75
+
76
+ if _config_schema_name == "source":
77
+ features = datasets.Features({
78
+ "id": datasets.Value("string"),
79
+ "mya_text": datasets.Value("string"),
80
+ "ysm_text": datasets.Value("string"),
81
+ "video_url": datasets.Value("string")
82
+ })
83
+
84
+ # speech-text schema
85
+ elif _config_schema_name == "seacrowd_t2t":
86
+ features = schemas.text2text_features
87
+
88
+ elif _config_schema_name == "seacrowd_imtext":
89
+ features = schemas.image_text_features()
90
+
91
+ else:
92
+ raise ValueError(f"Received unexpected config schema of {_config_schema_name}!")
93
+
94
+ return datasets.DatasetInfo(
95
+ description=_DESCRIPTION,
96
+ features=features,
97
+ homepage=_HOMEPAGE,
98
+ license=_LICENSE,
99
+ citation=_CITATION,
100
+ )
101
+
102
+ def _split_generators(self, dl_manager: DownloadManager) -> List[datasets.SplitGenerator]:
103
+ local_path = dl_manager.download_and_extract(_URL)
104
+ local_path = os.path.join(local_path.title(), "MSL4Emergency-master", "msl4emergency-ver-1.0")
105
+
106
+ base_video_dir = os.path.join(local_path, "video")
107
+ video_dir_list = []
108
+ for _child_dir in os.listdir(base_video_dir):
109
+ _full_child_dir = os.path.join(base_video_dir, _child_dir)
110
+ if os.path.isdir(_full_child_dir):
111
+ video_dir_list.extend([os.path.join(_full_child_dir, video_fp) for video_fp in os.listdir(_full_child_dir) if video_fp.endswith(".mp4")])
112
+
113
+ text_path = os.path.join(local_path, "my-sl")
114
+ with open(text_path, "r", encoding="utf-8") as f:
115
+ text_data = [data.split("\t") for data in f.readlines()]
116
+
117
+ return [
118
+ datasets.SplitGenerator(
119
+ name=datasets.Split.TRAIN,
120
+ gen_kwargs={
121
+ "video_dir_list": video_dir_list,
122
+ "text_data": text_data
123
+ })
124
+ ]
125
+
126
+ def _generate_examples(self, video_dir_list: list, text_data: list) -> Generator[Tuple[int, Dict], None, None]:
127
+ _config_schema_name = self.config.schema
128
+
129
+ idx = 1
130
+ for video_path in video_dir_list:
131
+ mya_text, ysm_text = text_data[idx - 1]
132
+ if _config_schema_name == "source":
133
+ yield idx, {
134
+ "id": idx,
135
+ "mya_text": mya_text.strip(),
136
+ "ysm_text": ysm_text.strip(),
137
+ "video_url": video_path}
138
+
139
+ elif _config_schema_name == "seacrowd_t2t":
140
+ yield idx, {
141
+ "id": idx,
142
+ "text_1": mya_text.strip(),
143
+ "text_2": ysm_text.strip(),
144
+ "text_1_name": "target_mya",
145
+ "text_2_name": "source_ysm"}
146
+
147
+ elif _config_schema_name == "seacrowd_imtext":
148
+ yield idx, {
149
+ "id": idx,
150
+ "image_paths": [video_path],
151
+ "texts": ysm_text.strip(),
152
+ "metadata": {
153
+ "context": "myanmar sign language transcribed",
154
+ "labels": None,
155
+ },
156
+ }
157
+
158
+ else:
159
+ raise ValueError(f"Received unexpected config schema of {_config_schema_name}!")
160
+
161
+ idx += 1