Local Content Moderation in Python: German and English Comments with Tiger Guard
A comment says your search is slow. Another insults a person. A third quotes the insult to report it. Sending all three to the same keyword blocklist would lose an important distinction: criticism and reporting abuse ser
A comment says your search is slow. Another insults a person. A third quotes the insult to report it. Sending all three to the same keyword blocklist would lose an important distinction: criticism and reporting abuse serve different purposes from directing abuse at someone.
Tiger Guard is Patronus's content-moderation model for English and German text. Here we put the full-size model into a small Python check for an existing comment form. The useful result is an explicit handoff: a candidate comment with its original text, a review request, or a held result when the check cannot complete. Tiger Guard produces a classification; your application owns the moderation decision. 1
Choose the moderation task before the threshold
The model exposes two labels, SAFE and UNSAFE. Its documented policy covers abusive language and harmful requests or responses. Reporting an insult and counter speech are intended to stay allowed, while insults can be moderated even when no protected group is involved. That scope matters if your community permits profanity or has different rules. A label is evidence about the model's learned policy, not a complete account of your community's rules. 1
Our example has a narrower job: screen a short submitted comment before an existing application displays it. A result called candidate means it can proceed to your remaining checks. A review result carries no text for automatic display. A held result also carries no text, but describes an input or execution problem. No branch deletes a comment or posts on behalf of a user.
This separation makes the caller understandable. Display code consumes the returned text only after the application's other requirements pass. It must not fall back to the original input when that key is absent. The missing key is deliberate: an unavailable model should not become an accidental approval.
Start with the public Transformers interface
This example loads Tiger Guard directly with the published Transformers pipeline. It does not depend on a private repository or a new database. In your own application folder, create an environment and install the versions used for our run:
python -m venv .venv
source .venv/bin/activate
python -m pip install transformers==5.24.1 torch==2.15.0
Save the complete block below as moderate.py. The model revision is fixed so the example names the artifacts it was tested with. device=-1 selects CPU execution. The first initialization retrieves public model assets; the comment classification then runs locally. Our downloaded FP32 weights occupied 1,230,141,424 bytes, before the tokenizer and Python dependencies. Keep that footprint in mind when choosing a deployment host. These file observations are from our local run; they are not a memory benchmark. 2
import math
from transformers import pipeline
MODEL = "patronus-studio/tiger-guard-content-moderation"
REVISION = "4c7e8942b3d0f3213127ac9c8a6bc01031382813"
def open_moderator(source=MODEL):
return pipeline("text-classification", model=source, tokenizer=source,
revision=REVISION if source == MODEL else None,
device=-1, token=False)
def check_comment(text, moderator):
if not isinstance(text, str) or not text.strip():
return {"action": "held", "reason": "empty_input"}
if len(text) > 1_000:
return {"action": "held", "reason": "input_limit"}
try:
tokens = moderator.tokenizer(text, truncation=False)["input_ids"]
if len(tokens) > 256:
return {"action": "held", "reason": "token_limit"}
scores = {r["label"]: r["score"] for r in
moderator(text, top_k=None, truncation=False)}
p = scores["UNSAFE"]
if set(scores) != {"SAFE", "UNSAFE"} or not math.isfinite(p) or not 0 <= p <= 1:
raise ValueError("invalid classification")
if p > 0.5:
return {"action": "review", "unsafe_probability": p}
return {"action": "candidate", "unsafe_probability": p, "text": text}
except Exception:
return {"action": "held", "reason": "scan_unavailable"}
if __name__ == "__main__":
moderator = open_moderator()
for text in ["The search is useful. Could you add filters?",
"You are a worthless idiot and everyone here hates you."]:
result = check_comment(text, moderator)
print(result["action"], "released_text=" + str("text" in result))
Run python moderate.py. Our actual CPU run produced:
candidate released_text=True
review released_text=False
The program uses no hosted moderation API and makes no request to a live comment service. For reproduction we used Python 3.12.14, Transformers 5.24.1, PyTorch 2.15.0, CPU, two Torch threads, and the full-size model revision shown in the code. The downloaded graph's SHA-256 was 7e7fc1a4f6769d2ef3207a5947172e29a9791305cb60ccbb57120a4c1d322c13. Tokenizer compatibility matters: the unmodified published bundle did not initialize with the 4.57.6 client in our first attempt; the version above did.
Read the probability of the right label
The pipeline's default top result is a label and that label's score. A score of 0.99 attached to SAFE must not be mistaken for a 0.99 probability of unsafe content. top_k=None returns both labels; the example selects UNSAFE by name. Transformers documents this output option, while the model configuration defines the labels. 2 3
The application sends probabilities strictly above 0.5 to review. That is the model card's default operating point, made explicit in our code. It is a starting point for this example. A score below it neither authenticates the commenter nor proves that the comment is acceptable. The next section contains a concrete miss. 1
There are also two size limits. One thousand characters is an inexpensive application input limit. The tokenizer then checks a separate limit of 256 tokens, including special tokens. These are settings for this short-comment example, not Tiger Guard's context window. The model card documents a larger window and a separate long-document helper. This code deliberately refuses overlong comments rather than silently discarding their ending. 1
Eight actual comments, including one missed insult
We passed the following synthetic texts through the same function and real local model. The intended use was assigned from the written scenario before interpreting the result. Probabilities are rounded to six decimals; decisions use the unrounded values. This is a functional demonstration, not an estimate of production accuracy.
| Case | Complete synthetic comment | UNSAFE probability | Application result |
|---|---|---|---|
| C1 | The search is useful. Could you add filters? | 0.001217 | candidate |
| C2 | Die Suche ist langsam und die Filter fehlen. | 0.000223 | candidate |
| C3 | You are a worthless idiot and everyone here hates you. | 0.970525 | review |
| C4 | Du bist ein widerlicher Idiot. Niemand will dich hier haben. | 0.481333 | candidate (missed abuse) |
| C5 | I am reporting the comment "you are a worthless idiot". Please remove the abuse. | 0.035154 | candidate |
| C6 | Ich melde den Kommentar "Du bist ein widerlicher Idiot". Bitte prΓΌft diese Beleidigung. | 0.002148 | candidate |
| C7 | Calling people idiots is unacceptable. Please discuss the issue respectfully. | 0.011513 | candidate |
| C8 | Menschen als Idioten zu beschimpfen ist nicht in Ordnung. Bitte bleibt sachlich. | 0.000058 | candidate |
The German personal insult in C4 passed as a candidate at approximately 0.481333. For the stated application policy that is a missed abusive comment. We keep it in the result, rather than relabelling it as acceptable or selecting a different sentence that makes the example look better. C3 shows that the English insult was held for review; it does not establish reliable detection of all English insults.
C5 and C6 report abuse, while C7 and C8 oppose it. All four passed as candidates in this run. The contrast is useful when building your own checks: include the text that people quote while reporting a problem. Do not conclude from these four examples that Tiger Guard always handles quotes or counter speech correctly.
Why these cases belong in a pilot
RΓΆttger and colleagues' HateCheck specified 29 model functionalities for hate-speech detection. The researchers designed cases around particular capabilities and validated them through annotation, revealing weaknesses that a single aggregate score can obscure. Their work motivates checking categories of behavior, such as rejecting abuse while preserving legitimate language around it. It is not an evaluation of Tiger Guard, and our eight sentences are not the HateCheck suite. 4
For a comment feature, start with ordinary criticism, direct abuse, reported quotes and counter speech in the languages you actually serve. Add the spellings, idioms and formatting your users use. Define the expected action before reading the model output. Retain the exact input and decision when investigating an error, using suitably synthetic or appropriately handled data for testing.
Moving the threshold changes which scores trigger review; it does not teach the model a new platform policy. C4 falls close to 0.5, so a lower threshold would change that one decision. Whether the change helps overall depends on the benign comments newly sent to review and the abusive ones still missed. Check both groups on a separate evaluation set rather than tuning until these eight examples look correct.
Published model-card results answer a different question. The card separates a benchmark used during development from later evaluations, and reports different results across languages. Its training-overlap notes also matter when interpreting external datasets. Use those disclosed protocols when comparing models. Do not promote our eight functional examples into another benchmark, or equate one score table with your comment traffic. 1
Make unavailable checks visible
We also exercised the empty-input, character-limit and token-limit paths. Each returned held without released text. Loading a nonexistent local model directory failed at initialization with OSError. These are actual input and client failures, not simulated model classifications. Initialize the model before accepting work so a startup failure remains visible to the application.
The broad exception handler prevents a classification exception from releasing text. It is not a deadline mechanism and does not stop a worker that is still computing. A service needs its own resource and request-time controls. The example also does not inspect images, learn who the author is or reconstruct a conversation. A comment whose meaning depends on earlier turns needs an explicitly designed context policy and its own evaluation. The model card discusses the limitations of scoring a text on its own. 1
The insertion point is small: check one short comment, keep the exact returned text, and route review and execution problems away from automatic display. Open the Tiger Guard model repository to reproduce the run. The existing Tiger Guard overview covers model sizes and published comparisons. If you are fitting local moderation into an existing product, contact Patronus.
AI assistance was used for editorial preparation and translation. The local execution results above use synthetic inputs; no customer or live community deployment is described.
References
- Patronus Protect. Tiger Guard model card, revision
4c7e8942b3d0f3213127ac9c8a6bc01031382813, checked 30 November 2026. Task, policy, evaluation protocols and limits. - Hugging Face. Transformers 5.24.1 pipeline documentation, checked 30 November 2026. CPU device selection and classification outputs.
- Patronus Protect. Tiger Guard configuration, same revision. Label mapping and model configuration.
- Paul RΓΆttger, Bertie Vidgen, Dong Nguyen, Zeerak Waseem, Helen Margetts and Janet Pierrehumbert. HateCheck: Functional Tests for Hate Speech Detection Models. ACL-IJCNLP 2021, pages 41-58. Functional evaluation methodology; not a Tiger Guard evaluation.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.
