Skip to content
BriskStack Study
Sign in
ML Paradigms & Python Engineering

Foundations, 2 of 5, about 5 h 5 min of reading

ML Paradigms & Python Engineering

About 4 h 52 min left

Concept. You cannot attack or defend a system whose learning paradigm you cannot name. This week is the engineering floor for everything that follows: the three ways machines learn, the Python toolchain that builds them, and a local model runtime that lets you probe a large language model (LLM) without an API key sitting between you and the failure. Verified status. The foundations are stable and not bleeding-edge, which is the point; only the reward-hacking worked example is recent.

🎯 Objectives

By the end of this unit you can:

  • Name supervised, unsupervised, and reinforcement learning, and map each paradigm to the attack class it invites.
  • Build and evaluate a real classifier in scikit-learn, the same shape as the spam and malware detectors you will later try to evade (scikit-learn).
  • Explain overfitting, generalization, and data leakage as security properties, not only accuracy problems.
  • Read PyTorch code (tensors, autograd, the training loop) well enough to follow an adversarial-example paper (Raschka).
  • Run a local LLM with Ollama so the model is the variable under test, not a remote black box (Ollama).
  • Design, train, and save a small neural network yourself (an nn.Module, a loss, an optimizer, the loop), so the artifact the attack weeks target is one you built (PyTorch).
  • (Go deeper) Fit an anomaly detector on network flows and engineer the DNS features that expose a beaconing backdoor. These are the two security-data tasks that Hack The Box's (HTB) path and this course's design ask for beside the spam filter (scikit-learn).
Next sectionThe big picture: three ways to learn, three ways to breakabout 1 minOpening question: A team ships a malware detector trained on labelled samples and tunes it to 99% accuracy. Which paradigm is that, which attack does the paradigm invite, and why is accuracy the wrong figure to report for a detector?

The big picture: three ways to learn, three ways to break

Every model you will attack in the attack weeks was trained under one of three paradigms, and the paradigm is the threat model. Supervised learning maps labelled inputs to outputs, such as spam or not spam, malware or benign. Its signature weakness is the adversarial example: a perturbation too small for a human to notice that flips the label. Unsupervised learning finds structure in unlabelled data, through clustering or anomaly detection, and it breaks when an attacker either hides inside a dense cluster or poisons the notion of "normal." Reinforcement learning optimizes a reward signal through trial and error, and it fails through reward hacking: the agent maximizes the proxy you wrote down instead of the goal you meant. Google's crash course frames the same split around classification, regression, and the generalization problem that sits under all of it (Google ML Crash Course).

🔑 The frame for the week: the learning paradigm predicts the attack. Supervised learning invites adversarial examples, unsupervised learning invites poisoning of the baseline, and reinforcement learning invites reward hacking. Learn to name the paradigm on sight.

Paradigm Learns from Canonical task Signature attack You'll exploit it in
Supervised Labelled examples Spam and malware classification Adversarial examples, evasion Adversarial Machine LearningModels and supply chain, 1 of 3, about 12.3 h
Unsupervised Unlabelled structure Clustering, anomaly detection Poisoning the "normal" baseline Adversarial Machine LearningModels and supply chain, 1 of 3, about 12.3 h–12
Reinforcement Reward signal Agent control, recommenders Reward hacking, spec gaming Core Concepts of Agentic AIFoundations, 4 of 5, about 5.3 h and Agentic Safety & Control PatternsAgent identity and control, 3 of 3, about 20.8 h

Recall from memory

A team ships a malware detector trained on labelled samples and tunes it to 99% accuracy. Which paradigm is that, which attack does the paradigm invite, and why is accuracy the wrong figure to report for a detector?

Not saved. Sign in and this question comes back in Review when you are about to forget it.

Next sectionBuilding a classifier, and why security people build one first (Needs access)
Sign in to keep reading. It is free, and your place is kept. Sign in and continue

Building a classifier, and why security people build one first

Generalization, overfitting, and data leakage as attack surface

Reading PyTorch: the language of the attacks to come

Reinforcement learning and reward hacking

Local LLMs with Ollama: removing the black box

✅ Check yourself

Go deeper: ML on security data, network flows and DNS

🧪 This week, hands-on

Finish ML Paradigms & Python Engineering

About 4 h 52 min left in this unit.

From memory first

Write the main points of this unit, in your own words.

What you set out to be able to do

Check each one against what you can do now.

The unit is done when you have answered the check and marked the required sources.

  1. 1 Check yourself

    Do the check
  2. 2 Required sources

    Go to the sources

Sources in this unit

  • Google's Machine Learning Crash Course
  • scikit-learn User Guide
  • scikit-learn: Text Classification Tutorial
  • Ollama Documentation
  • Sebastian Raschka: PyTorch in One Hour
  • Hugging Face: Deep Reinforcement Learning Course
  • StatQuest: Machine Learning
  • Kaggle: Intro to Game AI and Reinforcement Learning
  • Kaggle: Intro to Machine Learning
  • GitHub's model for secret detection: finding more secrets with less noise (GitHub)
  • scikit-learn: Novelty and Outlier Detection
  • CIC-IDS2017 (Canadian Institute for Cybersecurity)
  • Mandiant: SUNBURST backdoor analysis (2020-12-13)
  • SANS: Detecting DNS Tunneling (Farnham, 2013)
  • freeCodeCamp: Run and Customize LLMs Locally with Ollama
  • PyTorch: Build the Neural Network
  • PyTorch: Optimizing Model Parameters
  • learnpytorch.io: Zero to Mastery
  • Udacity: Intro to Deep Learning with PyTorch

Checklist

It does not count toward done.

  • Name supervised, unsupervised, and reinforcement learning, and the attack each one invites.
  • Build a spam classifier in scikit-learn (CountVectorizer, tf-idf, Naive Bayes, Pipeline) and see its predictions on held-out messages.
  • Report precision and recall separately, then induce a data leak and watch the fake accuracy appear.
  • Read a PyTorch training loop and explain what tensors, autograd with .backward(), and each step of the loop do.
  • Explain reward hacking as the reinforcement-learning failure mode and the ancestor of spec gaming.
  • Set up a local LLM with Ollama and call its localhost:11434 API from Python to get a reply.
  • Sweep a decision tree's max_leaf_nodes on real data, trace the mean absolute error (MAE) U-curve, and name the generalization sweet spot (Kaggle Intro to ML).
  • Walk the Connect Four arc (one-step heuristic, minimax, Stable Baselines) and explain where a hand-written objective ends and reward hacking begins (Kaggle Game AI and RL).
  • Train a two-layer MLP in PyTorch on the spam tf-idf features for five epochs, report precision and recall per epoch, save the state_dict, and compare its top tokens by input gradient with Naive Bayes's.
  • (Go deeper) Fit IsolationForest on CIC-IDS2017's Monday flows and score Wednesday and Thursday, with precision and recall for DoS and for infiltration apart. Then engineer DNS length, entropy, unique-subdomain, and cadence features and catch ten planted SUNBURST-shaped lookups.
Drill, planned

Three words to flip a spam filter

Attack: Flip a spam filter by appending at most three words from the model's own vocabulary Defend: Cap the appended words' weights and recompute how many messages still flip

Nothing to do here yet; the unit is complete without it.

Practise this in the lab, Fool a small classifier, then ask what it remembers.1 h to 1 h 30 min estimate

Practise this in the lab, Clone a model through its API, then catch the cloner.1 h to 1 h 15 min estimate

Practise this in the lab, Capstone: one engagement, replayable findings and a scope log.1 h 40 min estimate

Study notes

None yet

Sign in to take notes.

More for this unit

11 readings

Readings no section cites. They do not count toward the unit.

Show
Supervised, unsupervised, and reinforcement learning2 readings
  • youtube.comvideoGo deeper

    A playlist that explains individual topics clearly. Pick the videos for the topics you need rather than watching all of it.

  • kaggle.comvideoGo deeper

    An interactive mini-course that teaches reinforcement learning concepts through game-development exercises. Do it alongside the reinforcement section.

Building a classifier (hands-on)2 readings
  • kaggle.comlabGo deeperabout 4 h

    An interactive notebook course on real datasets. Do it first if ML itself is new to you.

  • github.blogreferenceGo deeper

    a two-stage ML pipeline — fast high-recall regex candidate generation + a fine-tuned ModernBERT classifier that reads surrounding context (file path, variable names, nearby code) to kill hard-negative false positives — replaced an LLM scanner for +19% recall / +13% precision, 86% faster, 98% cheaper; a real-world precision/recall + hard-negative engineering case for this week's ML fundamentals

Go deeper: ML on security data (network flows and DNS)3 readings
  • unb.calabGo deeper

    Five days of labelled traffic, with Monday benign only, and more than 80 CICFlowMeter features per flow. It is the dataset for the flow-anomaly drill.

  • cloud.google.compaperGo deeper

    It shows DNS used for command and control (C2): encoded victim subdomains, CNAME steering, an A-record kill switch, and random gaps of 1 to 3 or 30 to 120 minutes between lookups after up to two dormant weeks. Read it to see the behaviors the DNS features target.

  • sans.orgpaperGo deeper

    It describes the two detection families, payload analysis and traffic analysis, that the DNS feature set follows. Read it before you engineer the DNS features.

Local LLMs with Ollama1 reading
PyTorch basics3 readings
  • docs.pytorch.orglabGo deeperabout 30 min

    The training loop with the numbers filled in: cross-entropy loss, SGD at 1e-3, batches of 64, a train loop, and a no_grad test loop. Do it right after the build tutorial.

  • learnpytorch.iocourseGo deeper

    A hands-on, code-first PyTorch course with 25h of video on YouTube and a free online book. Pick it if you learn best by typing along.

  • udacity.comvideoGo deeper

    A free course on natural language processing, computer vision, and building deep neural networks. Take it if you want a structured alternative to the tutorials.

This unit's library holds 13 more readings for readers with access.