Image-Text-to-Text
Safetensors
gemma3
conversational
mrpeerat commited on
Commit
70982eb
·
verified ·
1 Parent(s): 6cb3276

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +44 -0
README.md CHANGED
@@ -66,11 +66,55 @@ The output of the model is only "safe" or "unsafe". Users can directly use it wi
66
 
67
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
68
  Users can also continue training this model further on the target tasks, e.g., vision-text safety datasets.
 
69
 
70
  ## How to Get Started with the Model
71
  Use the code below to get started with the model.
72
  ```python
 
 
 
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  ```
75
 
76
  ## Training and evaluation data
 
66
 
67
  <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
68
  Users can also continue training this model further on the target tasks, e.g., vision-text safety datasets.
69
+ Also, this model is supported VLLM for the fast inference.
70
 
71
  ## How to Get Started with the Model
72
  Use the code below to get started with the model.
73
  ```python
74
+ from transformers import AutoProcessor, Gemma3ForConditionalGeneration
75
+ from PIL import Image
76
+ import requests
77
+ import torch
78
 
79
+ model_id = "aisingapore/Gemma-SEA-Guard-v2-12b"
80
+
81
+ model = Gemma3ForConditionalGeneration.from_pretrained(
82
+ model_id, device_map="auto"
83
+ ).eval()
84
+
85
+ processor = AutoProcessor.from_pretrained(model_id)
86
+
87
+ text = "Why Thai people is so lazy?"
88
+ prompt = f"You are a classifier for analyzing interactions between humans and LLMs. Given a request from a human user and a response from an LLM assistant, determine whether the human user's request is safe or unsafe.\nHuman user: {text}"
89
+
90
+
91
+ messages = [
92
+ {
93
+ "role": "system",
94
+ "content": [{"type": "text", "text": "You are a helpful assistant."}]
95
+ },
96
+ {
97
+ "role": "user",
98
+ "content": [
99
+ {"type": "text", "text": prompt}
100
+ ]
101
+ }
102
+ ]
103
+
104
+ inputs = processor.apply_chat_template(
105
+ messages, add_generation_prompt=True, tokenize=True,
106
+ return_dict=True, return_tensors="pt"
107
+ ).to(model.device, dtype=torch.bfloat16)
108
+
109
+ input_len = inputs["input_ids"].shape[-1]
110
+
111
+ with torch.inference_mode():
112
+ generation = model.generate(**inputs, max_new_tokens=100, do_sample=False)
113
+ generation = generation[0][input_len:]
114
+
115
+ decoded = processor.decode(generation, skip_special_tokens=True)
116
+
117
+ print(prompt,decoded)
118
  ```
119
 
120
  ## Training and evaluation data