---
title: "Introducing TextImage Augmentation for Document Images"
description: "Albumentations adds a TextImage transform that augments document images and their text annotations together, so vision-language models fine-tuned on small document datasets see text-preserving variations."
url: "https://swe.quest/articles/introducing-textimage-augmentation-for-document-images-9f0736935fc8d1ff"
canonical: "https://huggingface.co/blog/doc_aug_hf_alb"
source: "Hugging Face"
published: "2024-08-06"
difficulty: "medium"
kind: "How-to"
reading_minutes: 7
tags: ["computer-vision","model-training","python"]
---

# Introducing TextImage Augmentation for Document Images

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2024-08-06, 7 min read, How-to. Original: [https://huggingface.co/blog/doc\_aug\_hf\_alb](https://huggingface.co/blog/doc_aug_hf_alb)

## Summary

Albumentations adds a TextImage transform that augments document images and their text annotations together, so vision-language models fine-tuned on small document datasets see text-preserving variations. It picks random text lines (fraction\_range), applies word-level edits (random swap, deletion, or stopword insertion), blacks out and inpaints the original line, and re-renders the new text sized from the bounding box (font\_size\_fraction\_range). The transform composes with other Albumentations transforms such as PlanckianJitter and Affine, returns the altered text and bounding boxes via overlay\_data for training labels, and can render arbitrary text onto templates to generate synthetic data. Synonym replacement was dropped because of its time overhead.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Computer vision](https://swe.quest/tags/computer-vision.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- Python image processing ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- data augmentation basics
- bounding box formats

## Keywords

Albumentations, TextImage, Vision Language Models, NLTK, IDL dataset, PDFA dataset, SynthDOG

## Related posts

- [A Dive into Vision-Language Models](https://swe.quest/articles/a-dive-into-vision-language-models-1c708a70976bf2ac.md): Hugging Face · 2023-02-03 · Hard · 18 min read · Computer vision, Model training, Machine learning, LLMs
  Vision-language models pair an image encoder and a text encoder with a strategy for fusing the two, and the pre-training objective determines which downstream tasks they handle well.
- [Open Preference Dataset for Text-to-Image Generation by the 🤗 Community](https://swe.quest/articles/open-preference-dataset-for-text-to-image-generation-by-the-community-51063f2eca79d4de.md): Hugging Face · 2024-12-09 · Easy · 7 min read · Model training, Computer vision, Evaluation, Open source
  Data is Better Together released an Apache 2.0 text-to-image preference dataset of 10K pairs, with over 30K annotations from more than 250 community members collected in under two weeks.
- [Introducing Idefics2: A Powerful 8B Vision-Language Model for the community](https://swe.quest/articles/introducing-idefics2-a-powerful-8b-vision-language-model-for-the-community-abaf7f042823c369.md): Hugging Face · 2024-04-15 · Easy · 6 min read · Computer vision, LLMs, Model training, Open source
  Idefics2 is an 8B-parameter open (Apache 2.0) vision-language model that takes interleaved images and text and generates text, with strong OCR and document understanding.
- [Welcome PaliGemma 2 – New vision language models by Google](https://swe.quest/articles/welcome-paligemma-2-new-vision-language-models-by-google-24dd8ece5058fbe9.md): Hugging Face · 2024-12-05 · Medium · 9 min read · Computer vision, LLMs, Model training, Inference & serving
  PaliGemma 2 pairs Google's SigLIP image encoder with Gemma 2 text decoders, shipping pre-trained vision language models at 3B, 10B and 28B parameters, each at 224, 448 and 896 pixel input resolutions, plus 3B and 10B checkpoints fine-tuned on DOCCI for detailed captioning.
- [PRX Part 4: Our Data Strategy](https://swe.quest/articles/prx-part-4-our-data-strategy-65ac8355bac33db9.md): Hugging Face · 2026-07-06 · Hard · 20 min read · Model training, Data pipelines, Computer vision, Machine learning
  PRX's pre-training corpus for a 7B text-to-image model is assembled from public and internal datasets, re-captioned with a VLM into long dense paragraphs, curated in Lance and streamed to training as Mosaic Data Shards.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
