LightOnOCR-2 Run
Clean text out of messy documents, right inside ComfyUI
- model
- image
- text
The whole point of the ComfyUI-LightOnOCR-2 pack is this node. Feed it an image of a receipt, an invoice, a scanned page, or a form, and it hands you back the text - clean, in natural reading order, tables and multi-column layouts included. That's a step beyond the OCR you've been faking with Florence-2's text-recognition task, and light-years past typing things out by hand. If you've ever wanted a document's contents as plain text inside a workflow, this is the node.
It's a vision-language model doing the work: LightOn's LightOnOCR-2-1B, a 1B-parameter model trained end-to-end for document understanding rather than bolted onto an old OCR engine. The model card puts it at state-of-the-art on the OlmOCR-Bench document benchmark, and the Apache-2.0 license plus a very healthy Hugging Face download count say the community has quietly adopted it. This wrapper is a thin, readable slice of Python on top - which, after the LLMVISION malware incident in this ecosystem, is genuinely a point in its favor. Read it if you're paranoid; it's 140 lines.
How it works
The Run node takes the LIGHTONOCR2_MODEL bundle from the Model Loader plus any ComfyUI IMAGE, converts the pixels to a PIL image, and builds a chat-template prompt - a vision-language model, so the image goes in as a conversational turn. Then it calls generate(), slices off the prompt tokens, and decodes the result. Text out.
Under the hood it's a standard generation call, so all the usual LLM knobs are exposed. There are no tooltips in the schema, but the naming is self-explanatory and the defaults are sane.
The inputs that matter
- model - the loader's output. Wire it up once.
- image - any ComfyUI image tensor. Gotcha: only
image[0]is processed. This node reads the first frame of the batch and silently ignores the rest. Feed it single images, or loop your batch upstream. This is the trap that catches everyone who feeds a multi-image tensor expecting five OCR results. - max_tokens - output cap, 64 to 8192, default 1024. A dense page of text can chew through a lot of tokens; if you get truncated output, raise it.
- do_sample - default on. Flip it off for greedy decoding, which is the deterministic choice. For OCR you almost always want it off unless you're getting weird hallucinations - you're extracting text, not vibing.
- temperature / top_p - sampling controls, default 0.2 / 0.9. Only applied when
do_sampleis on. 0.2 is already low, which is right: OCR is a task where you want the model confident, not creative. - seed - set for reproducibility (default 42). With greedy decoding it doesn't matter; with sampling it's your "same answer again" switch.
The one output, text, is a plain STRING. That's the beautiful part: you can wire it into a text display node to read it, a save/text-file node for a transcript, or straight into a prompt or LLM node to do something with the contents - summarize an invoice, search it, feed it to a captioner pipeline. Anywhere a STRING goes, it goes.
Installation
Same pack as the loader - install once, both nodes show up under LightOnOCR-2. ComfyUI Manager: search "LightOnOCR-2". Or manually:
cd ComfyUI/custom_nodes
git clone https://github.com/MennilTossFlykune/ComfyUI-LightOnOCR-2.git
pip install "transformers>=5.0.0" pillow
The transformers >= 5.0.0 requirement is the real gotcha - that's the version that added the LightOnOcr classes, and a stock ComfyUI env usually sits on 4.x, so the import fails at startup with an ImportError that tells you exactly what to upgrade. Restart ComfyUI after. First run downloads the ~2GB model through the loader; after that it's cached.
Troubleshooting
- Truncated output - bump
max_tokens; 1024 fills up on dense pages. - Different answer each run -
do_sampleis on by default. Either set a seed or flip it off for deterministic greedy decoding. - Startup ImportError about transformers - version too old; the upgrade command above fixes it.
- Only first image read - that's the batch gotcha, not a bug. Loop or feed singles.
- Slow first run - it's downloading the model, not frozen. It's ~2GB.
For clean single-page documents this is now my default in ComfyUI. The wrapper's new enough that there's no big community lore behind it yet, but the model behind it has the receipts.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| model | LIGHTONOCR2_MODEL | — | |
| image | IMAGE | — | |
| max_tokens | INT | 102464–8192 | — |
| seed | INT | 420–4294967295 | — |
| do_sample | BOOLEAN | true | — |
| temperature | FLOAT | 0.200.01–2 | — |
| top_p | FLOAT | 0.900–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |