holylovenia
commited on
Commit
•
d658879
1
Parent(s):
ebba23f
Upload id_msvd.py with huggingface_hub
Browse files- id_msvd.py +136 -0
id_msvd.py
ADDED
@@ -0,0 +1,136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import Dict, List, Tuple
|
3 |
+
|
4 |
+
import datasets
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
from seacrowd.utils.configs import SEACrowdConfig
|
8 |
+
from seacrowd.utils.constants import (SCHEMA_TO_FEATURES, TASK_TO_SCHEMA,
|
9 |
+
Licenses, Tasks)
|
10 |
+
|
11 |
+
_CITATION = """\
|
12 |
+
@article{hendria2023msvd,
|
13 |
+
author = {Willy Fitra Hendria},
|
14 |
+
title = {MSVD-Indonesian: A Benchmark for Multimodal Video-Text Tasks in Indonesian},
|
15 |
+
journal = {arXiv preprint arXiv:2306.11341},
|
16 |
+
year = {2023},
|
17 |
+
url = {https://arxiv.org/abs/2306.11341},
|
18 |
+
}
|
19 |
+
"""
|
20 |
+
|
21 |
+
_DATASETNAME = "id_msvd"
|
22 |
+
_DESCRIPTION = """\
|
23 |
+
MSVD-Indonesian is derived from the MSVD (Microsoft Video Description) dataset, which is
|
24 |
+
obtained with the help of a machine translation service (Google Translate API). This
|
25 |
+
dataset can be used for multimodal video-text tasks, including text-to-video retrieval,
|
26 |
+
video-to-text retrieval, and video captioning. Same as the original English dataset, the
|
27 |
+
MSVD-Indonesian dataset contains about 80k video-text pairs.
|
28 |
+
"""
|
29 |
+
|
30 |
+
_HOMEPAGE = "https://github.com/willyfh/msvd-indonesian"
|
31 |
+
_LANGUAGES = ["ind"]
|
32 |
+
_LICENSE = Licenses.MIT.value
|
33 |
+
_URLS = {"text": "https://raw.githubusercontent.com/willyfh/msvd-indonesian/main/data/MSVD-indonesian.txt", "video": "https://www.cs.utexas.edu/users/ml/clamp/videoDescription/YouTubeClips.tar"}
|
34 |
+
|
35 |
+
_SUPPORTED_TASKS = [Tasks.VIDEO_TO_TEXT_RETRIEVAL]
|
36 |
+
_SOURCE_VERSION = "1.0.0"
|
37 |
+
_SEACROWD_VERSION = "2024.06.20"
|
38 |
+
|
39 |
+
_LOCAL = False
|
40 |
+
|
41 |
+
|
42 |
+
class IdMsvdDataset(datasets.GeneratorBasedBuilder):
|
43 |
+
"""MSVD dataset with Indonesian translation."""
|
44 |
+
|
45 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
46 |
+
SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
|
47 |
+
|
48 |
+
SEACROWD_SCHEMA_NAME = TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower() # "vidtext"
|
49 |
+
|
50 |
+
BUILDER_CONFIGS = [
|
51 |
+
SEACrowdConfig(
|
52 |
+
name=f"{_DATASETNAME}_source",
|
53 |
+
version=SOURCE_VERSION,
|
54 |
+
description=f"{_DATASETNAME} source schema",
|
55 |
+
schema="source",
|
56 |
+
subset_id=f"{_DATASETNAME}",
|
57 |
+
),
|
58 |
+
SEACrowdConfig(
|
59 |
+
name=f"{_DATASETNAME}_seacrowd_{SEACROWD_SCHEMA_NAME}",
|
60 |
+
version=SEACROWD_VERSION,
|
61 |
+
description=f"{_DATASETNAME} SEACrowd schema",
|
62 |
+
schema=f"seacrowd_{SEACROWD_SCHEMA_NAME}",
|
63 |
+
subset_id=f"{_DATASETNAME}",
|
64 |
+
),
|
65 |
+
]
|
66 |
+
|
67 |
+
DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
|
68 |
+
|
69 |
+
def _info(self) -> datasets.DatasetInfo:
|
70 |
+
if self.config.schema == "source":
|
71 |
+
features = datasets.Features(
|
72 |
+
{
|
73 |
+
"video_path": datasets.Value("string"),
|
74 |
+
"text": datasets.Value("string"),
|
75 |
+
}
|
76 |
+
)
|
77 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
78 |
+
features = SCHEMA_TO_FEATURES[self.SEACROWD_SCHEMA_NAME.upper()] # video_features
|
79 |
+
|
80 |
+
return datasets.DatasetInfo(
|
81 |
+
description=_DESCRIPTION,
|
82 |
+
features=features,
|
83 |
+
homepage=_HOMEPAGE,
|
84 |
+
license=_LICENSE,
|
85 |
+
citation=_CITATION,
|
86 |
+
)
|
87 |
+
|
88 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
89 |
+
# expect several minutes to download video data ~1.7GB
|
90 |
+
data_path = dl_manager.download_and_extract(_URLS)
|
91 |
+
|
92 |
+
return [
|
93 |
+
datasets.SplitGenerator(
|
94 |
+
name=datasets.Split.TRAIN,
|
95 |
+
gen_kwargs={
|
96 |
+
"text_path": Path(data_path["text"]),
|
97 |
+
"video_path": Path(data_path["video"]) / "YouTubeClips",
|
98 |
+
"split": "train",
|
99 |
+
},
|
100 |
+
),
|
101 |
+
]
|
102 |
+
|
103 |
+
def _generate_examples(self, text_path: Path, video_path: Path, split: str) -> Tuple[int, Dict]:
|
104 |
+
"""Yields examples as (key, example) tuples."""
|
105 |
+
text_data = []
|
106 |
+
with open(text_path, "r", encoding="utf-8") as f:
|
107 |
+
for line in f:
|
108 |
+
id = line.find(" ")
|
109 |
+
video = line[:id]
|
110 |
+
text = line[id + 1 :].strip()
|
111 |
+
text_data.append([video, text])
|
112 |
+
|
113 |
+
df = pd.DataFrame(text_data, columns=["video_path", "text"])
|
114 |
+
df["video_path"] = df["video_path"].apply(lambda x: video_path / f"{x}.avi")
|
115 |
+
|
116 |
+
if self.config.schema == "source":
|
117 |
+
for i, row in df.iterrows():
|
118 |
+
yield i, {
|
119 |
+
"video_path": str(row["video_path"]),
|
120 |
+
"text": row["text"],
|
121 |
+
}
|
122 |
+
elif self.config.schema == f"seacrowd_{self.SEACROWD_SCHEMA_NAME}":
|
123 |
+
for i, row in df.iterrows():
|
124 |
+
yield i, {
|
125 |
+
"id": str(i),
|
126 |
+
"video_path": str(row["video_path"]),
|
127 |
+
"text": row["text"],
|
128 |
+
"metadata": {
|
129 |
+
"resolution": {
|
130 |
+
"width": None,
|
131 |
+
"height": None,
|
132 |
+
},
|
133 |
+
"duration": None,
|
134 |
+
"fps": None,
|
135 |
+
},
|
136 |
+
}
|