CLIP Image Tokenization
A vision tokenizer that turns fixed-size image patches into embedding vectors for transformer-style image encoders.
CLIP-style image tokenization divides an image into a grid of fixed-size patches, projects each patch into a vector token, and feeds that patch-token sequence into a transformer-style image encoder. These patch tokens are not text tokens; they are learned visual units that let vision models reuse the same attention machinery as language models.
At a glance
Released
February 2021
Authors
Alec Radford, Jong Wook Kim, Chris Hallacy, et al.
Optimizes
- Fixed Grid Image Input
- Shared Vision Transformer Input
What It Is
CLIP image tokenization is a vision tokenizer that converts a raw image into a sequence of patch tokens. The image is split into a regular grid of small squares, each square is flattened into a pixel vector, and a learned linear projection turns that vector into one embedding token. The resulting tokens are the discrete units a vision transformer consumes, similar in role to text tokens in a language model but built from local image regions instead of characters or subwords.Why It Exists
Transformer blocks expect a sequence of vectors, not a raw height-by-width pixel grid. Image tokenization bridges that gap by turning local image structure into a fixed-length token stream the encoder can process with self-attention. A regular patch grid also keeps the input shape predictable, which simplifies batching, position handling, and reuse of standard transformer stacks across images of the same resolution.How It Works
A typical CLIP-style vision encoder starts from a square image such as 224×224 pixels. A patch size of 16×16 yields a 14×14 grid, so the tokenizer produces 196 patch tokens before any optional class token is added. Each patch is flattened into a vector of raw pixel values, then multiplied by a learned projection matrix to produce one embedding per patch. Those embeddings form the token sequence passed into the image encoder. Position information is added separately through positional embeddings or another position mechanism, because the patch tokenizer itself mainly defines what each token represents, not where it sits in the grid.Input imageSplit into fixed-size patchesFlatten each patch to a pixel vectorProject each patch with a learned matrixPatch embedding tokensToken sequence for image encoderInput image to Split into fixed-size patchesSplit into fixed-size patches to Flatten each patch to a pixel vectorFlatten each patch to a pixel vector to Project each patch with a learned matrixProject each patch with a learned matrix to Patch embedding tokensPatch embedding tokens to Token sequence for image encoder
Math Or Compute Schema
The two formulas below separate the tokenizer into its two core steps. First, the image becomes a grid of patches. Second, each patch vector is projected into one embedding token.- Set of non-overlapping image patches covering the input.
- Number of patch rows after tiling the image.
- Number of patch columns after tiling the image.
- Flattened pixel vector for the patch at grid row i and column j.
Compared To Nearby Modules
Text tokenizers such as byte pair encoding (BPE) build tokens from learned text pieces or bytes. CLIP image tokenization instead builds tokens from fixed spatial patches in a pixel grid. Both produce a sequence the model can attend over, but the input alphabet, training objective, and failure modes differ. Image patch tokens inherit local visual context from their square region; text tokens inherit linguistic context from subword statistics.| Comparison dimension | CLIP Image Tokenization | BPE |
|---|---|---|
| Input type | Fixed-resolution images | Unicode text strings |
| Base unit | Equal-size pixel patches from a regular grid | Learned subword pieces built from frequent symbol merges |
| Output form | One learned embedding vector per patch | Discrete token ids from a text vocabulary |
| Main tradeoff | Simple and resolution-stable, but patch size locks local detail and sequence length | Flexible open-vocabulary text coverage, but pieces are linguistic rather than spatial |