1 / 34
1
ComplianceGPT Lab · AI Innovation & Diffusion REU 2026

Neural Networks → Transformers → LLMs

A detailed walkthrough of how we got from a single neuron to Gemma3-4B — matched to notebooks 02, 04, 05, 06

teach_02
Neural Networks
XOR, backprop, depth, scale
teach_04
Transformers
tokens, attention, Q/K/V
teach_05
Encoders
sentence embeddings
teach_06
LLMs — Real Results
94.2% on GoldCoin

Every number on a verified slide was computed live from this repo's actual data during prep for today — experiments/finalserverrun/final_vast_gemma3_4b.csv (137 cases) and the four instructor notebooks. Two demo cells needed a fix before class — flagged where they come up.

2
Part 1 — Neural Networks
Part 1 · Neural Networks (teach_02_dl.ipynb)

Learning Arc

Five steps, in order, each one motivated by the failure of the step before it.

Today's arc

  1. Show what a linear model can't do (XOR)
  2. A neural network = layers of learned, non-linear transforms
  3. Backpropagation — the training loop, live
  4. Depth — why more layers solve harder problems
  5. Scale — same math, 10 billion× more parameters = LLM

Why this comes before Transformers

Every Transformer layer is built from the same two primitives you'll see today: a matrix multiply + non-linearity, trained by backpropagation. Gemma3-4B has no new math — it has 4 billion of the same parameters you're about to train 17 of.

3
Part 1 — Neural Networks

The Wall — What Logistic Regression Can't Do

Logistic Regression draws one straight line (or flat plane) to separate classes. XOR is the smallest problem where that's mathematically impossible.

XOR(A, B) = 1 only when exactly one is 1

ABXOR
000
011
101
110

The two 1s sit in opposite corners of the plane. No single straight line separates them from the two 0s.

Logistic Regression on XOR verified

from sklearn.linear_model import LogisticRegression lr = LogisticRegression() lr.fit(X_xor, y_xor) # Predictions: [0 0 0 0] # True labels: [0 1 1 0] # Accuracy: 50%

A coin flip. It predicts the majority class every time — there is no line to find, so gradient descent gives up at the best it can do.

4
Part 1 — Neural Networks

Solving XOR — and a Live Gotcha verified

One hidden layer (4 neurons, ReLU) should learn a new coordinate system where XOR becomes linearly separable. Run live today, it doesn't always — and that's worth teaching too.

As scripted (relu + adam + seed 42)

MLPClassifier(hidden_layer_sizes=(4,), activation='relu', random_state=42) # Predictions: [0 0 0 0] # Accuracy: 50% ← stuck!

This exact configuration hits a dead ReLU: with this seed's initial weights, every hidden unit's input starts negative, ReLU zeroes it, and the gradient is zero everywhere — training can't escape.

The fix — swap activation to tanh

MLPClassifier(hidden_layer_sizes=(4,), activation='tanh', random_state=42) # Predictions: [0 1 1 0] # Accuracy: 100% # Params: 17 (12 weights + 5 bias)

tanh can't die the same way (its output is never flat-zero for negative inputs), so it always finds the fold. Same architecture, same seed, different result.

Teaching moment

"Whether a network trains isn't just about whether the function is representable — it's about whether gradient descent can find it from this starting point." This is the single most common real-world debugging issue with neural nets, and you just watched it happen on the simplest possible example. Before class: edit the activation in teach_02_dl.ipynb cell 4 from 'relu' to 'tanh', or the printed narration ("→ 100%") will contradict the printed accuracy line.

5
Part 1 — Neural Networks

What a Neuron Actually Computes

A neural network is a function built from millions of copies of one simple unit.

output = ReLU(w₁x₁ + w₂x₂ + ... + wₙxₙ + bias)
  • w — weights, learned during training
  • bias — offset, also learned
  • ReLU(z) = max(0, z) — the non-linearity. Without it, stacking layers is mathematically identical to one layer.

Manual neuron: w₁=0.7, w₂=0.3, bias=−0.2 verified

Input (x₁,x₂)z = 0.7x₁+0.3x₂−0.2ReLU(z)
(0, 0)−0.200.00
(0, 1)+0.100.10
(1, 0)+0.500.50
(1, 1)+0.800.80

One neuron is a weighted vote with a floor at zero. Gemma3-4B repeats this ~4 billion times, arranged in 34 layers.

6
Part 1 — Neural Networks

Backpropagation — the Training Loop, Live verified

Training is four steps repeated until the loss stops improving. Below: real loss values training an 8×4 hidden network on XOR (tanh, lr=0.1).

1 · Forward

Input flows through every layer. Final layer produces a prediction.

2 · Loss

Compare prediction to the true label. One number: how wrong.

3 · Backward

Chain rule: how much did each weight contribute to the error?

4 · Update

Nudge every weight to reduce the loss. Repeat from step 1.

Loss curve — 200 epochs on XOR

Epoch1102550100150200
Loss0.6850.3400.1520.0850.0720.0710.071

Sharp drop in the first ~50 epochs, then it flattens near zero — the network has found the fold in feature space that separates the two classes. Final accuracy: 100%.

7
Part 1 — Neural Networks

Why Depth Matters verified

XOR needed one hidden layer. A harder, checkerboard-shaped pattern (200 points, 4 alternating quadrant classes) needs more.

Architecture5-fold CV accuracy
Logistic Regression (0 hidden)46.5%█████████
Shallow MLP (1 layer × 8)45.0%█████████
Deeper MLP (2 layers, 32×16)65.0%█████████████
Deep MLP (4 layers, 64×32×16×8)73.5%███████████████

Read this carefully

A single hidden layer is barely better than no hidden layer at all on this problem — it's actually worse here (45.0% vs 46.5%) due to optimization noise on a hard, highly non-linear boundary. Depth is what buys the real gain: 2 layers → 65%, 4 layers → 73.5%.

The 2012 AlexNet moment

ImageNet: best 2011 approach, 26% error. AlexNet — a deep network on GPUs — 15.3% error. A 10-point gap overnight. Every layer refines the representation: edges → shapes → objects. In text: tokens → phrases → legal concepts.

8
Part 1 — Neural Networks

Scale — Parameters and Compute

Same math you just ran (17 parameters). Modern LLMs are the identical architecture, scaled by ten billion.

ModelParametersTraining computeNotes
Perceptron (1958)1punch cardsXOR impossible
Early MLP (1980s)1,000CPU secondstoy problems
LeNet (1998)60,000CPU hoursMNIST digits
AlexNet (2012)61,000,000GPU daysImageNet photos
BERT-base (2018)110,000,000GPU weeksNLP understanding
GPT-3 (2020)175,000,000,000GPU monthsfew-shot learning
Gemma3-4B (our model)4,000,000,000≈4 GPU-daysfits on one V100
GPT-4 (est., 2023)1,800,000,000,000months (est.)frontier model

Every one of those parameters is a w in a neuron exactly like the one on slide 5. Nothing new happens conceptually between here and Gemma3 — only scale, and (next section) how it reads sequences.

9
Part 1 — Neural Networks

Back to HIPAA — Does Depth Help? verified

Take the 9 boolean oracle predicates already extracted by Gemma3-4B for all 137 GoldCoin cases. Predict PERMITTED/DENIED from those 9 numbers alone — does a deeper network do better?

Model (on 9 extracted booleans)5-fold CV accuracy
Logistic Regression68.0%
Decision Tree (depth 5)64.3%
MLP (16×8)63.6%
Deep MLP (64×32×16)63.6%
Actual system: LLM extraction → Soufflé engine94.2%

The honest, more interesting result

Depth does not help here — a plain Logistic Regression on 9 clean booleans (68.0%) slightly beats every MLP variant. That's not a contradiction of slide 7: depth helps when the network has to discover structure from raw signal (pixels, checkerboard coordinates, raw text). Once Gemma3 has already collapsed a 300-word legal narrative into 9 clean flags, there's no more structure left to discover — the hard part was the extraction, not the classification. That's the whole thesis of this week.

10
Part 2 — Transformers & Attention
Part 2 · Transformers & Attention (teach_04_transformers.ipynb)

Learning Arc

Neural networks need numeric input. Text isn't numeric, and it's sequential. This section answers: how does a network read a sentence, and why does context change meaning?

  1. Tokenization — text → integers
  2. The RNN problem — why sequential processing fades
  3. Self-attention — every token to every token
  4. Same word, different meaning by context
  5. Positional encoding — how order survives

No GPU, no HuggingFace download

Every demo in this section runs in plain numpy on a laptop CPU — the attention mechanism is simple linear algebra. Scale (34 layers × 8 billion multiplications) is the only thing that requires a GPU.

11
Part 2 — Transformers & Attention

Tokenization — Text Becomes Integers verified

LLMs process subword tokens, not words. GPT-4's tokenizer (cl100k_base, ~100k vocabulary) is used here as a stand-in — Gemma3 uses a similarly-sized vocabulary (256,128 tokens).

Real HIPAA sentence, tokenized

"HIPAA §164.512(e) permits
disclosure with a court order."

Legal citations like §164.512(e) split into several small pieces — the symbol §, the section number, the parenthetical — each an independent token the model must reassemble meaning from.

Token counts, all 137 GoldCoin scenarios

MinMedianMeanMax
475858.076

Gemma3-4B context window: 8,192 tokens. Even the longest scenario prompt uses under 1% of it — plenty of headroom for the schema + instructions template on top.

12
Part 2 — Transformers & Attention

The RNN Problem — Why Sequential Fails verified

Before Transformers, RNNs read text one token at a time, passing a "hidden state" forward. Each step compresses everything seen so far into one fixed-size vector.

Signal retention: hidden = 0.9 × hidden + 0.1 × new input

After N tokensSignal remaining
190.0%
559.0%
1034.9%
2012.2%
500.5%

Real HIPAA sentence (34 words)

"The patient, who was admitted after a workplace injury treated by a physician who had previously disclosed records in an unrelated matter, filed for damages claiming the hospital had shared information without court authorization."

Subject ("patient") is at word 2. Key fact ("without court authorization") is at word 34.

Signal from "patient" surviving to word 34: 2.78%

→ By the time an RNN reaches the legal fact, it has essentially forgotten who the subject is. This is the vanishing gradient problem, and it's exactly why Transformers throw sequential processing out entirely.

13
Part 2 — Transformers & Attention

Self-Attention — Every Token to Every Token

For each token, compute a score for how much it should "look at" every other token. Same word, different sentence, different attention pattern, different meaning. (Illustrative weights below — in a trained model these are learned, not hand-set.)

LEGAL: "The judge signed the order to release records"

judge  0.20  signed 0.15  release 0.09
→ order = COURT ORDER → has_court_order = true

MEDICAL: "The physician wrote a medication order"

physician 0.18  medication 0.24
→ order = MEDICATION ORDER → has_court_order = false

SAME WORD. DIFFERENT CONTEXT. DIFFERENT MEANING.
This is exactly what TF-IDF (Part 3, next section) cannot represent — and exactly why transformers exist.

14
Part 2 — Transformers & Attention

Attention Math — Q, K, V verified

From "Attention Is All You Need" (Vaswani et al., 2017):

Attention(Q, K, V) = softmax( QKᵀ / √dₖ ) V

What Q, K, V mean

  • Q (Query) — what is this token looking for?
  • K (Key) — what does each token offer?
  • V (Value) — what information does it carry?
  • √dₖ — scales the dot product so gradients don't explode

Toy attention matrix — 5 tokens, d_model=4

tok0 tok1 tok2 tok3 tok4 tok0: 0.20 0.21 0.14 0.14 0.30 tok1: 0.21 0.18 0.12 0.16 0.34 tok2: 0.16 0.17 0.09 0.13 0.45 tok3: 0.20 0.14 0.19 0.34 0.13 tok4: 0.14 0.25 0.35 0.14 0.11

Each row sums to 1.0 — a probability distribution over "how much attention this token pays to every token."

In Gemma3-4B: d_model=2048, seq_len up to 8,192 → an 8,192×8,192 attention matrix (67M values) computed in parallel on GPU, for every one of 8 attention heads, at every one of 34 layers.

15
Part 2 — Transformers & Attention

Positional Encoding — How Order Survives verified

If every token attends to every other token simultaneously, attention alone can't tell "court order" from "order court" — it's permutation-invariant. Transformers add a positional vector to each token's embedding.

PE(pos, 2i) = sin(pos / 10000^(2i/d))
PE(pos, 2i+1) = cos(pos / 10000^(2i/d))

Sinusoidal, fixed (not learned). Each position gets a unique fingerprint; nearby positions get similar fingerprints, so the model can infer relative distance.

First 6 positions, 8 dimensions

pos0: +0.00 +1.00 +0.00 +1.00 +0.00 +1.00 +0.00 +1.00 pos1: +0.84 +0.54 +0.10 +1.00 +0.01 +1.00 +0.00 +1.00 pos2: +0.91 -0.42 +0.20 +0.98 +0.02 +1.00 +0.00 +1.00 pos3: +0.14 -0.99 +0.30 +0.96 +0.03 +1.00 +0.00 +1.00 pos4: -0.76 -0.65 +0.39 +0.92 +0.04 +1.00 +0.00 +1.00 pos5: -0.96 +0.28 +0.48 +0.88 +0.05 +1.00 +0.00 +1.00
16
Part 2 — Transformers & Attention

The Full Forward Pass + Gemma3-4B Specs

TOKENIZE"The judge signed a court order" → [512, 4008, 9431, 287, 2267, 1502]
EMBEDeach ID → 2048-dim vector (learned lookup table)
+ POSITIONadd positional encoding to each embedding
LAYERS 1–34self-attention + feed-forward + residual, repeated. Early: syntax. Mid: semantics. Late: reasoning.
OUTPUTfinal hidden states → 256,128 vocabulary scores → next-token probabilities

Gemma3-4B specifications

Parameters: 4 billion
Layers: 34
d_model: 2,048
Attention heads: 8
Context window: 8,192 tokens
Vocabulary: 256,128
GPU memory: ~8GB @ 4-bit
Fits on: one V100 (cluster)
17
Part 3 — Encoders & Embeddings
Part 3 · Encoders & Sentence Embeddings (teach_05_encoders.ipynb)

Learning Arc

The Transformer architecture splits into two families. We use the understanding half — an encoder — to finally represent whole-sentence meaning as geometry.

Encoder (BERT)Decoder (GPT, Gemma)
DirectionBidirectional (left + right)Left-to-right only
Training taskPredict masked wordsPredict next word
Use forUnderstanding, classificationGeneration, completion
Today's exampleSentence embeddingsLLM oracle extraction
18
Part 3 — Encoders & Embeddings

Closing the Semantic Gap verified

Query: "A court order was issued requiring release of the records." Cosine similarity to other phrases, computed live with all-MiniLM-L6-v2.

PhraseTF-IDF simEmbedding sim
"A judicial mandate compelled disclosure of patient information"0.0580.566
"The subpoena issued by the court authorized disclosure"0.1280.599
"Law enforcement asked the hospital to turn over the file"0.0600.617
"The officer implied there might be a court order forthcoming"0.1620.561
"The physician requested records for treatment purposes"0.0430.638

TF-IDF: "court order" and "judicial mandate" score 0.058 — near zero, despite triggering the identical HIPAA exception. Embeddings lift that to 0.566 — real progress, but notice it's not close to 1.0 either. Embeddings capture rough topic similarity, not legal validity — and interestingly, the hedged "implied there might be a court order" (0.561) scores about the same as genuine court-order language, not clearly higher. Embeddings alone can't reliably tell real authority from a passing mention of authority. That's the gap the LLM has to close.

19
Part 3 — Encoders & Embeddings

Does It Actually Improve Classification? verified

Real 5-fold cross-validation, all 137 GoldCoin scenarios, predicting PERMITTED vs DENIED from text representation alone (no LLM extraction).

MethodAccuracy
Majority-class baseline63.5%████████████
TF-IDF (uni+bigrams) + LogReg63.5%████████████ (no better than guessing!)
Sentence embeddings + LogReg82.0% (±16.2%)████████████████
LLM extraction → formal engine94.2%██████████████████

The number that should surprise you

TF-IDF + Logistic Regression gets exactly the majority-baseline accuracy — it learns nothing useful from the text at all on this task. Embeddings jump to 82% but with high fold-to-fold variance (±16.2%) — on 137 examples, embeddings are unstable. Only reading the full text in context, with an LLM, closes the rest of the gap reliably.

20
Part 3 — Encoders & Embeddings

Semantic Search on Real GoldCoin Cases

Embeddings let you search by meaning, not keywords — useful when writing adversarial test scenarios: find the real cases most similar to a hypothetical you're designing.

def semantic_search(query, top_k=5): q_emb = model.encode([query]) sims = cosine_similarity(q_emb, X_emb)[0] return sims.argsort()[::-1][:top_k] semantic_search("judicial mandate requiring disclosure") # → ranks all 137 cases by embedding similarity, # not by shared vocabulary

Why this matters for your project

If you're pursuing P1 Adversarial Robustness, this is your tool: write a new hedged scenario, embed it, and see which real cases it lands closest to. If it lands close to a DENIED case but you designed it to look PERMITTED, you've likely found a real Gemma3 failure mode before you even run the model.

21
Part 4 — LLMs: The Real System
Part 4 · LLMs — Real System Results (teach_06_llm.ipynb)

Learning Arc

Everything so far was building intuition on toy or synthetic data. This section is 100% real: the actual Gemma3-4B experiment on the Stony Brook cluster, 137 real GoldCoin court cases.

Court case text
Gemma3-4B (V100 GPU)
JSON: 5-tuple + 24 oracles
Soufflé Datalog engine
PERMITTED / DENIED
22
Part 4 — LLMs: The Real System

Headline Numbers verified

129 / 137
correct — 94.2% accuracy
87 / 50
PERMITTED / DENIED ground truth
15.8s
mean latency per case (V100)

Latency distribution

MinMedianMeanMaxStd
8.3s14.3s15.8s41.4s4.6s

Total GPU time for all 137 cases: 36.0 minutes. Throughput: ~228 cases/hour on one V100.

GPU used

V100 32GB — Stony Brook AI Cluster. This is the exact hardware you'll submit your own extraction job to this afternoon (Exercise 9).

23
Part 4 — LLMs: The Real System

One Case, Start to Finish verified

Case row_id 4 — a correct PERMITTED prediction.

STEP 1 — Input text (as truncated for the model)

"In early 2005, a legal battle unfolded involving Anthony Camillo, a plaintiff familiar with Medicare billing practices, and Kenneth Hall Regional Hospital, the defendant. The crux of the dispute was the hospital's billing and refund records, which Camillo suspected contained evidence of fraudulent M…"

STEP 2 — Extracted CI 5-tuple

senderKenneth Hall Regional Hospital
receiverAnthony Camillo (plaintiff)
subjectpatients
attributemedical information
purposelitigation

STEP 3 — Oracles set TRUE (of 24)

  • has_court_order
  • has_lawful_process_with_assurance
  • in_compliance_with_court_order
  • mentions_protective_order
  • is_authorized_by_law_for_purpose

STEP 4 — Soufflé verdict: PERMITTED (cites §164.512(e)(1)(ii) — subpoena with satisfactory assurance). Match: ✓ correct. Inference latency: 19.6s.

24
Part 4 — LLMs: The Real System

The 8 Failures — FP vs FN verified

3 False Positives

Model said PERMITTED, ground truth was DENIED.

→ Safety-critical: this is a real PHI disclosure that shouldn't have happened.

Cases: row_id 40, 46, 123

5 False Negatives

Model said DENIED, ground truth was PERMITTED.

→ Over-blocking: a lawful disclosure got incorrectly rejected.

Cases: row_id 16, 27, 30, 59, 66

FNs outnumber FPs 5-to-3 on this run — Gemma3-4B leans slightly toward under-granting access, not over-granting it. That's the safer failure direction, but it's still 5 real cases of incorrectly blocked lawful disclosure.

25
Part 4 — LLMs: The Real System

Anatomy of a False Positive — Case 40 verified

Truth: DENIED (cites §164.502(a)). Model said: PERMITTED.

"In 2012, an individual found himself requiring emergency medical services and was taken by ambulance to a hospital. To receive this necessary medical attention, he provided the ambulance service, operated by the Philadelphia Fire Department EMS, with his personal and sen[sitive information]…"

Oracles hallucinated TRUE

is_business_associate · believes_unlawful_conduct · believes_victim_of_crime · is_required_by_law · mentions_patient_notice · has_ba_agreement

What the model said

"…permitted under 45 CFR §164.502(a)(1)(i), which allows disclosure to the individual or their personal representative…" — a plausible-sounding citation attached to the wrong exception. It over-generalized routine EMS billing/payment processing into six separate enabling oracles that weren't actually satisfied.

26
Part 4 — LLMs: The Real System

Anatomy of a False Negative — Case 16 verified

Truth: PERMITTED (cites §164.502). Model said: DENIED.

"In a small town, A.S., a young woman with a developmental disability, was under the care of her parents who were appointed as her guardians by a probate court. Throughout her education, A.S. received special education services due to her condition. When she turned eighteen in 2003, her parents became…"

Oracles the model DID get right

has_authority_to_act · provider_patient · believes_minimum_necessary · is_in_designated_record_set

Where it went wrong

The model answered "DENIED under §164.203(a)(1)" — reasoning about a related-but-wrong provision (mental-health-evaluation confidentiality) instead of the guardian-authority exception that actually governs this case. It extracted correct facts but the LLM's own explanation cites the wrong rule — a reasoning failure downstream of extraction, not just an oracle miss.

27
Part 4 — LLMs: The Real System

Oracle Risk Table — Which Predicates Fail Most? verified

How often each oracle predicate is set TRUE in failure cases vs. correct cases (real counts, 137 cases).

Oracle predicateIn failuresIn correct cases
provider_patient552
has_treatment_relationship559
has_authority_to_act373
believes_minimum_necessary224
prohibited_by_other_law23
is_required_by_law259
believes_unlawful_conduct226
has_ba_agreement213

No single predicate dominates the failure set — the 8 errors are spread across 20 different oracles, each appearing 1–5 times. There's no one broken rule to patch. This is consistent with what you saw in case 40 (over-firing) and case 16 (right facts, wrong reasoning): the errors are contextual, not systematic.

28
Part 4 — LLMs: The Real System

Does Confidence Predict Correctness? verified

Hypothesis: maybe the model "hesitates" (takes longer) on cases it's about to get wrong. Real latency data says otherwise.

15.92s
mean latency — correct cases
13.49s
mean latency — failed cases

The counter-intuitive real finding

Failures were faster, not slower. There's no latency signal for uncertainty here — if anything, wrong answers were produced slightly more decisively. Don't trust "the model took a while, it must be thinking hard" as a proxy for correctness. Confidence (fast, fluent output) and correctness are simply not the same thing — this is the RLHF effect from Part 4's training discussion: models are optimized to sound sure of themselves.

29
Part 4 — LLMs: The Real System

Your Research — Six Directions on the Same 5.8% Gap

You've now seen every layer: neuron → attention → embedding → extraction → engine. The 8 remaining errors are your research target. Project selection due Friday, July 3.

P1

Adversarial Robustness

Can you write new scenarios that break the model the same way case 40 broke?

P2

Multi-Regulation

Does this same error pattern show up in GDPR / CCPA extraction too?

P3

Model Comparison

Does a larger model (Llama3-70B) fix cases 40 and 16?

P4

Prompt Engineering

Do stricter oracle definitions or few-shot negatives fix the FPs?

P5

Error Explanation

Can you automatically diagnose why a prediction was wrong?

P6

Few-Shot Examples

Does adding 3–5 worked examples to the prompt close the gap?

30

The Full Progression — Verified Numbers Side by Side

Every accuracy figure below was computed live on the real 137-case GoldCoin benchmark during prep for today.

ApproachWhat you saw todayAccuracyWall hit
Logistic RegressionSlide 3 — XOR50%Can't draw a curved boundary
Neural network (correct activation)Slide 4 — XOR100%Needs numeric features; text isn't numeric
MLP on 9 extracted booleansSlide 9 — HIPAA68.0%Ceiling of the classifier, not the features
TF-IDF + Logistic RegressionSlide 19 — HIPAA63.5%= majority baseline. Learns nothing.
Sentence embeddings + LogRegSlide 19 — HIPAA82.0% (±16.2%)Unstable; can't distinguish hedged from real authority
LLM extraction → formal engineSlide 22 — GoldCoin94.2%8 contextual errors remain — no single broken rule
31

Why Each Step Was Necessary

Neural nets Non-linear boundaries: solved XOR (100%) where linear models cap at 50%. Still needs numeric input
Tokenization Text → integers. Legal citations split into pieces the model reassembles. No meaning yet, just IDs
Self-attention Context-dependent meaning: "order" = court order or medication order, decided by neighbors. Solved what RNNs (2.78% signal at word 34) couldn't
Sentence embeddings Meaning as geometry: "court order" ↔ "judicial mandate" rose from 0.058 to 0.566 similarity. Still can't separate real from hedged authority
Full LLM (Gemma3) Scale + full-context reading: 4B parameters get you to 94.2% — real, contextual, mostly correct legal reasoning. 8 cases left — your research
32

Two Things to Fix Before You Run These Notebooks Live

Discovered while verifying today's numbers — both notebooks currently have never been executed, so these haven't surfaced yet.

teach_02_dl.ipynb — cell 4 (XOR neural net)

With activation='relu', random_state=42, the network hits a dead-ReLU state and prints Accuracy: 50% — but the next line still says "→ 100%. The hidden layer learned…", contradicting its own output live in front of students.

Fix: change activation='relu''tanh' in that cell (and the loss-curve cell right after it). Verified: gives 100% and a clean decreasing loss curve.

teach_05_encoders.ipynb — adversarial-gap cell

The script's narration claims group C (hedged phrases) embeds closer to group A (real court orders) than group B does. Run live with all-MiniLM-L6-v2, the opposite comes out: avg(C→A)=0.401 vs avg(B→A)=0.460.

Fix: use slide 18/19 of this deck instead — the single-phrase table (A1 vs. others) still makes the core point honestly, and the full-dataset classification comparison (63.5% → 82.0% → 94.2%) is a more robust, real result than the 12-phrase toy demo.

33

This Week's Notebooks — Quick Reference

#TopicKey demoWhen
01Machine Learning3 classifiers on FIFA → HIPAA feature-extraction wallMon
02Deep LearningXOR: LR fails (50%), MLP succeeds (100% with tanh)Mon/Tue
03NLPSemantic gap: "court order" ↔ "judicial mandate" = 0.06–0.13Tue
04Transformers"order" = different meaning by context; 2.78% RNN signal at word 34Tue/Wed
05EncodersEmbedding similarity 0.566–0.638; classification 63.5%→82.0%Wed
06LLMs129/137 = 94.2%; 8 failures live via show_case(N)Wed/Thu

Today (Wed, Jul 1): notebooks 04, 05, 06 — everything in Parts 2–4 of this deck.

34

94.2% — Now You Know Every Wall That Led Here

What you built today, by hand

  • A neuron, and watched why it can fail to train
  • Backpropagation, epoch by epoch, watching loss fall
  • Self-attention, on paper, disambiguating "order"
  • A sentence embedding space, and where it still fails
  • Full failure analysis of a real 4-billion-parameter model

This afternoon

Exercise 9 — submit your own Gemma3-4B extraction job to the V100 cluster you just read the specs of. Then Exercises 7–8: find your own failure case, and diagnose it exactly the way we diagnosed cases 40 and 16.

"You've seen every wall that led here. Now: which one do you want to try to climb?"