Instructions to use sweetpapa/sentry-270m-moderation-v3 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use sweetpapa/sentry-270m-moderation-v3 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="sweetpapa/sentry-270m-moderation-v3") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("sweetpapa/sentry-270m-moderation-v3") model = AutoModelForCausalLM.from_pretrained("sweetpapa/sentry-270m-moderation-v3", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use sweetpapa/sentry-270m-moderation-v3 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "sweetpapa/sentry-270m-moderation-v3" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "sweetpapa/sentry-270m-moderation-v3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/sweetpapa/sentry-270m-moderation-v3
- SGLang
How to use sweetpapa/sentry-270m-moderation-v3 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 "sweetpapa/sentry-270m-moderation-v3" \ --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": "sweetpapa/sentry-270m-moderation-v3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "sweetpapa/sentry-270m-moderation-v3" \ --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": "sweetpapa/sentry-270m-moderation-v3", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use sweetpapa/sentry-270m-moderation-v3 with Docker Model Runner:
docker model run hf.co/sweetpapa/sentry-270m-moderation-v3
SENTRY-270M — content-moderation gate (sweetpapa/sentry-270m-moderation-v3)
A 270M-parameter content-moderation classifier, distilled from a Gemma-4 31B teacher
onto the FunctionGemma-270M student. Given a piece of content it emits exactly one
moderate(...) function call — a category, a severity in [0.0, 1.0], and a policy
action — designed to run cheaply (CPU) as the first-pass gate of a moderation cascade,
escalating low-confidence cases to a larger judge.
⚠️ Serving — read this before you deploy
This model is numerically fp16-sensitive (Gemma-3-270M activations overflow fp16's 5-bit exponent range). That has a hard consequence:
- Serve ONLY via a transformers-native path in fp32 or bf16. On CPU use fp32 (it is the exact reference AND ~7× faster than bf16, which CPUs emulate). bf16 is numerically identical to fp32 for this model and fine on GPU.
- Do NOT serve via Ollama / llama.cpp / GGUF (any quant — F16, Q8_0, or even BF16-GGUF).
Measured directly: llama.cpp's kernels silently under-flag borderline hate/self_harm
(~20 of 42 harmful items downgraded to
safe) at every quant level. This is a 270M model — there is no resource problem for quantization to solve, and a quantized variant would put a silent safety failure under this model's name. No quantized/GGUF artifacts are published, on purpose. - Reference inference code:
scripts/moderate.pyin the training repo (fp32, exactly the eval path).
Output schema
{"name": "moderate", "parameters": {
"category": "safe | hate_harassment | dangerous_content | sexual_content | violence_gore | self_harm | spam_scam | pii_exposure",
"severity": 0.0,
"action": "allow | flag | block | escalate"
}}
Intended use & scope
- Use: a stateless first-pass moderation gate; pair it with a confidence threshold and escalate the uncertain slice to a stronger model. Calibrate the threshold to your risk tolerance (see the escalation curve in the eval).
- Out of scope: standalone high-stakes decisions without human/secondary review; CSAM/child-safety detection (explicitly excluded from training — handled by a separate Tier-0 hash gate).
Evaluation (directional — scored against the 31B teacher's labels, not a human gold set)
| metric | value |
|---|---|
| format validity | 98.1% (greedy decoding) |
| high-severity recall (teacher sev ≥ 0.8) | 0.909 |
| calibration (ECE) | 0.071 |
| CPU latency | p50 ≈ 470 ms, p95 ≈ 525 ms per call (fp32, CPU; faster with int8) |
| recall — dangerous_content | 0.84 |
| recall — self_harm | 0.85 |
| recall — violence_gore | 0.58 |
| recall — hate_harassment | 0.54 |
These are teacher-scored and therefore directional; a human-verified gold set is the pre-ship arbiter.
Recommended generation config
Decode greedily and parse the call:
model.generate(**inputs, max_new_tokens=48, do_sample=False)
Do NOT add repetition_penalty / no_repeat_ngram_size — they corrupt the JSON call's
required repetition (quotes, keys, enum names) and drop format validity from 98% to ~9%.
On the rare unparseable output (2%, a degenerate decode on hard inputs), treat it as
escalate — a malformed low-confidence result belongs with the larger judge, which is
exactly the cascade's job.
Training
- Teacher: Gemma-4 31B (bf16), labeling via vLLM; each row gets one
moderate()call. - Corpus: ~33k rows balanced across the 8 categories (Aegis / BeaverTails / a self-harm set), child-safety rows dropped at ingest.
- Student: full fine-tune of FunctionGemma-270M with a completion-only loss mask (loss on the call tokens only) and oversampling of thin toxic classes.
Limitations
hate_harassmentrecall (~0.54) trails the other harmful classes — hard, contextual, and thinner in the teacher-labeled data.- 270M capacity: escalate low-confidence rather than trust every call.
- Evaluated against teacher labels, not human gold.
License
Governed by the Gemma Terms of Use. Trained on public safety datasets (see their respective licenses).
- Downloads last month
- 398
Model tree for sweetpapa/sentry-270m-moderation-v3
Base model
google/functiongemma-270m-it