Image-Text-to-Text
Transformers
Safetensors
Chinese
English
qwen3_5
forgery-detection
document-forensics
image-tampering
vision-language-model
vlm
qwen3.5-vl
conversational
Instructions to use vankey/DocShield-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vankey/DocShield-9B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="vankey/DocShield-9B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("vankey/DocShield-9B") model = AutoModelForMultimodalLM.from_pretrained("vankey/DocShield-9B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vankey/DocShield-9B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vankey/DocShield-9B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vankey/DocShield-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/vankey/DocShield-9B
- SGLang
How to use vankey/DocShield-9B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "vankey/DocShield-9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vankey/DocShield-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "vankey/DocShield-9B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vankey/DocShield-9B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use vankey/DocShield-9B with Docker Model Runner:
docker model run hf.co/vankey/DocShield-9B
File size: 5,326 Bytes
0c0231a d1d55e2 0c0231a d1d55e2 0c0231a d1d55e2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | ---
library_name: transformers
license: apache-2.0
language:
- zh
- en
pipeline_tag: image-text-to-text
tags:
- forgery-detection
- document-forensics
- image-tampering
- vision-language-model
- vlm
- qwen3.5-vl
---
<p align="center">
<img src="docshield_showcase.png" alt="DocShield-9B showcase" width="70%">
</p>
# DocShield-9B
**DocShield-9B** is a forensic-grade vision-language model for **document / image forgery analysis**. It inspects an input document image, reasons over visual tampering traces and logical consistency, and produces a structured forgery-analysis report with localized tampered regions (grounding coordinates), per-region reasoning, an overall conclusion, and a fraud-risk score.
It is fine-tuned from **Qwen3.5-VL-9B** with supervised training on forensic document-forgery data, and supports Qwen3.5 thinking mode.
📄 **Paper:** [arxiv.org/abs/2604.02694](https://arxiv.org/abs/2604.02694)
## Training data
DocShield-9B was developed using the **RealText** forensic document datasets:
- [vankey/RealText-V1](https://huggingface.co/datasets/vankey/RealText-V1)
- [vankey/RealText-V2](https://huggingface.co/datasets/vankey/RealText-V2)
## Capabilities
- **Visual forgery trace analysis** — crude redaction / mosaic, font & anti-aliasing inconsistency, edge halos, copy-paste artifacts, compression mismatches.
- **Logical & fact-checking** — price/quantity contradictions, date conflicts, bulk-discount logic violations.
- **Semantic alteration detection** — subtle spec substitutions (e.g. color, material) that bypass crude visual checks.
- **Localization** — bounding-box coordinates for each tampered region with per-anomaly reasoning.
- **Structured report** — conclusion (`FORGED` / authentic) + fraud-risk score.
## Model details
| | |
|---|---|
| Base model | Qwen3.5-VL-9B |
| Architecture | Qwen3_5ForConditionalGeneration (hybrid linear / full attention) |
| Precision (weights) | bfloat16 |
| Max new tokens | 1024 (default) |
| Thinking mode | supported (`--thinking` / `--no-thinking`) |
> The base model is **not** bundled here. This repository only releases the
> fine-tuned DocShield-9B weights.
## Quick start
Install dependencies:
```bash
pip install -U transformers torch torchvision pillow qwen-vl-utils
```
> Requires a `transformers` version with native **Qwen3.5-VL (`qwen3_5`)** support.
> The released weights were saved with `transformers==5.13.0`.
Run inference (see `inference.py` in this repo):
```bash
# default: greedy, thinking disabled
python inference.py --image path/to/image.jpg --no-thinking --max-new-tokens 1024
# with sampling + thinking mode
python inference.py --image path/to/image.jpg --thinking --do-sample \
--temperature 0.6 --top-p 0.8 --top-k 20 --max-new-tokens 2048
```
### Minimal example
```python
import torch
from transformers import AutoProcessor, AutoTokenizer, AutoModelForImageTextToText
from qwen_vl_utils import process_vision_info
MODEL = "vankey/DocShield-9B"
tokenizer = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
processor = AutoProcessor.from_pretrained(MODEL, trust_remote_code=True)
model = AutoModelForImageTextToText.from_pretrained(
MODEL, torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto"
)
model.eval()
SYSTEM_PROMPT = (
"你是一个图像鉴伪专家,擅长结合视觉,文字结合伪造特征分析手段鉴别输入图像的真假。"
"分析过程中,你会逐步分析,抽丝剥茧,找到图像伪造的蛛丝马迹,最终给出专业的鉴别结果及分析。"
)
USER_PROMPT = "请分析这张文档图片是否存在伪造或篡改风险,并输出一份专业、精炼、准确的防伪分析报告。"
messages = [
{"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
{"role": "user", "content": [
{"type": "image", "image": "image.jpg"},
{"type": "text", "text": USER_PROMPT},
]},
]
text = processor.apply_chat_template(messages, tokenize=False,
add_generation_prompt=True, enable_thinking=False)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(text=[text], images=image_inputs, videos=video_inputs,
padding=True, return_tensors="pt").to(model.device)
with torch.no_grad():
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
gen = [o[len(i):] for i, o in zip(inputs["input_ids"], out)]
print(processor.batch_decode(gen, skip_special_tokens=False)[0])
```
## Inference notes
- **Image input** — pass the image path directly in the message content; the processor handles resize/tokenization.
- **Thinking mode** — `--no-thinking` (default) gives a direct report; `--thinking` enables Qwen3.5 chain-of-thought before the report (use a larger `--max-new-tokens`).
- **Decoding** — greedy by default (`do_sample=False`); pass `--do-sample` with `--temperature/--top-p/--top-k` for sampling.
- **Precision** — `bfloat16` is the tested configuration (`--dtype bf16`).
## Citation
```bibtex
@article{docshield2026,
title={DocShield: A Forensic Vision-Language Model for Document Forgery Analysis},
author={DocShield},
year={2026},
url={https://arxiv.org/abs/2604.02694}
}
```
## License
Apache-2.0.
|