Instructions to use NYUAD-ComNets/Gemma4_safe_unsafe_prompt with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use NYUAD-ComNets/Gemma4_safe_unsafe_prompt with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="NYUAD-ComNets/Gemma4_safe_unsafe_prompt") 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("NYUAD-ComNets/Gemma4_safe_unsafe_prompt") model = AutoModelForMultimodalLM.from_pretrained("NYUAD-ComNets/Gemma4_safe_unsafe_prompt", 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 NYUAD-ComNets/Gemma4_safe_unsafe_prompt with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "NYUAD-ComNets/Gemma4_safe_unsafe_prompt" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "NYUAD-ComNets/Gemma4_safe_unsafe_prompt", "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/NYUAD-ComNets/Gemma4_safe_unsafe_prompt
- SGLang
How to use NYUAD-ComNets/Gemma4_safe_unsafe_prompt 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 "NYUAD-ComNets/Gemma4_safe_unsafe_prompt" \ --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": "NYUAD-ComNets/Gemma4_safe_unsafe_prompt", "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 "NYUAD-ComNets/Gemma4_safe_unsafe_prompt" \ --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": "NYUAD-ComNets/Gemma4_safe_unsafe_prompt", "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" } } ] } ] }' - Unsloth Studio
How to use NYUAD-ComNets/Gemma4_safe_unsafe_prompt with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for NYUAD-ComNets/Gemma4_safe_unsafe_prompt to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for NYUAD-ComNets/Gemma4_safe_unsafe_prompt to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for NYUAD-ComNets/Gemma4_safe_unsafe_prompt to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="NYUAD-ComNets/Gemma4_safe_unsafe_prompt", max_seq_length=2048, ) - Docker Model Runner
How to use NYUAD-ComNets/Gemma4_safe_unsafe_prompt with Docker Model Runner:
docker model run hf.co/NYUAD-ComNets/Gemma4_safe_unsafe_prompt
Finetuned Gemma 4 for Arabic Users Prompts classification into [Safe, Unsafe]
The rise of large language models has led to the spread of Arabic Prompts as a key form of prompt engineering (or interaction with
artificial intelligence), enabling users to communicate effectively with AI systems in their native language to achieve precise,
context-aware results.
While these contents can be helpful and informative, they are also increasingly being used to spread fraud, deception, adult content,
harassment, harm to others, hate speech, and self-harm.
Consequently, there is a growing demand for precise analysis of content in Arabic prompts.
This work used Gemma 4 to effectively identify harmful content within Arabic prompts. The evaluation is conducted using a dataset of Arabic prompts proposed in the ArabicNLP ArGuard 2026 challenge. The results underscore the capacity of google/gemma-4-E2B fine-tuned with Arabic prompts, to deliver superior performance.
The proposed solutions offer a more nuanced understanding of user prompts for accurate and efficient Arabic content moderation systems.
Finetuned Gemma 4 Embedding Model with last token
import torch
from sentence_transformers import SentenceTransformer
from sentence_transformers.models import Transformer, Pooling
import pandas as pd
import numpy as np
model_id = 'NYUAD-ComNets/Gemma4_safe_unsafe_prompt'
device = "cuda" if torch.cuda.is_available() else "cpu"
df=pd.read_csv('train.csv')
word_embedding_model = Transformer(
model_id,
model_args={"torch_dtype": torch.float16}
)
pooling_model = Pooling(
word_embedding_model.get_word_embedding_dimension(),
pooling_mode='lasttoken'
)
custom_emb_model = SentenceTransformer(
modules=[word_embedding_model, pooling_model],
device=device
)
embeddings = custom_emb_model.encode(
df.prompt.values,
batch_size=32,
show_progress_bar=True,
convert_to_numpy=True
)
print(embeddings.shape)
Finetuned Gemma 4 Embedding Model with average pooling
import torch
from sentence_transformers import SentenceTransformer
from sentence_transformers.models import Transformer, Pooling
import pandas as pd
import numpy as np
model_id='NYUAD-ComNets/Gemma4_safe_unsafe_prompt'
word_embedding_model = Transformer(model_id, model_args={"torch_dtype": torch.float16})
pooling_model = Pooling(word_embedding_model.get_word_embedding_dimension(), pooling_mode='mean')
custom_emb_model = SentenceTransformer(modules=[word_embedding_model, pooling_model])
df=pd.read_csv('dev.csv')
embeddings_array=[]
for k in df.prompt.values:
vector = custom_emb_model.encode([k])
embeddings_array.append(vector)
dev_matrix = np.array(embeddings_array)
np.save('dev_embd_Gemma4.npy',dev_matrix)
Prepare Dataset for inference
import pandas as pd
from datasets import Dataset
from datasets import load_dataset
df=pd.read_csv('dev_with_label.csv')
df
raw_data=[]
for k in range(df.shape[0]):
te=df.prompt.values[k]
lab=df.label.values[k]
raw_data.append({"text":te,"label":lab})
SYSTEM_PROMPT = "classify the text into one of the following: [Safe, Unsafe]"
formatted_rows = []
for item in raw_data:
conversation = {
"messages": [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": item["text"]},
{"role": "assistant", "content": item["label"]}
]
}
formatted_rows.append(conversation)
hf_dataset = Dataset.from_list(formatted_rows)
hf_dataset.to_json("dev_dataset.jsonl")
dataset = load_dataset("json", data_files="dev_dataset.jsonl")
print(dataset)
Finetuned Gemma 4 for Inference
from transformers import AutoModelForMultimodalLM, AutoProcessor
from transformers import pipeline, GenerationConfig, pipeline
model_id ="NYUAD-ComNets/Gemma4_safe_unsafe_prompt"
# Load Model with PEFT adapter
model = AutoModelForMultimodalLM.from_pretrained(
model_id,
device_map="auto",
dtype="auto",
)
processor = AutoProcessor.from_pretrained(model_id)
config = GenerationConfig.from_pretrained(model_id)
config.max_new_tokens = 256
config.eos_token_id = [processor.tokenizer.convert_tokens_to_ids("<turn|>")]
pipe = pipeline("text-generation", model=model, tokenizer=processor.tokenizer)
lis=[]
pred=[]
n=0
for k,lab in zip(range(df.shape[0]),df.label.values):
test_sample = dataset['train'][k]
prompt = processor.tokenizer.apply_chat_template(test_sample["messages"][:2], tokenize=False, add_generation_prompt=True)
outputs = pipe(text_inputs=prompt, generation_config=config)
p=outputs[0]['generated_text'][len(prompt):].strip().removesuffix("<turn|>")
print(p)
pred.append(p)
lis.append(lab)
d=pd.DataFrame({'label':lis,'predict':pred})
print(sum(d.label==d.predict))
We used Low-Rank Adaptation (LoRA) as the Parameter-Efficient Fine-Tuning (PEFT) method for fine-tuning utilizing the unsloth framework.
BibTeX entry and citation info
@misc{aldahoul,
title={NYUAD at ArGuard Shared Task: Multimodal Embedding Models for
Detecting Arabic Hateful Memes and Unsafe Prompts},
author={Nouar AlDahoul and Yasir Zaki},
year={2026},
eprint={},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={},
}
- Downloads last month
- 4