Intermediate7 min readUpdated

Zero-shot classification: how a model understands rules written in plain words

How can a model enforce “No spoilers” if it was never trained on that rule? Natural language inference, entailment and custom moderation rules, explained.

The problem

A classic classifier knows only the categories it was trained on. But every community has its own rules: no spoilers, no selling accounts, only football talk, no links to other servers. Training a new model for every rule of every community is impossible.

Zero-shot classification solves it: the model receives the category as a sentence at the moment of the request, and judges whether the text matches it.

Natural language inference (NLI)

Many zero-shot classifiers are built on a task called natural language inference. The model gets two texts:

  • a premise (here: the chat message),
  • a hypothesis (here: a rule or a category description),

and decides whether the premise entails the hypothesis, contradicts it or is neutral.

Premise (message)HypothesisAnswer
“lol the dog dies at the end”“This message reveals the plot of a film or series.”entails
“anyone watched the finale?”“This message reveals the plot of a film or series.”does not entail
“selling my lvl 80 account, DM me”“This message offers to buy or sell game accounts.”entails

The probability of “entails” becomes the score of the rule. The same mechanism handles fixed categories too: “insult” is just the hypothesis “This message insults a person”.

Why it generalises

During training the model sees hundreds of thousands of premise–hypothesis pairs about every kind of topic. It does not learn the rules themselves: it learns the skill of checking whether a text matches a description. That skill transfers to rules it has never seen, in any language the model knows.

Writing good rules

  • Concrete beats abstract. “No buying, selling or trading accounts or items” works better than “Respect the economy”.
  • One idea per rule. Split “No spam and no politics” into two rules.
  • Describe the behaviour, not the word list. “Do not reveal the end of films or series” catches spoilers written in any way.
  • Test on real examples and adjust the threshold, as for any category.

Context helps rules too

“He dies at the end” is a spoiler only if the conversation is about a series. Zero-shot models that also read the previous messages can judge rules that depend on the chat, see context in moderation.

In VigiMod

Rules are sent with each request, up to 10, in any language:

"rules": {"no-spoilers": "No spoilers about films or series"}

Each rule returns its own score and flag (rule:no-spoilers), next to the built-in categories. Details in the documentation.

Test yourself

Answer the questions, then check your answers.

  1. 1. What does “zero-shot” mean here?
  2. 2. In NLI, the chat message plays the role of…
  3. 3. Which rule is likely to work best?
  4. 4. Why can the model check a rule it never saw?

All guides →

See it on real messages

Try the live demo, or read how the API works.