Excellent question! This is a specialized and increasingly important area of computer vision that goes beyond traditional image recognition. Models that create embeddings based mainly on the text within an image are different from standard models like ResNet or ViT, which focus on visual features like shapes, colors, and textures.
These text-centric image models are crucial for tasks like document understanding, visual question answering about text, and searching for images based on signs or labels.
Here’s a breakdown of the models and approaches, categorized from simple pipelines to sophisticated end-to-end systems.
1. Two-Stage Approach: OCR + Text Embedding (The Classic Pipeline)
This is the most straightforward and often very effective method. It's not a single "model" but a pipeline you construct.
How it works:
- Optical Character Recognition (OCR): First, you use an OCR model to extract all the text from the image. You also get the bounding boxes (coordinates) of where each word or line of text is located.
- Popular OCR Tools: Tesseract, EasyOCR, Keras-OCR, Google Cloud Vision API, AWS Textract.
- Text Embedding: You take the extracted text and feed it into a standard text embedding model. This model converts the text into a dense vector (embedding).
- Popular Text Embedding Models: Sentence-Transformers (e.g.,
all-MiniLM-L6-v2), OpenAI's text-embedding-3-small, or any BERT-based model.
How it "uses mainly text":
The final embedding is derived entirely from the OCR'd text. You can optionally combine this text embedding with a standard image embedding (from a ViT or ResNet) to get a hybrid representation, but the core text information comes from this pipeline.
- Pros: Simple to implement, highly interpretable, uses best-in-class components for each task.
- Cons: Prone to error propagation (if OCR fails, the embedding is useless), loses the visual context and spatial layout of the text unless you explicitly encode the bounding box information.
2. End-to-End Multimodal Models (Sophisticated & Context-Aware)
These are single models designed to understand both pixels and text simultaneously. They are generally more powerful as they learn the relationship between the visual appearance of text and its semantic meaning.
A. Models for Document Understanding (Text-Heavy Images)
These models are the most direct answer to your question for documents, forms, and receipts. They are specifically designed to fuse text, its layout, and visual information.
-
LayoutLM Family (Microsoft):
- How it works: This is a BERT-like transformer model that takes in both text embeddings and 2D position embeddings. It processes the OCR'd text but also knows where on the page that text appeared. This allows it to understand document structure (headers, tables, lists).
- LayoutLMv3 is a truly multimodal version that also processes the image pixels, making it less reliant on a separate OCR tool.
- Best for: Scanned documents, forms, invoices, and structured text.
-
Donut (Naver AI Lab):
- How it works: Stands for Document Understanding Transformer. It's an end-to-end model that takes an image as input and generates structured text (like JSON) as output, without needing a separate OCR engine. It learns to "read" directly from pixels.
- Its internal encoder creates an embedding that is inherently based on reading the text in the image.
- Best for: "OCR-free" document parsing, especially for things like receipts.
-
Pix2Struct (Google):
- How it works: A versatile model trained to "parse" visual information into a simplified format. It was pre-trained by taking screenshots of web pages and learning to reconstruct the underlying HTML. This task forces it to read text, understand its hierarchy, and interpret its layout.
- It is exceptionally good at creating embeddings from images containing a mix of text and graphics, like diagrams, charts, and app UIs.
- Best for: Screenshots, user interfaces, scientific charts, and complex diagrams.
B. General-Purpose Vision-Language Models with Strong OCR
These models weren't built just for text in images, but their massive training on web-scale data has given them powerful, emergent capabilities to read and understand text in natural scenes.
-
CLIP (and its variants like OpenCLIP):
- How it works: CLIP learns to associate an entire image with a text caption. While it doesn't perform explicit OCR, it learns to recognize the visual patterns of words. For example, it knows what the word "STOP" looks like on a red octagonal sign.
- How it uses text: It associates the visual representation of text with its semantic meaning. If an image is dominated by a large sign, the CLIP embedding will be heavily influenced by the visual features of that sign's text. It's less "reading" and more "recognizing a visual word."
- Best for: General-purpose image search where text might be one of many important features (e.g., finding a picture of a "Coca-Cola can").
-
Florence-2 (Microsoft):
- How it works: A modern, powerful vision foundation model that can perform many tasks. It has a specific "OCR with Region" capability, showing it can precisely locate and read text. Its core vision encoder, which generates the embeddings, is trained on this data.
- The embeddings from Florence-2 are highly sensitive to the text present in the image.
- Best for: A state-of-the-art, all-purpose model that has excellent text-reading abilities for both documents and natural scenes.
-
LLaVA / GPT-4V (Vision Encoders):
- How it works: These are Large Multimodal Models (LMMs) that can "see" and describe images. While you typically interact with them via text generation, their power comes from a sophisticated vision encoder (often a variant of CLIP trained on more data) that creates a detailed embedding of the image. This embedding is then interpreted by a Large Language Model.
- The vision encoder in these models is excellent at capturing text information because the model has been trained to answer questions like "What does the sign in this image say?". The embedding must contain that information for the LLM to access it.
- Best for: Getting state-of-the-art representations, though extracting the raw embedding can be more complex than using a standalone model.
Summary Table & How to Choose
| Model / Approach | Type | How it Uses Text | Best Use Case |
|---|
| OCR + Text Embedding | Pipeline | Extracts text first, then embeds it. Purely semantic. | Simple, controllable tasks. When text content is all that matters. |
| CLIP / OpenCLIP | General Vision-Language | Recognizes the visual pattern of words as part of the overall scene. | General image search where text is one of many visual cues. |
| LayoutLM Family | Document AI | Fuses text content with its 2D position on the page. | Invoices, forms, resumes, and structured documents. |
| Donut / Pix2Struct | End-to-End Visual Language Model | "Reads" directly from pixels, understanding layout and content together. | "OCR-free" document parsing, UIs, charts, and diagrams. |
| Florence-2 / LLaVA (Encoder) | Large Multimodal Model (Foundation Model) | Deeply integrates pixel data and has strong, emergent OCR from massive training. | State-of-the-art performance on complex, in-the-wild images. |
How to Choose:
- For scanned documents or forms: Start with LayoutLMv3 or Donut.
- For screenshots of apps or websites: Pix2Struct is the perfect choice.
- For photos of street signs, product labels, or posters (text in the wild): Florence-2 or the vision encoder from a model like LLaVA would be best. A Two-Stage Pipeline is also a very strong and simple-to-implement alternative here.
- For general image search that should be aware of text: CLIP is a good baseline.