﻿# Florence-2 task tokens: parse spatial output before using it as annotation

Use Florence-2 task prompts and task-aware postprocessing to turn generated strings into boxes, regions or captions without discarding structural tokens.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-florence2-task-token-structured-output/
Language: en

## Treat the prompt as a task selector

Florence-2 represents several vision tasks through a prompt-based interface. The [technical report](https://arxiv.org/abs/2311.06242) explains a unified visual representation, while the application still selects the requested task. A caption prompt and an object detection prompt do not ask for interchangeable answers. Preserve the exact task token with the input image and any accompanying text when storing an example for later comparison or annotation review.

## Keep structure during decoding

The [Transformers documentation](https://huggingface.co/docs/transformers/model_doc/florence2) shows generated token IDs decoded without discarding special tokens before task-aware postprocessing. A generic text-cleaning function can remove information the parser requires to reconstruct regions or coordinates. Maintain a distinction between a user-facing caption string and the intermediate generated representation. Readable output alone does not prove that the requested spatial structure survived the decoding path.

## Apply the parser for the actual task

Use the processor's `post_process_generation` with the selected task and the corresponding image size. The [official model card](https://huggingface.co/microsoft/Florence-2-base) provides released-model examples and supported tasks. Do not take a parser result from a caption pathway and label it as object detection merely because the original image contains recognizable objects. Validate the expected result fields before downstream software turns them into annotations or an application action.

## Preserve coordinate provenance

A spatial output must be mapped to the image dimensions used for interpretation. If a pipeline cropped, tiled or rotated the original photograph, record those transformations as well as the final image size passed to the parser. Test the parsed regions with an overlay before exporting them. A fluent label can accompany a geometrically misplaced region, so language plausibility and coordinate correctness need independent inspection in the same concrete example.

## Review generated annotations as model proposals

For a labeling workflow, retain the model version, task prompt, raw representation and parsed result until the review step has established what is acceptable. Distinguish an empty valid result from a parser failure. The guides to [image orientation](/journal/data-guide-image-exif-box-coordinate/) and [COCO annotation identity](/journal/data-guide-coco-instance-caption-identities/) provide useful supporting rules. Florence-2 adds a distinct boundary: generation and task-aware parsing must both succeed before a spatial output becomes a usable annotation proposal.
