Results
Scored once on the 419-page test split of tech4humans/signature-detection (383 signed, 36 unsigned), pages at 640x640. A box counts as right if each of its four edges is within 5% of the page's width or height of a labelled signature.
Table with columns: Measure, This adapter, Same base, no adapter| Measure | This adapter | Same base, no adapter |
|---|
| Presence balanced accuracy | 0.982 | 0.938 |
| Unsigned pages called signed | 1 / 36 | 4 / 36 |
| Boxes right (one box per signed page) | 95.6% | 61.1% |
On 239 unsigned pages from a different collection (DocLayNet), it called none signed. On the 642 SignverOD signed pages it never trained on, it found all 642 and put 90.8% of boxes within 5%.
Limitations
- Small unsigned test set. Only 36 unsigned test pages; 1 error in 36 has a 95% interval reaching about 8%.
- The remaining errors are handwriting that isn't a signature: notes that end in a scrawled name, routing notes, marginal initials. The labelling rule here counts initials used as a sign-off as a signature and other handwriting as not.
- One box per page. On pages with several signatures it returns one; boxes were right on 86.7% of multi-signature test pages.
- Narrow training data. Mostly 1980s-90s business and legal scans (Tobacco800 lineage) plus SignverOD. Untested on forms, receipts, cheques, photos or non-Latin scripts.
- Not signature verification. It says whether a page is signed, not whether the signature is genuine.
- Personal data. The training sets are public, but they contain scans of real people's signatures. The adapter stores no images.
One page image, resized to 640x640, and exactly this prompt (the adapter was trained on it; other wording is untested):
Does this scanned page contain a handwritten signature? A signature is the handwritten mark that signs the document, including initials used as a sign-off. Handwritten notes, filing names, dates, printed names, typed '/s/' marks, stamps, logos and cursive letterheads do not count.Answer with JSON only: {"signed": true or false, "bbox_2d": [x1, y1, x2, y2] of the signature, or null if not signed}.
Output: {"signed": true|false, "bbox_2d": [x1, y1, x2, y2] | null}, coordinates 0-1000 normalised to the page. Use greedy decoding, up to 160 new tokens, with thinking disabled in the chat template.
import torchfrom PIL import Imagefrom transformers import AutoModelForImageTextToText, AutoProcessorfrom peft import PeftModel PROMPT = ( "Does this scanned page contain a handwritten signature? A signature is the handwritten mark that signs " "the document, including initials used as a sign-off. Handwritten notes, filing names, dates, printed names, " "typed '/s/' marks, stamps, logos and cursive letterheads do not count.\n" "Answer with JSON only: {\"signed\": true or false, \"bbox_2d\": [x1, y1, x2, y2] of the signature, or null if not signed}.")base_id = "Qwen/Qwen3.5-9B"processor = AutoProcessor.from_pretrained(base_id)model = AutoModelForImageTextToText.from_pretrained(base_id, dtype=torch.bfloat16, device_map="auto")model = PeftModel.from_pretrained(model, "TextLayerAI/qwen3.5-9b-signature-detection-lora").eval() page = Image.open("page.png").convert("RGB").resize((640, 640))messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": PROMPT}]}]text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)inputs = processor(text=[text], images=[page], return_tensors="pt").to(model.device)# Qwen/Qwen3.5-9B's config.json stops on <|endoftext|>; the chat turn ends with <|im_end|>, so pass it explicitlyout = model.generate(**inputs, max_new_tokens=160, do_sample=False, eos_token_id=processor.tokenizer.eos_token_id)print(processor.batch_decode(out[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)[0])
Pass eos_token_id as shown: the base repo has no generation config, so without it generation runs past the answer into a new turn. Tested with transformers 5.24 and peft 0.22. vLLM's LoRA support on Qwen3.5's linear-attention layers is untested; merge the adapter into the base if a server rejects it.
Use on a Mac with MLX
The mlx/ folder holds the same adapter in mlx-vlm format (trained with mlx-vlm 0.8.0):
pip install mlx-vlm==0.8.0python -m mlx_vlm.server --model mlx-community/Qwen3.5-9B-MLX-bf16 --adapter-path ./mlx
About 18 GB of memory in bf16; about 3 s per page on an Apple M5 Pro.
Training
- LoRA rank 16, alpha 32, on the language model's attention, linear-attention and MLP projections (43.3 M parameters); vision tower frozen.
- 3,637 training pages: the tech4humans train split (1,980 pages, about 396 sources each augmented five ways) plus 1,657 SignverOD pages, after removing SignverOD pages that were near-copies of test or validation pages. 438 unsigned.
- 2 epochs (7,274 steps at batch 1, 8-step accumulation), AdamW 1e-4, cosine schedule, loss on the answer tokens only. This checkpoint is step 3,000, chosen on the validation split before the test split was used.
- Trained with mlx-vlm 0.8.0 on an Apple M5 Pro in about 7 hours.
verification.json records the check that the PEFT copy reproduces the MLX checkpoint: 20 of 20 validation pages gave the same signed/unsigned answer, and the 5%-rule verdict on boxes matched on 19 of 19.
Data and licences