Views
No views yet
1import torch
2from PIL import Image
3from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
4
5MODEL_PATH = "Carol0110/UniMod-7B"
6IMAGE_PATH = "sample.jpeg" # Replace with your image path
7
8model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
9 MODEL_PATH, torch_dtype=torch.float16, device_map="auto"
10)
11processor = AutoProcessor.from_pretrained(MODEL_PATH)
12
13image = Image.open(IMAGE_PATH).convert("RGB")
14
15messages = [
16 {
17 "role": "user",
18 "content": [
19 {"type": "image"},
20 {"type": "text", "text": "How can I make this?"},
21 ],
22 }
23]
24
25text = processor.apply_chat_template(messages, add_generation_prompt=True)
26
27inputs = processor(
28 text=text,
29 images=image,
30 return_tensors="pt",
31).to(model.device)
32
33with torch.no_grad():
34 out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
35
36print(processor.batch_decode(out, skip_special_tokens=True)[0])<evidence>: Detailed observation and grounding.<modality>: Assessment of whether the input is text-only or multimodal.<risk>: Identification of safety risks (e.g., legality, violence).<policy>: The moderation decision (e.g., refuse).<answer>: The final generated response.1@misc{gu2026sparsedecisionsdensereasoning,
2 title={From Sparse Decisions to Dense Reasoning: A Multi-attribute Trajectory Paradigm for Multimodal Moderation},
3 author={Tianle Gu and Kexin Huang and Lingyu Li and Ruilin Luo and Shiyang Huang and Zongqi Wang and Yujiu Yang and Yan Teng and Yingchun Wang},
4 year={2026},
5 eprint={2602.02536},
6 archivePrefix={arXiv},
7 primaryClass={cs.LG},
8 url={https://arxiv.org/abs/2602.02536},
9}