Instructions to use vankey/DocShield-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vankey/DocShield-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="vankey/DocShield-7B") 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-7B") model = AutoModelForMultimodalLM.from_pretrained("vankey/DocShield-7B") 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-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vankey/DocShield-7B" # 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-7B", "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-7B
- SGLang
How to use vankey/DocShield-7B 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-7B" \ --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-7B", "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-7B" \ --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-7B", "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-7B with Docker Model Runner:
docker model run hf.co/vankey/DocShield-7B
DocShield-7B
DocShield-7B is a forensic-grade vision-language model for document / image forgery analysis. It inspects an input image, reasons step-by-step over visual tampering traces and logical consistency, and produces a professional forgery-analysis report with localized tampered regions and a forgery score.
It is fine-tuned from Qwen2.5-VL-7B-Instruct with supervised chain-of-thought (CoT) reasoning on document-forgery data.
📄 Paper: arxiv.org/abs/2604.02694
Capabilities
- Visual forgery trace analysis — font / glyph / kerning / baseline inconsistency, copy-paste artifacts, edge halos, compression mismatches, noise-pattern breaks.
- Logical & fact-checking — impossible dates, failed calculations, contradictory metadata, domain-commonsense violations.
- Localization — bounding boxes of tampered regions with per-region reasoning.
- Structured CoT report — forensic-style report with a final conclusion and forgery score.
Model details
| Base model | Qwen2.5-VL-7B-Instruct |
| Architecture | Qwen2_5_VLForConditionalGeneration |
| Inference resolution | 1344 × 896 (W × H) |
| Precision (weights) | bfloat16 |
| Precision (compute) | float32 (load with torch_dtype=torch.float32) |
| Max new tokens | 8192 |
The weights are stored in bfloat16 (~16 GB). Always load them with
torch_dtype=torch.float32so computation runs in float32 (the bf16 weights are upcast on load). The base model is not bundled here — download it from Qwen/Qwen2.5-VL-7B-Instruct if needed. This repository only releases the fine-tuned DocShield-7B weights.
Quick start
Install dependencies:
pip install transformers torch torchvision pillow opencv-python qwen-vl-utils
Run inference (see inference.py in this repo):
python inference.py --image path/to/image.jpg
Minimal example
import cv2, torch
from PIL import Image
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
from qwen_vl_utils import process_vision_info
MODEL_PATH = "vankey/DocShield-7B"
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
MODEL_PATH,
torch_dtype=torch.float32,
attn_implementation="eager",
device_map="auto",
)
model.eval()
processor = AutoProcessor.from_pretrained(MODEL_PATH)
SYSTEM_PROMPT = (
"你是一个图像鉴伪专家,擅长结合视觉,文字结合伪造特征分析手段鉴别输入图像的真假。"
"分析过程中,你会逐步分析,抽丝剥茧,找到图像伪造的蛛丝马迹,最终给出专业的鉴别结果及分析。"
)
USER_PROMPT = "请帮我分析这张图片是否是伪造的,并给出分析报告."
image = cv2.cvtColor(cv2.resize(cv2.imread("image.jpg"), (1344, 896)), cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
messages = [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": [
{"type": "image", "image": image},
{"type": "text", "text": USER_PROMPT},
]},
]
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
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,
do_sample=True, temperature=1.0, top_p=1.0,
top_k=0, repetition_penalty=1.0,
max_new_tokens=8192)
generated = out[:, inputs["input_ids"].shape[1]:]
print(processor.batch_decode(generated, skip_special_tokens=True)[0])
Inference notes (important)
These choices are required to reproduce the reported results:
- Image resize — resize the input to
1344 × 896(W × H) before processing:cv2.resize(image, (1344, 896)). - Precision — load with
float32, never compute inbfloat16. The weights are stored as bfloat16; load them withtorch_dtype=torch.float32so they are upcast and computation runs in float32. Computing in bfloat16 accumulates rounding error over the long CoT and degrades output into gibberish on harder images.float16 + eagerattention also overflows (NaN) for long contexts.float32 (compute) + eageris the verified configuration. - Sampling —
temperature=1.0, top_p=1.0, top_k=0, repetition_penalty=1.0(full multinomial sampling). Do not use the values in the bundledgeneration_config.json(temperature=0.1, top_k=1, top_p=0.001, repetition_penalty=1.05) — that near-greedy config triggers repetition loops. - No flash-attention —
attn_implementation="eager".
Citation
@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.
- Downloads last month
- 1
docker model run hf.co/vankey/DocShield-7B