Download code/sft_templates.py from Joshkn/Distilled_handvqa: direct link, hf CLI and curl.
- Browser
- Download file 8.32 kB
-
https://huggingface.co/datasets/Joshkn/Distilled_handvqa/resolve/main/code/sft_templates.py
- Command line
-
hf download hf://datasets/Joshkn/Distilled_handvqa/code/sft_templates.py
-
curl -L -o sft_templates.py https://huggingface.co/datasets/Joshkn/Distilled_handvqa/resolve/main/code/sft_templates.py
8.32 kB
| """Synthetic tool rationales for HanDyVQA, not recorded teacher reasoning. | |
| Selection uses only the seed, question ID, and task type. It never reads answers | |
| or future observations. Each question has its own RNG, independent of row order. | |
| """ | |
| import json | |
| import random | |
| DEFAULT_SEED = 42 | |
| TEMPLATE_VERSION = "handyvqa-tools-v1" | |
| FIXED_REASONS = ( | |
| "I need to identify the visible entities relevant to the question.", | |
| "I need a scene description based on the recognized objects.", | |
| "I need temporal observations to assess the relevant motion and state evidence.", | |
| ) | |
| # Twenty alternatives per tool. Task-specific focus follows each selected text. | |
| RECOG_TEMPLATES = ( | |
| "I need to identify the visible entities before I assess the question.", | |
| "I will use object recognition to establish which entities are visible.", | |
| "I need a list of visible objects to guide further inspection.", | |
| "I will identify the objects that could provide evidence for the question.", | |
| "I need object recognition before I request more detailed scene evidence.", | |
| "I will check which entities appear in the video.", | |
| "I need to ground the question in the objects visible in the video.", | |
| "I will request object names before I examine their context.", | |
| "I need to identify possible subjects of the question in the video.", | |
| "I will inspect the video for visible objects before I interpret their roles.", | |
| "I need an initial inventory of visible entities.", | |
| "I will use recognition to identify objects for further analysis.", | |
| "I need to establish which objects the video shows.", | |
| "I will request visual object recognition to guide the next observation.", | |
| "I need to identify entities without treating the answer options as visual evidence.", | |
| "I will check the visible objects before I assess their properties or relationships.", | |
| "I need object identities to make the next scene description useful.", | |
| "I will identify candidate entities without selecting an answer yet.", | |
| "I need to connect the question to entities that the video actually shows.", | |
| "I will start with recognition of the visible objects.", | |
| ) | |
| CAPTION_TEMPLATES = ( | |
| "I need a scene description that places the recognized objects in context.", | |
| "I will request a description of the scene using the recognized objects.", | |
| "I need context beyond the object names before I assess the question.", | |
| "I will use captioning to describe the scene around the recognized entities.", | |
| "I need a broad description of what the recognized objects are doing or showing.", | |
| "I will examine the scene context for the recognized objects.", | |
| "I need a description of the objects and their visible relationships.", | |
| "I will request scene evidence before I interpret the object list.", | |
| "I need to understand how the recognized entities appear in this scene.", | |
| "I will use the object list to guide a scene description.", | |
| "I need visual context to connect the recognized objects to the question.", | |
| "I will ask for a scene description without selecting an answer yet.", | |
| "I need more than object identities to assess the visible situation.", | |
| "I will request a broad account of the scene and its recognized objects.", | |
| "I need a description of the visible context before a closer temporal check.", | |
| "I will examine the setting and relationships of the recognized entities.", | |
| "I need scene information that object recognition alone does not provide.", | |
| "I will request context for the recognized objects without assuming an unseen event.", | |
| "I need to connect the object list with the visible situation.", | |
| "I will use captioning to establish context for further observations.", | |
| ) | |
| TRACK_TEMPLATES = ( | |
| "I need observations across frames to assess the evidence relevant to the question.", | |
| "I will request tracking observations before I select an answer.", | |
| "I need a temporal check beyond the broad scene description.", | |
| "I will examine the relevant objects across frames.", | |
| "I need tracking evidence to assess the visible situation over time.", | |
| "I will request observations over time without assuming that a change occurs.", | |
| "I need to check what the video supports across its frames.", | |
| "I will use tracking to inspect the evidence beyond the scene overview.", | |
| "I need observations across frames before I interpret the relevant details.", | |
| "I will examine temporal evidence while preserving uncertainty about unseen details.", | |
| "I need a closer check of the relevant entities over time.", | |
| "I will request tracking evidence to support the answer with visible observations.", | |
| "I need to assess which details remain visible across frames.", | |
| "I will check the relevant observations over time before drawing a conclusion.", | |
| "I need temporal observations rather than assumptions based on a broad description.", | |
| "I will use tracking to examine details relevant to the question.", | |
| "I need evidence across frames without inferring hidden events.", | |
| "I will request a temporal account of the relevant objects.", | |
| "I need to inspect the visible evidence over time before choosing an option.", | |
| "I will examine the tracked observations without assuming motion or a state change.", | |
| ) | |
| TOOL_TEMPLATES = (RECOG_TEMPLATES, CAPTION_TEMPLATES, TRACK_TEMPLATES) | |
| # These specify evidence to seek, never observations or conclusions. | |
| TASK_FOCUS = { | |
| "state": ( | |
| "I will focus on entities whose visible condition could answer the question.", | |
| "I need context for the visible condition, without assuming a change.", | |
| "I need to distinguish a visible condition from an observed change.", | |
| ), | |
| "process": ( | |
| "I will focus on participants and objects involved in the queried activity.", | |
| "I need context for how the queried activity occurs.", | |
| "I need the order and manner of actions, where visible.", | |
| ), | |
| "location": ( | |
| "I will focus on the queried entity and possible spatial reference objects.", | |
| "I need context for the queried entity's position relative to other objects.", | |
| "I need evidence of position and spatial relationships at the relevant time, without assuming movement.", | |
| ), | |
| "parts": ( | |
| "I will focus on the queried object and any visible components.", | |
| "I need context for visible parts and their relationship to the whole object.", | |
| "I need observations of the queried parts across frames, without assuming that they change.", | |
| ), | |
| "general": ( | |
| "I will focus on entities relevant to the video question.", | |
| "I need scene context relevant to the video question.", | |
| "I need evidence relevant to the video question, without assuming a change.", | |
| ), | |
| } | |
| def template_metadata(template_mode="varied", seed=DEFAULT_SEED): | |
| if template_mode not in ("varied", "fixed"): | |
| raise ValueError("template_mode must be 'varied' or 'fixed'") | |
| if type(seed) is not int: | |
| raise ValueError("seed must be an integer") | |
| return {"template_mode": template_mode, "template_seed": seed if template_mode == "varied" else None, | |
| "template_version": TEMPLATE_VERSION if template_mode == "varied" else "legacy-fixed"} | |
| def tool_reasons(row, *, template_mode="varied", seed=DEFAULT_SEED): | |
| template_metadata(template_mode, seed) | |
| if template_mode == "fixed": | |
| return FIXED_REASONS | |
| task = row.get("question_type") | |
| if not task: | |
| task = str(row.get("question_id", "")).split("_", 1)[0] | |
| if not isinstance(task, str) or task not in TASK_FOCUS: | |
| task = "general" | |
| rng = random.Random(json.dumps([TEMPLATE_VERSION, seed, row.get("question_id"), task], ensure_ascii=False)) | |
| return tuple(rng.choice(candidates) + " " + focus | |
| for candidates, focus in zip(TOOL_TEMPLATES, TASK_FOCUS[task])) | |
| def add_template_arguments(parser): | |
| parser.add_argument("--template-mode", choices=("varied", "fixed"), default="varied", | |
| help="Select task-aware tool rationales, or retain the three legacy fixed texts") | |
| parser.add_argument("--seed", type=int, default=DEFAULT_SEED, | |
| help="Seed for per-question template selection (default: 42). Ignored in fixed mode or restore") | |