Lion Cipher Lab
Label phishing emails with weak supervision, and measure a label model against majority vote
- AI Security
- Advanced
- ~90 min
- Free · no account required
Why it matters
Every phishing classifier needs labelled emails, and labels are the expensive part. An analyst can hand-label a couple of hundred emails in an afternoon. Ten thousand would take weeks. WEAK SUPERVISION is the shortcut: instead of labelling emails, you write rules that label them for you, each one rough, and let math combine the votes. Snorkel made the idea popular, and a whole family of label models came from it. The pitch is that a clever model will work out which rules to trust without anyone giving it the answers. This lab tests that pitch on synthetic but realistic email data, with the…
What you'll learn
- writing labeling functions: twelve small phishing heuristics that each vote PHISH, BENIGN or ABSTAIN, and measuring their coverage, overlap and conflict on 10,000 unlabelled emails
- implementing a Dawid-Skene style EM label model from scratch in numpy, and proving it works where its assumption holds (F1 0.844 vs majority vote 0.766 on simulated independent rules, accuracies recovered to two decimals)
- measuring the same label model losing to plain majority vote on realistic email rules (F1 0.515 vs 0.646), and explaining why
- catching a label model that is confidently wrong: it believed a link rule was 0.999 accurate when the truth was 0.420, and a 200-email gold sample said 0.40
- showing how correlated rules double-count: 218 emails where only the two link rules fired were 1.8% phishing, yet the model gave them P(phish) 0.997
- showing that the class-balance prior moves the answer: 0.5 gave precision 0.180, the gold estimate 0.08 gave precision 0.643
- training a scikit-learn end model on weak labels and scoring it on unseen emails: majority-vote labels beat 200 hand labels on PR-AUC (0.737 vs 0.704) and recall (0.778 vs 0.604)
- telling a label gap from a feature gap: callback phishing went from 0.35 to 0.60 recall after one new rule, while vendor-account compromise stayed near zero even with every true label
Steps in this lab
- The words first: weak supervision, labeling function, label model, end model - and the fact that everything here is synthetic
- Open a terminal, make a folder, install numpy and scikit-learn
- Build the corpus: 10,000 unlabelled emails, a hidden truth file, 200 gold labels and a test set
- Write twelve labeling functions and measure coverage, overlap and conflict
- Write the label model: Dawid-Skene style EM, from scratch
- Sanity check: where the assumption holds, the label model wins - until you paste a rule three times
- Measure on the emails: majority vote beats the label model, and the model is sure of itself
- Honest negative 1: the duplicate rules double-count - and removing the duplicate is not enough
- Honest negative 2: the class prior moves the answer more than you would think
- Train the end model on each set of labels and score it on emails nobody has seen
- Honest negative 3: the sub-types your rules never saw - a label gap you can fix, and a feature gap you cannot
- Do it better: how a pro runs weak supervision, and when not to