fesvhtr commited on
Commit
399df25
·
verified ·
1 Parent(s): 8d46aec

Add files using upload-large-folder tool

Browse files
README.md CHANGED
@@ -1,5 +1,87 @@
1
  ---
2
- license: cc-by-nc-sa-4.0
3
  task_categories:
4
- - question-answering
5
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: unknown
3
  task_categories:
4
+ - video-text-to-text
5
+ configs:
6
+ - config_name: default
7
+ data_files:
8
+ - split: full
9
+ path: data/all.parquet
10
+ - split: test
11
+ path: data/test.parquet
12
+ ---
13
+
14
+ # CUVA
15
+
16
+ ## Repository Layout
17
+
18
+ ```text
19
+ data/
20
+ all.parquet
21
+ test.parquet
22
+ raw/
23
+ cuva_gt_cleaned.json
24
+ cuva_test.json
25
+ cuva_test_filled.json
26
+ group_0.zip
27
+ group_1.zip
28
+ group_2.zip
29
+ group_3.zip
30
+ scripts/
31
+ build_hf_repo.py
32
+ fill_cuva_test.py
33
+ ```
34
+
35
+ ## Split Layout
36
+
37
+ Splits:
38
+
39
+ - `full`: backed by `data/all.parquet`, which contains `raw/cuva_gt_cleaned.json` + `raw/cuva_test_filled.json`
40
+ - `test`: `raw/cuva_test_filled.json`
41
+
42
+ Columns:
43
+
44
+ - `instruction`
45
+ - `visual_input`
46
+ - `output`
47
+ - `task`
48
+ - `ID`
49
+
50
+ ## Build
51
+
52
+ ```bash
53
+ python scripts/fill_cuva_test.py --repo-root .
54
+ python scripts/build_hf_repo.py --repo-root .
55
+ ```
56
+
57
+ The build script moves the original JSON and zip files into `raw/` if they are still in the repository root, then writes `data/all.parquet` and `data/test.parquet`.
58
+
59
+ ## Load from Hugging Face Hub
60
+
61
+ ```python
62
+ from datasets import load_dataset
63
+
64
+ all_ds = load_dataset("your-name/CUVA", split="full")
65
+ test_ds = load_dataset("your-name/CUVA", split="test")
66
+ ```
67
+
68
+ ## Load from Local Files
69
+
70
+ ```python
71
+ from datasets import load_dataset
72
+
73
+ ds = load_dataset(
74
+ "parquet",
75
+ data_files={
76
+ "full": "data/all.parquet",
77
+ "test": "data/test.parquet",
78
+ },
79
+ )
80
+ ```
81
+
82
+ ## Notes
83
+
84
+ - The parquet files preserve the original column names.
85
+ - The raw source files remain in `raw/` without renaming.
86
+ - Because `output` and `ID` are mixed-type in the original JSON files, the parquet export stores them as strings so both splits share one stable schema.
87
+ - `all.parquet` keeps the requested filename, but Hugging Face `datasets` reserves `all` as a special keyword, so the loadable split name must be `full` rather than `all`.
data/all.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b813fff5e96f8c98a06147c814b24ed67de00ef59fbb257a6f7f8d2c1607bee7
3
+ size 275322
data/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:82110759f1d76dada223ec55b57405c2e0093dc81ebb3e13435c86cf39800dda
3
+ size 64602
raw/cuva_gt_cleaned.json ADDED
The diff for this file is too large to render. See raw diff
 
raw/cuva_test.json ADDED
The diff for this file is too large to render. See raw diff
 
raw/cuva_test_filled.json ADDED
The diff for this file is too large to render. See raw diff
 
raw/group_0.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96f3a9dae5f06ae1cf9534f9b0e6436d50f5d9ee5573d23628c839eeaa5c51d0
3
+ size 7567343144
raw/group_1.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e013359eb4dbccddacf548dc50f118d0d01eaf5b1cc64d4c69960a91e92e9fa8
3
+ size 7621985066
raw/group_2.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f5fb4436b8118312b08effb50fcd30ea28134ac8c917ec85ddfb2406f49ce0cd
3
+ size 7721863044
raw/group_3.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7453919185729de8645cafd50f2c099008bccf4b7d42eb5a3bf7f17491a76cf8
3
+ size 2734787473
scripts/build_hf_repo.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ import shutil
4
+ from pathlib import Path
5
+
6
+ import pandas as pd
7
+ import pyarrow as pa
8
+ import pyarrow.parquet as pq
9
+
10
+
11
+ RAW_JSON_FILES = [
12
+ "cuva_gt_cleaned.json",
13
+ "cuva_test.json",
14
+ "cuva_test_filled.json",
15
+ ]
16
+
17
+ VIDEO_ARCHIVES = [
18
+ "group_0.zip",
19
+ "group_1.zip",
20
+ "group_2.zip",
21
+ "group_3.zip",
22
+ ]
23
+
24
+ PARQUET_COLUMNS = ["instruction", "visual_input", "output", "task", "ID"]
25
+
26
+
27
+ def load_json(path: Path):
28
+ with path.open("r", encoding="utf-8") as f:
29
+ return json.load(f)
30
+
31
+
32
+ def move_raw_files(repo_root: Path, raw_dir: Path) -> None:
33
+ raw_dir.mkdir(parents=True, exist_ok=True)
34
+ for filename in RAW_JSON_FILES + VIDEO_ARCHIVES:
35
+ src = repo_root / filename
36
+ dst = raw_dir / filename
37
+ if src.exists() and not dst.exists():
38
+ shutil.move(str(src), str(dst))
39
+
40
+
41
+ def normalize_rows(rows):
42
+ normalized = []
43
+ for row in rows:
44
+ normalized.append(
45
+ {
46
+ "instruction": row["instruction"],
47
+ "visual_input": row["visual_input"],
48
+ "output": str(row["output"]),
49
+ "task": row["task"],
50
+ "ID": str(row["ID"]),
51
+ }
52
+ )
53
+ return normalized
54
+
55
+
56
+ def write_parquet(rows, output_path: Path) -> None:
57
+ df = pd.DataFrame(normalize_rows(rows), columns=PARQUET_COLUMNS)
58
+ schema = pa.schema(
59
+ [
60
+ ("instruction", pa.string()),
61
+ ("visual_input", pa.string()),
62
+ ("output", pa.string()),
63
+ ("task", pa.string()),
64
+ ("ID", pa.string()),
65
+ ]
66
+ )
67
+ output_path.parent.mkdir(parents=True, exist_ok=True)
68
+ table = pa.Table.from_pandas(df, schema=schema, preserve_index=False)
69
+ pq.write_table(table, output_path)
70
+
71
+
72
+ def main():
73
+ parser = argparse.ArgumentParser(description="Build a HF-style CUVA dataset repo with raw files and parquet splits.")
74
+ parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parent.parent)
75
+ args = parser.parse_args()
76
+
77
+ repo_root = args.repo_root.resolve()
78
+ raw_dir = repo_root / "raw"
79
+ data_dir = repo_root / "data"
80
+
81
+ move_raw_files(repo_root, raw_dir)
82
+
83
+ gt_rows = load_json(raw_dir / "cuva_gt_cleaned.json")
84
+ test_rows = load_json(raw_dir / "cuva_test_filled.json")
85
+ all_rows = gt_rows + test_rows
86
+
87
+ write_parquet(test_rows, data_dir / "test.parquet")
88
+ write_parquet(all_rows, data_dir / "all.parquet")
89
+
90
+ print(f"Built parquet splits under: {data_dir}")
91
+ print(f"test rows: {len(test_rows)}")
92
+ print(f"all rows: {len(all_rows)}")
93
+
94
+
95
+ if __name__ == "__main__":
96
+ main()
scripts/fill_cuva_test.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import json
3
+ from pathlib import Path
4
+
5
+
6
+ DETECTION_INSTRUCTION = (
7
+ "Determine whether the video contains an anomalous event. "
8
+ "Output 1 if an anomaly is present."
9
+ )
10
+
11
+ EXPECTED_TEST_TASKS = {
12
+ "Classification",
13
+ "Cause",
14
+ "Result",
15
+ "Timestamp",
16
+ "Description",
17
+ "Detection",
18
+ }
19
+
20
+
21
+ def load_json(path: Path):
22
+ with path.open("r", encoding="utf-8") as f:
23
+ return json.load(f)
24
+
25
+
26
+ def dump_json(path: Path, data) -> None:
27
+ with path.open("w", encoding="utf-8") as f:
28
+ json.dump(data, f, ensure_ascii=False, indent=2)
29
+ f.write("\n")
30
+
31
+
32
+ def build_instruction_map(gt_rows):
33
+ task_to_instruction = {}
34
+ for row in gt_rows:
35
+ task = row["task"]
36
+ instruction = row["instruction"]
37
+ existing = task_to_instruction.get(task)
38
+ if existing is None:
39
+ task_to_instruction[task] = instruction
40
+ elif existing != instruction:
41
+ raise ValueError(f"Task {task!r} has multiple instructions in gt")
42
+ return task_to_instruction
43
+
44
+
45
+ def fill_test_rows(test_rows, task_to_instruction):
46
+ filled = []
47
+ for row in test_rows:
48
+ task = row["task"]
49
+ if task == "Detection":
50
+ instruction = DETECTION_INSTRUCTION
51
+ else:
52
+ if task not in task_to_instruction:
53
+ raise KeyError(f"Missing instruction mapping for task {task!r}")
54
+ instruction = task_to_instruction[task]
55
+
56
+ filled.append(
57
+ {
58
+ "instruction": instruction,
59
+ "visual_input": row["visual_input"],
60
+ "output": row["output"],
61
+ "task": row["task"],
62
+ "ID": row["ID"],
63
+ }
64
+ )
65
+ return filled
66
+
67
+
68
+ def resolve_data_dir(repo_root: Path) -> Path:
69
+ raw_dir = repo_root / "raw"
70
+ return raw_dir if raw_dir.exists() else repo_root
71
+
72
+
73
+ def main():
74
+ parser = argparse.ArgumentParser(description="Fill missing instructions in CUVA test annotations.")
75
+ parser.add_argument("--repo-root", type=Path, default=Path(__file__).resolve().parent.parent)
76
+ args = parser.parse_args()
77
+
78
+ repo_root = args.repo_root.resolve()
79
+ data_dir = resolve_data_dir(repo_root)
80
+
81
+ gt_path = data_dir / "cuva_gt_cleaned.json"
82
+ test_path = data_dir / "cuva_test.json"
83
+ output_path = data_dir / "cuva_test_filled.json"
84
+
85
+ gt_rows = load_json(gt_path)
86
+ test_rows = load_json(test_path)
87
+
88
+ task_to_instruction = build_instruction_map(gt_rows)
89
+ test_tasks = {row["task"] for row in test_rows}
90
+ unknown_tasks = test_tasks - EXPECTED_TEST_TASKS
91
+ if unknown_tasks:
92
+ raise ValueError(f"Unexpected tasks in test set: {sorted(unknown_tasks)}")
93
+
94
+ filled_rows = fill_test_rows(test_rows, task_to_instruction)
95
+ dump_json(output_path, filled_rows)
96
+
97
+ print(f"Wrote {len(filled_rows)} rows to {output_path}")
98
+
99
+
100
+ if __name__ == "__main__":
101
+ main()