Doc2Command: Furthering Language Guided Document Editing

Manan Suri, Puneet Mathur, Ramit Sawhney, Preslav Nakov, Dinesh ManochaICLR 2024

TL;DR

Doc2Command is a new multimodal model designed to turn natural language instructions—like "change the date in the footer"—into machine-executable commands and precise bounding boxes on a document. By rendering the user's request directly onto the document image and treating localization as a segmentation task, the model achieves a massive 12-31% improvement in detecting edit regions compared to previous state-of-the-art methods.

What Problem Does This Paper Address?

Editing digital documents is a ubiquitous task, yet automating it through natural language remains a significant challenge. To successfully "edit" a document based on a text request, a model must solve two hard problems simultaneously:

  1. Semantic Understanding: It must translate a vague human request into a structured, machine-parsable command (e.g., ACTION: REPLACE, COMPONENT: TEXT...).
  2. Visual Grounding: It must find exactly where on the page that edit should happen, which requires understanding complex layouts, fonts, and spatial relationships.
Example of visual grounding for a document edit request

Previous approaches often treated text and images as separate streams or struggled to precisely "point" to the right part of the document. Doc2Command aims to bridge this gap by unifying the instruction and the document into a single visual workspace.

Methods

The authors introduce a multi-task, multimodal architecture that deviates from standard approaches in two clever ways:

Doc2Command Architecture
  • Visual Unification: Instead of using a separate text encoder for the user's request, they "print" the request at the top of the document image. This allows a single Vision Transformer (ViT) encoder to process both the instruction and the document context as a single visual entity.
  • Segmentation for Localization: Most models try to predict bounding box coordinates $(x, y, h, w)$ directly through regression. Doc2Command instead treats localization as a segmentation task. It uses a "Mask Transformer" (a DETR-style decoder) to highlight the pixels belonging to the Region of Interest (RoI). During inference, the model simply draws a box around the largest highlighted area.
  • Multi-Task Output: While the Mask Transformer handles the "where," a standard text decoder handles the "what," generating the structured command string.

The backbone is based on Pix2Struct, a model pre-trained on screenshot parsing, which makes it naturally adept at handling the mixture of text and layout found in PDFs.

Datasets

The model was trained and evaluated on the DocEdit-PDF dataset.

  • Content: Approximately 17,808 scanned PDF documents paired with human-like edit requests.
  • Scope: It covers a wide range of actions including Add, Delete, Copy, Move, Replace, Split, Merge, and Modify.
  • Format: Each entry includes the document image, the request, the ground-truth executable command, and the coordinates for the edit.

Key Insights and Ideas

  • The "Vision-Only" Advantage: By rendering text onto the image, the model can leverage spatial reasoning for the instruction itself. It doesn't just read the words; it "sees" the request in relation to the page.
  • Moving Beyond OCR: Unlike many document tools that rely on a separate OCR (Optical Character Recognition) engine to "read" the PDF first, Doc2Command parses the document structure and text directly from the pixels. This reduces errors that typically propagate from messy OCR outputs.
  • The Power of Masks: Reconceptualizing bounding box detection as segmentation (pixel-masking) proved much more effective than coordinate regression. This is likely because masks can better capture the irregular shapes of document components before they are forced into a rectangular box.

Key Results

Doc2Command set new benchmarks for the language-guided editing task:

  • Command Accuracy: The model saw a huge jump in "Component" recognition—identifying what is being edited (e.g., a header vs. a paragraph)—climbing to 86.1% compared to the previous best of 40.7%.
  • Localization (The "Where"): In the bounding box detection task, the model achieved a 48.69% Top-1 Accuracy (using a Jaccard overlap threshold of 0.5). This is a significant leap over the previous state-of-the-art (DocEditor), which sat at 36.50%.
  • Exact Match (EM): For the full command text, the model achieved 39.6% accuracy, outperforming a suite of baselines including GPT-4 and specialized multimodal transformers.

Limitations and Future Work

Despite its success, the authors note several areas for improvement:

  • Visual Elements: The model struggles with non-textual components like complex charts, diagrams, or intricate figures, largely because the underlying backbone was pre-trained primarily on text-heavy documents.
  • Ambiguity: If a user says "change the second paragraph" in a document with a non-linear or multi-column layout, the model sometimes struggles to resolve which paragraph is "second."
  • Patchy Masks: In some cases, the segmentation process produces "patchy" or fragmented masks for large regions, which can lead to less accurate bounding boxes.
  • Not "End-to-End" Editing: The system generates the command to edit the document but does not yet perform the actual pixel-level manipulation to show the final edited document. Integrating this into a generative "Edit-to-Image" pipeline is a logical next step.

Summary updated

BibTeX
@inproceedings{suri2024doc,
  author = {Manan Suri and Puneet Mathur and Ramit Sawhney and Preslav Nakov and Dinesh Manocha},
  title = {{Doc2Command: Furthering Language Guided Document Editing}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=inQ9bW5AQz},
}
Figure