fix(loader): use video_id from JSON data instead of filename

load_benchmark used the JSON filename stem as video_id, which broke
v2-360 questions (all 180 questions got video_id='accepted_questions').
Now uses qa['video_id'] when present, falls back to filename for
Video-MME format compatibility.
This commit is contained in:
2026-07-14 01:02:55 -04:00
parent dec7346da3
commit 9ee37a8534
+7 -4
View File
@@ -21,8 +21,10 @@ _LEGACY_DEFAULT_DIFFICULTY = "medium"
def load_benchmark(questions_dir: Path) -> list[GeneratedQuestion]: def load_benchmark(questions_dir: Path) -> list[GeneratedQuestion]:
"""从 benchmark JSON 目录加载题目列表。 """从 benchmark JSON 目录加载题目列表。
每个 JSON 文件以文件名(不含扩展名)作为 video_id, video_id 优先使用题目 JSON 中的 ``video_id`` 字段;若缺失则回退到
文件内容为题目数组。 文件名(不含扩展名)。Video-MME benchmark 按视频拆文件(文件名即
video_id),v2 生成题把多视频题目合并在单个 JSON 中(每条记录自带
``video_id``),两种格式均兼容。
参数: 参数:
questions_dir: 包含 *.json 文件的目录路径。 questions_dir: 包含 *.json 文件的目录路径。
@@ -32,20 +34,21 @@ def load_benchmark(questions_dir: Path) -> list[GeneratedQuestion]:
""" """
results: list[GeneratedQuestion] = [] results: list[GeneratedQuestion] = []
for path in sorted(questions_dir.glob("*.json")): for path in sorted(questions_dir.glob("*.json")):
video_id = path.stem fallback_video_id = path.stem
with open(path, encoding="utf-8") as f: with open(path, encoding="utf-8") as f:
qa_list: list[dict] = json.load(f) qa_list: list[dict] = json.load(f)
for qa in qa_list: for qa in qa_list:
results.append( results.append(
GeneratedQuestion( GeneratedQuestion(
question_id=qa["question_id"], question_id=qa["question_id"],
video_id=video_id, video_id=qa.get("video_id", fallback_video_id),
task_type=qa["task_type"], task_type=qa["task_type"],
question=qa["question"], question=qa["question"],
options=tuple(qa["options"]), options=tuple(qa["options"]),
answer=qa["answer"], answer=qa["answer"],
source_nodes=tuple(qa.get("source_nodes", ())), source_nodes=tuple(qa.get("source_nodes", ())),
difficulty=qa.get("difficulty", _LEGACY_DEFAULT_DIFFICULTY), difficulty=qa.get("difficulty", _LEGACY_DEFAULT_DIFFICULTY),
family=qa.get("family"),
skill_target=qa.get("skill_target"), skill_target=qa.get("skill_target"),
difficulty_steps=qa.get("difficulty_steps"), difficulty_steps=qa.get("difficulty_steps"),
) )