Back to Multimodal Mind Map
中文·English
👁️ MultimodalID: masked-cross-entropy

Masked Cross-Entropy Loss

Masked Cross-Entropy
🎯Core Definition
Masked Cross-Entropy (Masked CE) is the standard VLM training loss — sequence-level next-token prediction that computes loss only on assistant (model-answer) text tokens, masking gradients of user-instruction tokens and all vision patch tokens: L=tassistantlogpθ(ytx<t)\mathcal{L} = -\sum_{t \in \text{assistant}} \log p_\theta(y_t \mid x_{<t}) The input is x=[v1,,vN,u1,,um,a1,,aL]x = [v_1, \dots, v_N, u_1, \dots, u_m, a_1, \dots, a_L] (vision patches → user instruction → assistant answer); causal attention sees all tokens, but only tassistantt \in \text{assistant} positions contribute loss — exactly the LLM SFT labels mechanism where non-supervised positions are set to ignore_index\text{ignore\_index} (e.g. -100). Why mask: (1) vision patch tokens have no "next token" supervision target (they come from the frozen encoder, they are not generation targets) — CE on them forces patch-sequence prediction, pointless and harmful to text learning; (2) user instructions are not content the model should generate — predicting them teaches the model to parrot the user; (3) compute efficiency — with high-resolution inputs, vision tokens dominate the sequence (336×336, patch 14 → 576 vision tokens, often 85–90% of the sequence), so masking cuts backward-computation roughly an order of magnitude. An optional 1/L1/L normalizes by supervised-token count.
💡Use Cases
the standard objective across all VLM stages (alignment/pretraining/SFT); interview follow-ups on how the multimodal loss is written and whether vision tokens are supervised; it also links to why hallucination correlates with missing vision gradients (see the multimodal-hallucination card).
Key Problems Solved
naively computing CE over the whole sequence makes the model learn to predict image patches and echo user questions, wasting 85–90% of compute and degrading generation quality; Masked CE concentrates supervision on what the model should actually generate (assistant text), mirroring the ignore_index mechanism of LLM chat templates — the design that unifies VLM and LLM training objectives.
🎯5 High-Frequency Exam Points
1
Write the masked-CE formula; which tokens are masked and why?
2
What goes wrong if you compute CE on vision patch tokens?
3
With vision tokens at 85–90% of the sequence, how does masking affect compute (336×336→576 patches)?
4
How does masked CE correspond to the ignore_index=-100 mechanism of LLM SFT?
5
Why mask user instructions too? What would the model learn otherwise?
Updated 2026-08-12
🎯
Test Your Knowledge: Practice Questions for "Masked Cross-Entropy Loss"
Single choice pitfall questions with instant feedback and mistake tracking.
🚀 Start Card Practice
Previous CardVLM 3-Stage PipelineNext CardMultimodal DPO / RLHF-V

🔗 More Multimodal Knowledge Cards

ASR (Whisper)Audio RepresentationClassifier-Free GuidanceCLIP Applications