fesvhtr commited on
Commit
5540f6f
·
verified ·
1 Parent(s): f1b564e

Update FunQA dataset repo

Browse files
.gitattributes CHANGED
@@ -56,3 +56,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
56
  Funqa_mcqa_v1.json filter=lfs diff=lfs merge=lfs -text
57
  FunQA_train.json filter=lfs diff=lfs merge=lfs -text
58
  FunQA_val.json filter=lfs diff=lfs merge=lfs -text
 
 
 
 
56
  Funqa_mcqa_v1.json filter=lfs diff=lfs merge=lfs -text
57
  FunQA_train.json filter=lfs diff=lfs merge=lfs -text
58
  FunQA_val.json filter=lfs diff=lfs merge=lfs -text
59
+ raw/Funqa_mcqa_v1.json filter=lfs diff=lfs merge=lfs -text
60
+ raw/FunQA_train.json filter=lfs diff=lfs merge=lfs -text
61
+ raw/FunQA_val.json filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ __pycache__/
2
+ scripts/__pycache__/
3
+ hf_ready/
README.md CHANGED
@@ -2,8 +2,173 @@
2
  license: cc-by-nc-sa-4.0
3
  task_categories:
4
  - video-text-to-text
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  ---
6
 
7
  # Dataset for the paper: FunQA: Towards Surprising Video Comprehension
8
 
9
- Paper: https://huggingface.co/papers/2306.14899.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: cc-by-nc-sa-4.0
3
  task_categories:
4
  - video-text-to-text
5
+ configs:
6
+ - config_name: standard
7
+ data_files:
8
+ - split: train
9
+ path: data/train.parquet
10
+ - split: validation
11
+ path: data/validation.parquet
12
+ - split: test
13
+ path: data/test.parquet
14
+ - config_name: mcqa
15
+ data_files:
16
+ - split: mcqa_test
17
+ path: data/mcqa_test.parquet
18
  ---
19
 
20
  # Dataset for the paper: FunQA: Towards Surprising Video Comprehension
21
 
22
+ Paper: https://huggingface.co/papers/2306.14899.
23
+
24
+ ## Repository Layout
25
+
26
+ ```text
27
+ data/
28
+ train.parquet
29
+ validation.parquet
30
+ test.parquet
31
+ mcqa_test.parquet
32
+ videos/
33
+ train/
34
+ train_humor/
35
+ train_magic/
36
+ train_creative/
37
+ validation/
38
+ val_humor/
39
+ val_magic/
40
+ val_creative/
41
+ test/
42
+ test_humor/
43
+ test_magic/
44
+ test_creative/
45
+ raw/
46
+ FunQA_train.json
47
+ FunQA_val.json
48
+ FunQA_test.json
49
+ Funqa_mcqa_v1.json
50
+ train.zip
51
+ val.zip
52
+ test.zip
53
+ ```
54
+
55
+ ## Dataset Configs
56
+
57
+ ### `standard`
58
+
59
+ Splits:
60
+
61
+ - `train`
62
+ - `validation`
63
+ - `test`
64
+
65
+ Columns:
66
+
67
+ - `instruction`
68
+ - `visual_input`
69
+ - `output`
70
+ - `task`
71
+
72
+ ### `mcqa`
73
+
74
+ Splits:
75
+
76
+ - `mcqa_test`
77
+
78
+ Columns:
79
+
80
+ - `instruction`
81
+ - `visual_input`
82
+ - `gt`
83
+ - `id`
84
+
85
+ ## Load from Hugging Face Hub
86
+
87
+ ```python
88
+ from datasets import load_dataset
89
+
90
+ train_ds = load_dataset("your-name/FunQA", "standard", split="train")
91
+ val_ds = load_dataset("your-name/FunQA", "standard", split="validation")
92
+ test_ds = load_dataset("your-name/FunQA", "standard", split="test")
93
+ mcqa_ds = load_dataset("your-name/FunQA", "mcqa", split="mcqa_test")
94
+ ```
95
+
96
+ `load_dataset(...)` loads and caches the annotation files used by the selected config/split. It does not automatically download unrelated archive files in the repository.
97
+
98
+ ## Load from Local Files
99
+
100
+ ```python
101
+ from datasets import load_dataset
102
+
103
+ standard_ds = load_dataset(
104
+ "parquet",
105
+ data_files={
106
+ "train": "data/train.parquet",
107
+ "validation": "data/validation.parquet",
108
+ "test": "data/test.parquet",
109
+ },
110
+ )
111
+
112
+ mcqa_ds = load_dataset(
113
+ "parquet",
114
+ data_files={"mcqa_test": "data/mcqa_test.parquet"},
115
+ )
116
+ ```
117
+
118
+ ## Download Video Archives
119
+
120
+ If you want the original video files, download the split archives explicitly from the dataset repository.
121
+
122
+ Download one archive into the Hugging Face cache:
123
+
124
+ ```python
125
+ from huggingface_hub import hf_hub_download
126
+
127
+ zip_path = hf_hub_download(
128
+ repo_id="your-name/FunQA",
129
+ repo_type="dataset",
130
+ filename="raw/test.zip",
131
+ )
132
+ print(zip_path)
133
+ ```
134
+
135
+ Download the whole repository snapshot:
136
+
137
+ ```python
138
+ from huggingface_hub import snapshot_download
139
+
140
+ repo_dir = snapshot_download(
141
+ repo_id="your-name/FunQA",
142
+ repo_type="dataset",
143
+ )
144
+ print(repo_dir)
145
+ ```
146
+
147
+ If needed, download files to a specific local folder instead of only using the default cache:
148
+
149
+ ```python
150
+ from huggingface_hub import snapshot_download
151
+
152
+ repo_dir = snapshot_download(
153
+ repo_id="your-name/FunQA",
154
+ repo_type="dataset",
155
+ local_dir="funqa_local",
156
+ )
157
+ ```
158
+
159
+ After extracting the archives, locate a video by combining the split directory with `visual_input`:
160
+
161
+ ```python
162
+ from pathlib import Path
163
+
164
+ sample = test_ds[0]
165
+ video_name = sample["visual_input"]
166
+ video_path = next(Path("videos/test").rglob(video_name))
167
+ print(video_path)
168
+ ```
169
+
170
+ ## Notes
171
+
172
+ - The parquet files preserve the original JSON field names.
173
+ - `standard` and `mcqa` are separated into different configs because they use different schemas.
174
+ - The video archives are stored as repository files and should be downloaded explicitly with `huggingface_hub` if you need the raw videos.
data/mcqa_test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f03243af6d661ecba0231f928170fde2a8ee0076de852ca472a80e25ba868ec
3
+ size 2360096
data/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e3a0ca7a6d116cae1fb6af42ceb377ff94bcbd24567fb6a91961c8f43c52d3c
3
+ size 439872
data/train.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54eaf1646004d47af8688c706db6f9b09c407cf90b5473a7621cf65a67237c82
3
+ size 4419969
data/validation.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e8f5bc3bc5b3c2b6bd5e1a4143bbc762a817b45022cc77835a7c708894b2b59e
3
+ size 1054679
raw/FunQA_test.json ADDED
The diff for this file is too large to render. See raw diff
 
raw/FunQA_train.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff7dfd324420dada09f56c1d246bb0a9a037fedb2da25c675331783d108f1051
3
+ size 72819488
raw/FunQA_val.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a51686b522ae7ea11e1bcc97f7fd955e30d8633ddac8ed71ceaf290f030b691d
3
+ size 20439060
raw/Funqa_mcqa_v1.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dfb6604ba1b7e2a67c931d88f626a0fd094143b1e7eb3514246dafc8e086f0b8
3
+ size 11439964
raw/test.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18f29fa0a22e92828b7680401ce59424724fc806927f12b8c4a21aed508a7cca
3
+ size 2295981312
raw/train.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f9fe22d63dff39bf767df14b36a52233a2ab41fcbb53bd831e7915454b07483
3
+ size 17441899850
raw/val.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6f3675cdd655b014b8460c9a39c78159dda1ed6e6318b60a15387a91be53fa3e
3
+ size 4760814400
scripts/build_hf_repo.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ import shutil
4
+ import zipfile
5
+ from pathlib import Path
6
+
7
+ import pandas as pd
8
+ import pyarrow as pa
9
+ import pyarrow.parquet as pq
10
+
11
+
12
+ RAW_FILES = {
13
+ "train": "FunQA_train.json",
14
+ "validation": "FunQA_val.json",
15
+ "test": "FunQA_test.json",
16
+ "mcqa_test": "Funqa_mcqa_v1.json",
17
+ }
18
+
19
+ VIDEO_ARCHIVES = {
20
+ "validation": "val.zip",
21
+ "test": "test.zip",
22
+ "train": "train.zip",
23
+ }
24
+
25
+
26
+ def load_raw_rows(raw_dir: Path, split: str):
27
+ with (raw_dir / RAW_FILES[split]).open("r", encoding="utf-8") as f:
28
+ rows = json.load(f)
29
+ if split == "validation":
30
+ missing_videos = {"C_KT_6_6347_6427.mp4"}
31
+ rows = [row for row in rows if row.get("visual_input") not in missing_videos]
32
+ return rows
33
+
34
+
35
+ def write_parquet(rows, output_path: Path):
36
+ df = pd.DataFrame(rows)
37
+ output_path.parent.mkdir(parents=True, exist_ok=True)
38
+
39
+ if "output" in df.columns:
40
+ schema = pa.schema(
41
+ [
42
+ ("instruction", pa.string()),
43
+ ("visual_input", pa.string()),
44
+ ("output", pa.string()),
45
+ ("task", pa.string()),
46
+ ]
47
+ )
48
+ df = df[["instruction", "visual_input", "output", "task"]]
49
+ else:
50
+ schema = pa.schema(
51
+ [
52
+ ("instruction", pa.string()),
53
+ ("visual_input", pa.string()),
54
+ ("gt", pa.string()),
55
+ ("id", pa.string()),
56
+ ]
57
+ )
58
+ df = df[["instruction", "visual_input", "gt", "id"]]
59
+
60
+ table = pa.Table.from_pandas(df, schema=schema, preserve_index=False)
61
+ pq.write_table(table, output_path)
62
+
63
+
64
+ def move_raw_files(repo_root: Path, raw_dir: Path):
65
+ raw_dir.mkdir(parents=True, exist_ok=True)
66
+ for filename in list(RAW_FILES.values()) + list(VIDEO_ARCHIVES.values()):
67
+ src = repo_root / filename
68
+ dst = raw_dir / filename
69
+ if src.exists() and not dst.exists():
70
+ shutil.move(str(src), str(dst))
71
+
72
+
73
+ def extract_split_videos(raw_dir: Path, videos_dir: Path, split: str):
74
+ archive_name = VIDEO_ARCHIVES[split]
75
+ archive_path = raw_dir / archive_name
76
+ if not archive_path.exists():
77
+ return
78
+ videos_dir.mkdir(parents=True, exist_ok=True)
79
+ marker = videos_dir / f".{split}_extracted"
80
+ if marker.exists():
81
+ return
82
+ with zipfile.ZipFile(archive_path) as zf:
83
+ zf.extractall(videos_dir)
84
+ marker.write_text("ok\n", encoding="utf-8")
85
+
86
+
87
+ def normalize_video_layout(videos_dir: Path, split: str):
88
+ alias = {"validation": "val"}.get(split, split)
89
+ alias_root = videos_dir / alias
90
+ expected_root = videos_dir / split
91
+ if alias_root.exists() and alias_root != expected_root and not expected_root.exists():
92
+ shutil.move(str(alias_root), str(expected_root))
93
+
94
+ legacy_root = videos_dir / split / split
95
+ if legacy_root.exists():
96
+ expected_root.mkdir(parents=True, exist_ok=True)
97
+ for child in legacy_root.iterdir():
98
+ target = expected_root / child.name
99
+ if not target.exists():
100
+ shutil.move(str(child), str(target))
101
+
102
+ legacy_alias_root = videos_dir / split / alias
103
+ if legacy_alias_root.exists():
104
+ expected_root.mkdir(parents=True, exist_ok=True)
105
+ for child in legacy_alias_root.iterdir():
106
+ target = expected_root / child.name
107
+ if not target.exists():
108
+ shutil.move(str(child), str(target))
109
+
110
+
111
+ def ensure_layout(repo_root: Path):
112
+ move_raw_files(repo_root, repo_root / "raw")
113
+ for split in ["test", "validation", "train"]:
114
+ extract_split_videos(repo_root / "raw", repo_root / "videos", split)
115
+ normalize_video_layout(repo_root / "videos", split)
116
+
117
+
118
+ def main():
119
+ parser = argparse.ArgumentParser(description="Build a HF Hub-style FunQA dataset repo with original columns.")
120
+ parser.add_argument("--repo-root", type=Path, default=Path("."))
121
+ args = parser.parse_args()
122
+
123
+ repo_root = args.repo_root.resolve()
124
+ ensure_layout(repo_root)
125
+
126
+ raw_dir = repo_root / "raw"
127
+ data_dir = repo_root / "data"
128
+
129
+ for split in RAW_FILES:
130
+ rows = load_raw_rows(raw_dir, split)
131
+ write_parquet(rows, data_dir / f"{split}.parquet")
132
+
133
+ print(f"Built parquet splits under: {data_dir}")
134
+
135
+
136
+ if __name__ == "__main__":
137
+ main()