Probing classifiers
Definition & Problem Setup
Why "frozen" representations? If we fine-tuned , the model could learn to encode during probing—we'd measure the model's capacity to learn , not whether it already learned it during pre-training.
Derivation: What Does Probe Accuracy Tell Us?
Let's formalize the intuition. Suppose are layer- activations, and we probe with a linear classifier:
where is softmax (multiclass) or sigmoid (binary), , .
What does high probe accuracy mean?
-
Information theoretically: contains mutual information where is the true label distribution for task . High accuracy high MI.
-
Geometrically: The classes of are linearly separable in the representation space. The decision boundary cleanly partitions the space.
-
Causally: The pre-training objective induced features that correlate with . This happens if is a useful intermediate step for the main task, or if the data structure forces to be encoded.
Derivation of the separability condition:
For perfect linear separability, we need a hyperplane such that:
Define the margin :
If , classes are linearly separable. Probe training (e.g., via logistic loss) finds that maximize margin-like quantities.
Why this step? The margin quantifies how "easy" the linear separation is. Large margin robust linear encoding. Small margin the probe barely works, suggesting info is nonlinearly encoded or noisy.
Methodology: How to Run a Probing Study
Example calculation: Suppose we probe BERT for POS tags.
- Layer 0(word embeddings): (word identity strongly correlates with POS).
- Layer 6 (middle): (contextualized representations make POS trivial).
- Layer 12 (output): (slight drop; layer focuses on downstream task, not syntax).
Why this pattern? Middle layers balance local syntax (needed for MLM) and global context. Output layers specialize for the pre-training objective, potentially discarding task-irrelevant syntax.
Worked Example1: Probing for Subject-Verb Agreement
Task: Predict whether subject and verb agree in number (singular/plural) from a sentence.
Setup:
- Model: GPT-2 (12 layers).
- Dataset: 10k sentences with labels
{agree, disagree}. - Probe: Logistic regression on activations at the verb token position.
Step 1: Extract representations
For sentence "The cat sleps", extract at layers .
Step 2: Train probe
For layer :
Why this step? Cross-entropy loss measures how well the linear projection separates the classes. L2 penalty ensures stays small, testing if the info is easily linear.
Result: .
Interpretation: Layer 6 representations contain a linear subspace that encodes subject-verb agreement. GPT-2 learned this syntactic rule during language modeling, likely because predicting the verb requires tracking subject number.
Worked Example 2: Probing for Semantic Role (Agent vs. Patient)
Task: In sentences like "The dog chased the cat", identify whether a noun is the agent (doer) or patient (receiver).
Setup:
- Model: BERT.
- Dataset: 5k sentences with semantic role labels.
- Probe:2-layer MLP (hidden size 100) on noun token activations.
Why MLP instead of linear? Semantic roles might require nonlinear combinations of features (e.g., position + grammatical relation + verb semantics).
Step 1: Extract
Step 2: Train MLP probe
Results:
- Layer 8 (MLP), (linear probe).
- Layer 10: (MLP), (linear).
Interpretation: Semantic roles are present in layer 8 but require nonlinear extraction (MLP much better than linear). By layer 10, roles are more linearly accessible (gap narows). This suggests deeper layers "untangle" semantic structure.
Why this step? Comparing linear vs. nonlinear probes tells us how the info is encoded. Linearly separable explicit representation. Nonlinearly separable entangled, requires disentanglement.
Common Mistakes & Steel-Man Fixes
Diagram: Layer-Wise Probing Accuracy Across Tasks
Figure Explanation: The diagram shows how probe accuracy for three tasks (POS tags, dependency parsing, semantic similarity) varies across layers in a 12-layer Transformer. POS tags peak early (layer 4-6), syntax peaks mid-network (layer 6-8), and semantics emerge later (layer 8-12). This visualizes the representational hierarchy: lower layers encode surface form, middle layers encode structure, upper layers encode meaning.
Connections to Other Concepts
- Representation Learning: Probing measures what representations encode.
- Attention Mechanisms: Probing attention weights reveals which tokens influence decisions.
- Fine-tuning vs. Feature Extraction: Probing is feature extraction—we use frozen features for a new task.
- Causal Intervention Methods: Complement to probing; interventions test usage, probing tests presence.
- Adversarial Robustness: Probing adversarial representations reveals which features are robust vs. spurious.
- Disentangled Representations: High linear probe accuracy the feature is disentangled (occupies an independent subspace).
Hidden Feynman Recall Block
Recall Explain Like I'm 12
Imagine you teach a robot to translate English to French. The robot has a "brain" (neural network) with many layers, like floors in a building. You wonder: Does the robot understand grammar? Does it know which words are nouns vs. verbs?
You can't just open up the robot's brain and read it—it's too complicated. Instead, you play a game: You show the robot some sentences and ask, "Tell me the part-of-speech tag for each word." But here's the trick—you freeze the robot's brain (don't let it learn anything new) and only train a tiny helper (the "probe") to guess the tags based on what the robot already learned.
If the helper guesses correctly 95% of the time, the robot's brain already contains the part-of-speech info, stored in a way that's easy to extract. If the helper only guesses 60%, the info is either missing or hidden in a complicated way.
Why does this matter? It tells us what the robot learned and where (which layer). Maybe the first few layers know spelling, the middle layers know grammar, and the last layers know meaning. This helps us trust the robot and fix it when it makes mistakes.
Mnemonic
Active Recall Flashcards
#flashcards/ai-ml
What is a probing classifier? :: A simple supervised model (e.g., logistic regression) trained on frozen pre-trained representations to predict an auxiliary task, measuring whether the representation linearly encodes task-relevant information.
Why do we freeze the pre-trained model during probing?
What does high probe accuracy tell us?
Linear probe gets 65% accuracy, MLP probe gets 88%. What does this imply?
What is the margin in linear separability?
Why regularize the probe during training?
Probing shows layer6 encodes POS tags at 95% accuracy. Does the model use POS tags for its task?
What is the typical layer-wise pattern for linguistic probes in Transformers?
How do you establish a baseline for probe accuracy?
What is the difference between probing and causal intervention?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Probing classifiers ka matlab kya hai? Jab ap kisi bade neural network ko train karte hain (jaise BERT ya GPT), toh woh andar se representations banata hai—matlab har layer mein activations jo model ne seekha hai. Ab sawal yeh hai: Kya model ne grammar seekha? POS tags? Syntax trees? Weights dekhne se pata nahi chalega, bahut complex hain. Toh hum ek trick karte hain: Probing. Hum model ko freeze kar dete hain (koi nayi chez mat seekho), aur uske representations parek chhota sa classifier train karte hain jo specific property predict kare—jaise part-of-speech tags ya dependency relations. Agar yeh chhota classifier achi accuracy deta hai (jaise 95%), toh iska matlab hai ki model ke representations mein woh information already encoded hai, aur woh bhi aise form mein jo easily extract ho sakti hai (linearly separable). Low accuracy matlab ya toh woh information hai hi nahi, ya bahut entangled form mein hai.
Kyun important hai yeh? Interpretability ke liye.Agar ap jaan lo ki model ne kya seekha (syntax, semantics, factual knowledge), kahan seekha (kaun se layers mein), aur kitna easily accessible hai (linear ya nonlinear), toh ap model par trust kar sakte ho, uske mistakes debug kar sakte ho, aur samajh sakte ho ki downstream tasks ke liye kaunsa layer best hoga. Probing essentially ek diagnostic tool hai—jaise doctor test karke dekhta hai ki patient ke body mein kya chal raha hai, waise hi hum model ke andar dekhte hain.
Medical diagnosis jaise example lo: CT scan se doctor ko pata chalta hai ki kaun se organs mein problem hai, lekin woh treatment nahi hai—sirf diagnosis hai. Similarly, probing se pata chalta hai model ne kya encode kiya, lekin yeh nahi bata ki model us info ka use kaise kar raha hai. Usage test karne ke liye causal interventions chahiye (jaise feature ko hata do aur dekho task performance girti hai ya nahi). Toh probing aur causal methods dono milke complete picture dete hain.