Nodes/ComfyUI-Transformers/Document Question Answering
ComfyUI Node

Document Question Answering

Document QA

By kadirnar·Created 3 years ago·Updated 7 months ago· 25
Document Question Answering
  • image
  • answer
  • score
question
model_nameimpira/layoutlm-document-qa

Document Question Answering is the node for when your "image" is actually a piece of paper: a receipt, an invoice, a form, a scanned page. You show it the image, ask "what's the total?" or "when was this issued?", and it answers with text plus a confidence score. It's the natural next step up from the plain image-captioning nodes - instead of describing the whole image, it understands layout and text on a page and answers specific questions about it.

It wraps the document-question-answering pipeline from Hugging Face, defaulting to impira/layoutlm-document-qa. That's a LayoutLM-based model, which is the key trick: LayoutLM learns not just the words but where they sit on the page, so it can reason about form fields, tables, and document structure rather than just OCR-ing a blob of text. The node converts your image's first frame to PIL, runs the question against it, and returns the top answer and score.

The inputs that matter

  • image - the IMAGE tensor of the document. Keep it readable: a low-res or heavily compressed scan will degrade the model fast.
  • question - the question, a single-line string. Ask specific, extractable things - "what is the invoice number?" beats "what is this document about?"
  • model_name - Hub model ID as a string, default impira/layoutlm-document-qa.

Two outputs: answer (a STRING - the extracted answer) and score (a FLOAT confidence, 0–1). The score tells you when to trust the answer, which for document QA matters - the model will happily guess on a blurry receipt.

How to install it

Standard pack install - ComfyUI Manager (search "ComfyUI-Transformers") or:

cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers

Restart ComfyUI. LayoutLM document-QA is a small model and downloads quickly; requirements.txt already covers the transformers stack.

Where people get burned

Document QA is extractive and literal: it pulls an answer from text it can actually read in the image. If the document is a photo at a bad angle, or the answer requires calculation ("what's the total plus tax?"), it will either fail or give you a confident-looking wrong answer - again, watch the score. It also handles a few document types well and others poorly; receipts and forms are its comfort zone. For turning real paper documents into structured answers inside a workflow, it's a neat, self-contained tool - just keep your scans clean and your questions extractable.

CategoryTransformers/Multimodal/DocumentQA

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
questionSTRING
model_nameSTRINGimpira/layoutlm-document-qa

Outputs (2)

NameTypeDescription
answerSTRING
scoreFLOAT