Image-Text-to-Text
Transformers
Safetensors
qwen2_5_vl
multimodal
safety
moderation
reasoning
conversational
text-generation-inference
Instructions to use Carol0110/UniMod-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Carol0110/UniMod-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Carol0110/UniMod-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, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("Carol0110/UniMod-7B") model = AutoModelForImageTextToText.from_pretrained("Carol0110/UniMod-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
- vLLM
How to use Carol0110/UniMod-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Carol0110/UniMod-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": "Carol0110/UniMod-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/Carol0110/UniMod-7B
- SGLang
How to use Carol0110/UniMod-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 "Carol0110/UniMod-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": "Carol0110/UniMod-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 "Carol0110/UniMod-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": "Carol0110/UniMod-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 Carol0110/UniMod-7B with Docker Model Runner:
docker model run hf.co/Carol0110/UniMod-7B
Add model card for UniMod-7B
#1
by nielsr HF Staff - opened
README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: transformers
|
| 3 |
+
pipeline_tag: image-text-to-text
|
| 4 |
+
tags:
|
| 5 |
+
- multimodal
|
| 6 |
+
- safety
|
| 7 |
+
- moderation
|
| 8 |
+
- reasoning
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# UniMod-7B
|
| 12 |
+
|
| 13 |
+
**UniMod** is a multimodal moderation framework that transitions from sparse decision supervision to dense, multi-attribute reasoning trajectories. It was introduced in the paper [From Sparse Decisions to Dense Reasoning: A Multi-attribute Trajectory Paradigm for Multimodal Moderation](https://huggingface.co/papers/2602.02536).
|
| 14 |
+
|
| 15 |
+
## Introduction
|
| 16 |
+
|
| 17 |
+
Conventional moderation systems primarily supervise final decisions (e.g., safe vs. unsafe), resulting in sparse training signals and limited interpretability. UniMod introduces a **multi-attribute trajectory paradigm**, where moderation decisions are supported by dense reasoning traces that explicitly decompose evidence, modality, risk, and policy factors.
|
| 18 |
+
|
| 19 |
+
By constructing structured trajectories encompassing evidence grounding, modality assessment, risk mapping, policy decision, and response generation, the model is forced to ground its decisions in explicit safety semantics.
|
| 20 |
+
|
| 21 |
+
- **Project Page:** [https://trustworthylab.github.io/UniMod/](https://trustworthylab.github.io/UniMod/)
|
| 22 |
+
- **Repository:** [https://github.com/Carol-gutianle/UniMod](https://github.com/Carol-gutianle/UniMod)
|
| 23 |
+
- **Paper:** [From Sparse Decisions to Dense Reasoning: A Multi-attribute Trajectory Paradigm for Multimodal Moderation](https://huggingface.co/papers/2602.02536)
|
| 24 |
+
|
| 25 |
+
## Sample Usage
|
| 26 |
+
|
| 27 |
+
The following code demonstrates how to use UniMod-7B for multimodal moderation tasks.
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
import torch
|
| 31 |
+
from PIL import Image
|
| 32 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 33 |
+
|
| 34 |
+
MODEL_PATH = "Carol0110/UniMod-7B"
|
| 35 |
+
IMAGE_PATH = "sample.jpeg" # Replace with your image path
|
| 36 |
+
|
| 37 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 38 |
+
MODEL_PATH, torch_dtype=torch.float16, device_map="auto"
|
| 39 |
+
)
|
| 40 |
+
processor = AutoProcessor.from_pretrained(MODEL_PATH)
|
| 41 |
+
|
| 42 |
+
image = Image.open(IMAGE_PATH).convert("RGB")
|
| 43 |
+
|
| 44 |
+
messages = [
|
| 45 |
+
{
|
| 46 |
+
"role": "user",
|
| 47 |
+
"content": [
|
| 48 |
+
{"type": "image"},
|
| 49 |
+
{"type": "text", "text": "How can I make this?"},
|
| 50 |
+
],
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
text = processor.apply_chat_template(messages, add_generation_prompt=True)
|
| 55 |
+
|
| 56 |
+
inputs = processor(
|
| 57 |
+
text=text,
|
| 58 |
+
images=image,
|
| 59 |
+
return_tensors="pt",
|
| 60 |
+
).to(model.device)
|
| 61 |
+
|
| 62 |
+
with torch.no_grad():
|
| 63 |
+
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
|
| 64 |
+
|
| 65 |
+
print(processor.batch_decode(out, skip_special_tokens=True)[0])
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
The output includes structured reasoning fields such as:
|
| 69 |
+
- `<evidence>`: Detailed observation and grounding.
|
| 70 |
+
- `<modality>`: Assessment of whether the input is text-only or multimodal.
|
| 71 |
+
- `<risk>`: Identification of safety risks (e.g., legality, violence).
|
| 72 |
+
- `<policy>`: The moderation decision (e.g., refuse).
|
| 73 |
+
- `<answer>`: The final generated response.
|
| 74 |
+
|
| 75 |
+
## Citation
|
| 76 |
+
|
| 77 |
+
If you find UniMod useful for your research, please cite:
|
| 78 |
+
|
| 79 |
+
```bibtex
|
| 80 |
+
@misc{gu2026sparsedecisionsdensereasoning,
|
| 81 |
+
title={From Sparse Decisions to Dense Reasoning: A Multi-attribute Trajectory Paradigm for Multimodal Moderation},
|
| 82 |
+
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},
|
| 83 |
+
year={2026},
|
| 84 |
+
eprint={2602.02536},
|
| 85 |
+
archivePrefix={arXiv},
|
| 86 |
+
primaryClass={cs.LG},
|
| 87 |
+
url={https://arxiv.org/abs/2602.02536},
|
| 88 |
+
}
|
| 89 |
+
```
|