Visual Grounding Tokens in Multimodal Models: The Gap Between Training and Inference
Multimodal models rely on structured tokens to connect natural language with image regions, yet these tokens often appear in the tokenizer configuration without ever showing up in actual outputs. This article explains how visual regions are represented as text (points, boxes, and polygons), how to inspect tokenizer configs for grounding-related special tokens, why those tokens may be missing during inference, and how to validate grounding capability through controlled experiments, decoding checks, and accuracy metrics.
1. Background: Why Multimodal Models Need Grounding
Pure text models process sequences of characters, while multimodal models must also understand spatial relationships in images. To answer questions like “What is the button in the top-left corner?” or “What is the value in the third row of the table?”, a model needs to point to a specific region. Describing the image content alone is not enough—the model must map language to pixel locations.
There are two common approaches in the industry. The first is to output coordinates directly, for example by writing the top-left and bottom-right corners of a rectangle as plain text. The second is to introduce dedicated structured tokens, letting the model embed region information while generating text, which is then decoded back into boxes, points, or polygons. The advantage of the latter approach is that region information shares the same autoregressive generation process as regular text, so the model does not need an additional detection head.
These capabilities are commonly referred to as visual grounding or referring expression comprehension. Both share a common prerequisite: the model must establish a correspondence between the object referred to in natural language and a region in the image.
2. Representing Visual Regions as Text: Points, Boxes, and Polygons
To write regions as text, the first problem to solve is the representation format. The table below compares three common forms.
| Type | Minimum data required | Typical use cases |
|---|---|---|
| Point | A single (x, y) coordinate | Pointing to a button, keypoint, or text position |
| Box | Top-left and bottom-right corners, or center plus width and height | Object detection, region cropping, text-line localization |
| Polygon | Multiple vertices in order | Irregular objects, document regions, mask contours |
Coordinate normalization is a step that must be made explicit in engineering. A common practice is to map raw pixel coordinates into a fixed range, such as 0 to 1000 or 0 to 1. This allows images of different resolutions to share the same representation and makes training data easier to align. The specific range should be determined based on the model’s documentation or actual test results—never assume it blindly.
The following example uses placeholder tokens solely to illustrate parsing logic; it does not correspond to the real vocabulary of any specific model:
import re# Example format: <BOX>x1,y1,x2,y2</BOX>, coordinates normalized to 0-1000BOX_PATTERN = re.compile(r"<BOX>(\d+),(\d+),(\d+),(\d+)</BOX>")def parse_boxes(text):boxes = []for m in BOX_PATTERN.finditer(text):x1, y1, x2, y2 = map(int, m.groups())boxes.append((x1, y1, x2, y2))return boxessample = "The login button is at <BOX>820,95,960,140</BOX>, and the input field is at <BOX>300,200,700,240</BOX>."print(parse_boxes(sample))
This code illustrates the core idea: the model outputs structured text, and the program extracts region information using rules. The parsing logic must be fault-tolerant against abnormal outputs, such as unclosed tokens, missing numbers, or out-of-range coordinates.
3. Inferring Structured Output Capability from the Tokenizer Configuration
A low-cost way to assess whether a model might have grounding capability is to inspect its tokenizer configuration. The tokenizer config is usually a JSON file, where the added_tokens field lists special tokens added to the vocabulary.
These special tokens have several key attributes:
- special: Whether the token is a control token. When true, most decoding pipelines treat it as a formatting symbol.
- normalized: Whether the token participates in text normalization. When false, the token is usually preserved as-is.
- lstrip / rstrip: Whether the token consumes adjacent whitespace.
- single_word: Whether the token only matches at standalone word boundaries.
Here is an example of reading the configuration:
import jsonwith open("tokenizer.json", "r", encoding="utf-8") as f:cfg = json.load(f)for tok in cfg.get("added_tokens", []):print(tok["id"], tok["content"], "special=", tok["special"])
It is important to emphasize that the presence of a token in the vocabulary only shows that the model was designed to reserve this form of expression. It does not prove the model has learned to emit the token in appropriate scenarios, let alone that a downstream inference service will parse it correctly. Both of these require separate verification.
4. Why These Tokens Don’t Appear in Actual Outputs
This is the most common confusion in engineering practice: the tokens exist in the configuration, yet they almost never appear in the generated text. There is usually more than one cause, and they can be checked step by step along the pipeline.
1. Special tokens are skipped during decoding. Most inference frameworks provide an option like skip_special_tokens in their decoding interface, and the default is often true. If a token is configured as a control token, it disappears from the decoded string even when the model generates it. This is the most easily overlooked—and most easily ruled out—cause.
2. The chat template does not trigger grounding behavior. The chat template determines how the system prompt, user input, and model response are organized. If the template contains no instructions guiding the behavior, the model may prefer to describe positions in natural language rather than emit structured tokens.
3. Grounding samples make up a small share of the training data. When a model is trained primarily on general QA data, it rarely encounters scenarios that require outputting coordinates. If the structured capability carries insufficient weight during training, it is unlikely to be activated at inference time.
4. The prompt does not explicitly request it. Asking “Where is the button?” directly versus requesting “Output the button’s location using region tokens” can produce entirely different results. Prompt wording significantly affects the output format.
5. Post-processing discards the structural information. Some services sanitize, escape, or truncate outputs, stripping content wrapped in angle brackets as illegal characters. During troubleshooting, check both the raw token sequence and the final returned string.
The basic troubleshooting method is layer-by-layer comparison: first look at the raw token IDs generated by the model, then compare the differences before and after decoding, and finally examine what the service returns.
# Pseudocode: compare the results of two decoding methodsraw_ids = model_generate(prompt) # raw token IDs generated by the modeltext_default = decode(raw_ids, skip_special_tokens=True)text_raw = decode(raw_ids, skip_special_tokens=False)if text_default != text_raw:print("Special tokens were filtered out during decoding")
5. Engineering Practice Recommendations
In real projects, proceed in the following order.
Step 1: Build a minimal validation set. Prepare a batch of annotated images, each paired with one or two clear region-related questions. The validation set should cover scenarios of different resolutions and complexity levels—avoid drawing conclusions from a single image.
Step 2: Fix decoding parameters. Record the temperature, maximum output length, special-token handling, and other parameters to ensure consistent conditions across experiments.
Step 3: Compute grounding accuracy. For box outputs, Intersection over Union (IoU) is commonly used to measure the overlap between predicted and annotated boxes. For point outputs, you can check whether the predicted point falls inside the annotated region. Choose metrics based on the task definition—don’t just look at whether something was output.
Step 4: Record failure modes. Common problems include coordinate misalignment, reversed box corner order, unclosed tokens, and confusion among multiple objects. Categorizing failure samples helps determine whether the problem lies in the prompt, the decoding, or the model itself.
6. Caveats and Boundaries
First, do not equate the presence of a token in the vocabulary with the presence of the capability. The definition of a special token is merely an interface convention; the capability must be confirmed through actual testing.
Second, the coordinate system must be consistent. Whether the origin is at the top-left or bottom-left, and whether coordinates are pixel values or normalized values—these conventions must match between training and inference, otherwise results will be systematically offset.
Third, the granularity of the region representation should match the task. Simple text localization only needs boxes; only contour segmentation of irregular objects requires polygons. Overly complex representations increase generation length and raise the probability of errors.
Fourth, output parsing must include boundary checks. Out-of-range coordinates, negative values, and zero-width or zero-height boxes should have a clear handling strategy rather than being passed directly downstream.
7. Summary
Visual grounding tokens are one way for multimodal models to connect language with image locations. Understanding them requires three steps: confirm from the tokenizer configuration which structured tokens the model reserves, verify through controlled experiments whether the model actually emits them during inference, and ensure through decoding and post-processing checks that the information is not lost along the pipeline. Tokens in the configuration are only the starting point—only verified behavior can serve as evidence of capability.
