Video-Dependent Grammars: Constraining What a Video Model May Say, Not Just How

Language models that describe video are now asked to produce machine-readable output: tool calls, object itineraries, timestamped event lists, scene graphs. Two separate failures break these pipelines. The first is syntactic. The output does not parse, and frontier multimodal agents lose whole task chains to malformed JSON and bad tool arguments (Agent-X). The second is semantic. The output parses but names an object that never appears, or a time interval when nothing happened. Grammar-constrained decoding solves the first problem well. In this technique an automaton tracks the partial output and blocks every next token that would break the grammar. It does nothing for the second problem.

This proposal makes the grammar depend on the video. A cheap 3D convolutional network scans the clip as a volume of space and time. It proposes which objects exist, when they are present or moving, and roughly where they are. Those proposals then become the allowed vocabulary in the object, time and location slots of the output grammar. The language model keeps full freedom over reasoning and ordering. It cannot emit a claim that the video evidence rules out. The question is whether this hard, evidence-derived restriction reduces grounding errors on structured video reasoning tasks. The comparison points are syntax-only constrained decoding, fine-tuning on structured templates, and the simpler option of putting the same proposals in the prompt.

Core Claim

Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning introduced input-dependent grammars, whose allowed terminals change with each input. For entity disambiguation, the grammar admits only that sentence's candidate entities, and this alone raised LLaMA-33B accuracy from 54.1% to 80.3%. That result is the motivation here. When the candidate set is good, restricting the output to it is worth far more than syntax enforcement. Our claim is that the same move transfers to video. The candidate sets are object tracks with time intervals and coarse locations. They are extracted by a 3D convolutional evidence model rather than by text-side retrieval. The prediction is that on tasks whose answers are structured and time-indexed, such as object itineraries, stationary-object localization and video tool arguments, this video-dependent grammar will cut hallucinated entities and wrong timestamps well beyond what syntax-only masking achieves. It should also do so at a predictable cost: the system can only be as right as the proposer's recall.

The decoding rule is standard masked decoding with a grammar that is a function of the video $V$:

$$p(y_t \mid y_{<t}, V) \propto p_\theta(y_t \mid y_{<t}, V)\,\mathbb{1}[\,y_{<t}y_t \in \mathrm{Prefix}(G(E_\phi(V)))\,]$$

Here $p_\theta$ is the language model's next-token distribution. $E_\phi(V)$ is the evidence volume the 3D network produces from the video. $G(\cdot)$ builds a grammar from that evidence. $\mathrm{Prefix}(G)$ is the set of strings that can still be completed into a valid sentence of $G$. The new part is $G(E_\phi(V))$. The masking machinery itself is reused.

Research Program

The evidence model is a voxel-to-voxel encoder-decoder in the style of Deep End2End Voxel2Voxel Prediction. That design is a C3D-style 3D convolutional encoder (Learning Spatiotemporal Features with 3D Convolutional Networks) followed by 3D transposed convolutions with skip connections. It outputs per-voxel class presence and a motion channel over the clip. We pick it for two reasons. First, it is fast: V2V reports 91.6 FPS and C3D reports 313 FPS. That speed lets it sweep long videos in sliding windows, which matters because EgoReasoner reports trouble with 8–10 minute videos that exceed its context. Second, it is temporally consistent. V2V reports 76.0% versus 55.7% for 2D baselines on GATECH segmentation, which matters because interval boundaries are exactly what the grammar will encode.

One caution comes from V2V itself. Features pretrained for classification discard the low-level motion filters needed for dense motion. We therefore train the evidence model directly on dense targets: object-presence intervals and motion from Action Genome relationship annotations and from egocentric training data. We do not reuse a classification backbone frozen.

From the volume we extract a candidate table. Each row holds an object class, its active time intervals, and a coarse spatial cell. The grammar has a fixed skeleton per task, for example the JSON schema of an itinerary or a tool call. Its object, time and region terminals are drawn from this table. Time terminals carry a tolerance that matches the task's grading window, such as the ±2 s temporal grounding used by EgoReasoner.

Every grammar also contains an explicit UNKNOWN terminal. Hard masking is unforgiving, so this escape keeps a proposer miss from forcing a confident wrong answer.

The proposer threshold $\tau$ is set on held-out data. The goal is that candidate recall, meaning the fraction of ground-truth answer entities and intervals that survive into the table, is at least $1-\delta$. The analysis sweeps $\delta$ to trace the precision–recall trade-off the grammar inherits.

The grammar skeleton is fixed and only the terminal sets change per video. Per-video cost is therefore a set of masks over a precomputed lexicon of class names and numerals, and no grammar is recompiled. Masking runs on a SynCode-style automaton mask store (SynCode) or the faster transducer-based tables of GREATGRAMMA, which reports 5–32 ms per token. The method requires logit access, so all language models are open-weight. We say plainly that closed APIs are out of scope.

Baselines

The naive reference point is an off-the-shelf open video-language model given uniformly sampled frames, prompted with the output schema, and decoded without constraints. On HD-EPIC, EgoReasoner reports Qwen2.5-VL-7B at 25.7% average accuracy, which anchors this floor.

The strongest existing method on our main benchmark is EgoReasoner. It applies supervised fine-tuning on task-specific thinking templates, then reinforcement fine-tuning with entity, temporal and logic rewards. It reports 37.5% average accuracy on HD-EPIC with a 3B model, and 59.5% on object movement counting. It is the right competitor because it attacks the same grounding problem through training rather than decoding. We run our decoder on the same 3B base, and also on top of an EgoReasoner-style fine-tuned checkpoint trained with the same Ego-Exo4D kitchen data budget. Beating it means exceeding 37.5% average accuracy at matched model size. It also means a lower rate of hallucinated entities and out-of-window timestamps, scored automatically against annotations.

Syntax-only constrained decoding uses the same base model with the same schema enforced by the automaton, but with open object, time and region slots. Any gain it shows over the naive model is the "plumbing" effect. Any further gain from our method is attributable to the video-dependent terminals.

The ablation that isolates the key ingredient puts the identical candidate table into the prompt as text, without masking. A second variant does both. A 2D-proposer ablation replaces the 3D evidence model with a per-frame 2D network plus temporal smoothing, tuned to the same parameter count and the same compute. An oracle-grammar run builds the grammar from ground-truth annotations to measure the ceiling. All variants share the base model, frame budget, prompts, and an equal hyperparameter search budget.

On Action Genome, which we use as a grounding diagnostic, the strongest reported system is VOST-SGG. It seeds a one-stage scene-graph detector with Qwen2.5-VL proposals and reports PredCLS mR@10 of 46.5, up from 42.1.

Why not just…?

Why not just put the candidates in the prompt? This is the real threat. STSBench shows that text-only GPT-4o given ground-truth trajectory coordinates reaches 57.08%, while pixel-fed VLMs reach 29.33%–46.07%. Giving a model structured evidence as text clearly helps. What prompting does not do is stop the model from ignoring that evidence or inventing beyond it. The entity-disambiguation jump in the constrained-decoding paper came from masking, not from listing candidates. The prompt-only ablation decides this question. If it matches masking on accuracy and hallucination rate, the contribution reduces to "the 3D proposer is a good retriever," and we will report it that way.

Why not just fine-tune on structured templates, as EgoReasoner does? Fine-tuning teaches format and some grounding, but it gives no guarantee. Unconstrained LLaMA produced valid parse trees only about 64% of the time in the constrained-decoding study. That study also reports constrained decoding without fine-tuning beating a supervised model on information extraction (F1 36.0 vs 34.8). EgoReasoner itself notes that task-agnostic reinforcement learning destabilized its spatial tasks. The two approaches are not exclusive, so we test the decoder on top of the fine-tuned model. The interesting outcome is whether masking still adds grounding accuracy after fine-tuning.

Why not just validate and retry, or skip the language model and read answers off the detector? Retry loops fix syntax but resample from the same distribution. They do not make the model consult the video, and Agent-X shows frontier models still below 50% full-chain success. We include parse-and-retry with up to three attempts as an extra baseline on the format metrics. Reading answers directly off the 3D network works for closed-vocabulary scene graphs, where a classifier head is already "grammatical." For that reason we do not claim gains on Action Genome PredCLS against VOST-SGG. The language model earns its place only on tasks that need composition, such as itineraries, counting across intervals, and tool arguments. Those tasks are where we evaluate.

Proposed Experiments

The main experiment is on HD-EPIC. We report average accuracy and per-task accuracy, with emphasis on itinerary tracking and stationary-object localization. Alongside accuracy we measure parse validity, the hallucinated-entity rate, and the fraction of emitted timestamps outside the ±2 s window. Results cover all baselines above and are stratified by video length, to test whether the sliding 3D proposer helps on long videos where EgoReasoner struggles.

The first decisive check is the gap between masking and prompt-only on hallucination rate. The second is the gap between the 3D and 2D proposer on interval errors. The third is the recall curve: accuracy should track proposer recall and saturate toward the oracle grammar. If gains instead peak and fall as $\delta$ shrinks, the UNKNOWN escape is being misused.

The secondary experiment uses the video subset of Agent-X, restricted to tasks whose tool arguments contain objects or time spans. We measure goal accuracy and the format-error rate for open models under the same baselines. No reported result was found on Lacuna for open models on this subset. The closest anchor is o4-mini's 45% goal accuracy on the full benchmark, which is not directly comparable.

On Action Genome we evaluate the proposer's interval recall and the hallucination rate of grammar-constrained scene-graph generation. This is a diagnostic, not a leaderboard claim.

Latency is reported end to end: proposer FPS, plus per-token masking overhead, plus total time per query. Masking overhead is expected in the 1–32 ms per token range reported by the constrained-decoding papers above.