Harmonizing Visual Text Comprehension and Generation

Zhen Zhao, Jingqun Tang, Binghong Wu, Chunhui Lin, Shu Wei, Hao Liu, Xin Tan, zhizhong zhang, Can Huang, Yuan Xie

In the realm of multimodal AI, a significant divide persists. On one side, models excel at reading (visual text comprehension, such as OCR and Document VQA). On the other, specialized models excel at writing (visual text generation, like rendering a "Welcome" sign within a generated image).

Historically, attempting to unify these capabilities into a single model resulted in a "jack of all trades, master of none" scenario. Performance degrades because the underlying logic for generating pixels (regression) fundamentally clashes with generating words (classification). In a new paper titled Harmonizing Visual Text Comprehension and Generation, researchers from ByteDance and East China Normal University introduce TextHarmony, a model designed to bridge this gap without the usual performance tax.

TL;DR

TextHarmony is a unified multimodal model that excels at both comprehending and generating images containing text. By introducing a novel Slide-LoRA architecture that dynamically switches between modality-specific experts, it achieves state-of-the-art performance in visual text tasks with only a 2% increase in parameters.

Comparison of model pipelines and TextHarmony capabilities

The Core Challenge: Modality Inconsistency

The primary hurdle in building a unified model is modality inconsistency.

When a model simultaneously learns to describe an image (text generation) and create an image from a description (image generation), the training objectives clash. Text generation typically relies on cross-entropy loss to predict the next token, while image generation (via diffusion) uses mean square error (MSE) to denoise pixels.

Existing solutions often bypass this by training separate model instances for each task or relying on "modality-specific" fine-tuning. However, this fractures the vision of a truly versatile agent. The researchers behind TextHarmony sought to partially decouple these processes within a single model, ensuring that "learning to write" doesn't cause the model to "forget how to read."

Methodology: Slide-LoRA and a Unified Pipeline

The researchers built TextHarmony upon a robust foundation: a CLIP-ViT-L/14 vision encoder, a Vicuna-13B LLM, and a Stable Diffusion v2.1 image decoder. To harmonize these components, they introduced two key innovations:

  1. Slide-LoRA: Instead of applying a standard Low-Rank Adaptation (LoRA) universally, Slide-LoRA utilizes three distinct experts:
  2. A Language Expert for text generation.
  3. A Vision Expert for image generation.
  4. A Modality-Agnostic Expert to handle shared knowledge.

    A "Modal-Aware Gating" network acts as a conductor, dynamically "sliding" between these experts based on the input tokens. This allows the model to leverage specialized parameters for specific tasks while maintaining a shared foundation.

  5. Unified Generative Pipeline: The model treats image generation as a "detokenization" task. The LLM produces "image tokens," which then serve as the conditional input for the diffusion-based image decoder.

Enhancing Data: DetailedTextCaps-100K

Recognizing that existing datasets for visual text generation often feature overly simplistic captions, the authors created DetailedTextCaps-100K.

This new dataset contains 100,000 high-quality image-caption pairs. Using Gemini Pro, they rewrote simple captions (e.g., "A book cover") into rich, descriptive text that highlights specific textual and visual elements (e.g., "A book titled 'Dream Health' with a subtitle..."). For evaluation, they relied on standard benchmarks including DocVQA, InfoVQA, and ChartQA for comprehension, alongside the AnyText-benchmark and MARIO-Eval for generation.

Key Insights and Results

TextHarmony demonstrates that a unified approach is highly viable, yielding several key takeaways:

  • Partial Decoupling is Powerful: A massive Mixture-of-Experts (MoE) model isn't strictly necessary to solve modality inconsistency. The lightweight, sliding LoRA approach provides necessary separation with minimal computational overhead.
  • The "Read-to-Write" Synergy: Improving the model's ability to describe text-rich images (via the DetailedTextCaps dataset) directly enhanced its ability to generate them. High-quality linguistic descriptions serve as a stronger bridge for the diffusion process.
  • Strategic Gating: Placing Slide-LoRA in both the vision encoder and the LLM yielded the best results, allowing specialization at both the perception and reasoning stages.

Performance Highlights: * Comprehension: TextHarmony achieved an average improvement of 2.5% over baselines without Slide-LoRA, scoring competitively against specialized models like Monkey and InternLM-XComposer2. * Generation: The model saw a 4.0% improvement in generation tasks. On the AnyText-benchmark (measured by Normalized Edit Distance), it scored 0.75, significantly outperforming multi-task models like SEED-LLaMA (0.11) and MiniGPT5 (0.02). * Efficiency: These gains were realized with only a 2% increase in total parameters compared to a standard dense model.

Limitations and Future Directions

While TextHarmony represents a major step forward, the authors note a few remaining hurdles. The model still struggles with images containing extremely dense or small text, where the vision encoder's resolution limits become a bottleneck. Additionally, while it generates text well, it is less robust in highly complex visual scenarios compared to massive, specialized diffusion-only models.

Future work will likely explore more sophisticated gating mechanisms and scale training data to encompass diverse, multi-page document scenarios.

Check out the code: https://github.com/bytedance/TextHarmony

Summary updated

BibTeX
@inproceedings{zhao2024harmonizing,
  author = {Zhen Zhao and Jingqun Tang and Binghong Wu and Chunhui Lin and Shu Wei and Hao Liu and Xin Tan and zhizhong zhang and Can Huang and Yuan Xie},
  title = {{Harmonizing Visual Text Comprehension and Generation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=fqjeKsHOVR},
}
Figure