Step 1: Zero-Shot Classification

Classify security logs with no training data

1 ExplorePlay below
2 ReadUnderstand
3 BuildHands-on lab
4 CompareSolution
💡 ReflectThink deeper

What Is Zero-Shot Classification?

Traditional classifiers require labelled training data for every category. Zero-shot classification lets you define categories at inference time -- no training required. The model uses its general language understanding to match text to labels it has never been explicitly trained on.

ApproachTraining data needed?New categories?Security use case
Traditional classifierYes -- hundreds of labelled examples per classRetrain from scratchMalware family classification
Zero-shot classifierNo -- define labels at call timeJust add a new label stringMap SIEM alerts to MITRE ATT&CK tactics

The trade-off: zero-shot is less accurate than a fine-tuned model, but infinitely more flexible. For security teams that need to classify novel threat types without waiting for labelled datasets, this is transformative.

How It Works: Natural Language Inference (NLI)

Under the hood, zero-shot classification uses an NLI model. It frames the problem as: "Does the input text entail each candidate label?" The model scores each label independently:

Input textCandidate labelEntailment score
Outbound connection to 185.234.219.47:443 after powershell executionmalicious activity0.87
normal traffic0.08
configuration change0.05

The model has never seen these specific labels before. It uses its understanding of language to assess how well each label describes the input.

The HuggingFace Pipeline API

About that model name: HuggingFace model IDs follow the pattern org/name. facebook/bart-large-mnli means Facebook AI's BART architecture, the "large" size variant (~400M parameters), fine-tuned on the MNLI dataset — which is exactly what makes it work for zero-shot classification (the NLI training is what powers the entailment scoring shown in the table above). You'll learn to pick models for your own use cases in the workshop.

from transformers import pipeline

# Load the zero-shot classification pipeline
classifier = pipeline(
    "zero-shot-classification",
    model="facebook/bart-large-mnli"
)

# Classify a security log entry
result = classifier(
    "Lateral movement detected: SMB connections to 15 internal hosts",
    candidate_labels=[
        "lateral movement",
        "data exfiltration",
        "persistence",
        "normal traffic"
    ]
)

print(result["labels"][0])   # "lateral movement"
print(result["scores"][0])   # 0.92

Three lines of code. No training data. No model architecture decisions. HuggingFace handles tokenisation, model loading, and post-processing automatically.

Available Pipeline Tasks

TaskPipeline nameSecurity use case
Text classificationtext-classificationClassify log severity, phishing detection
Named entity recognitionnerExtract IPs, CVEs, malware names from reports
SummarisationsummarizationSummarise threat intel reports
Question answeringquestion-answeringExtract answers from policy documents
Zero-shot classificationzero-shot-classificationMap alerts to custom categories without training
Loading...
Loading...
Loading...

Think Deeper

Classify 'DNS query to known C2 domain at 3 AM from accounting workstation' using candidate labels: data exfiltration, lateral movement, C2 communication, normal activity. Which label wins? Now add 'scheduled backup' as a fifth label -- does the ranking change?

C2 communication should score highest because the text explicitly mentions a C2 domain. Adding 'scheduled backup' may slightly redistribute probabilities but should not displace C2. This demonstrates a key risk: label design controls model output. An attacker who understands your labels could craft log entries that push classification toward 'normal activity' -- this is an adversarial evasion technique against NLI-based classifiers.
Cybersecurity tie-in: Zero-shot classification lets a SOC team map raw SIEM alerts to MITRE ATT&CK tactics without any labelled training data. Define your tactic labels (initial access, lateral movement, exfiltration, etc.) and the model classifies each alert in real time. When a new tactic emerges, just add a label string -- no retraining needed.

Loading...