Semi-supervised & Self-supervised Learning
451 words
2 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Semi-supervised & Self-supervised Learning ## 🎯 Learning Objectives - Explain why unlabeled data helps learning - Implement self-training and pseudo-labeling - Understand label propagation algorithms - Apply consistency regularization ## 📖 Core Content ### 7.1 Intuition: Using Unlabeled Data as a Free Lunch Labe...

Semi-supervised & Self-supervised Learning
🎯 Learning Objectives
- Explain why unlabeled data helps learning
- Implement self-training and pseudo-labeling
- Understand label propagation algorithms
- Apply consistency regularization
📖 Core Content
7.1 Intuition: Using Unlabeled Data as a Free Lunch
Labeled data is expensive (requires human annotation). Unlabeled data is abundant. Semi-supervised learning uses the structure of unlabeled data to improve models trained on limited labeled data. It's like a student who reads the textbook (unlabeled) to supplement a few solved examples (labeled).
7.2 Self-Training (Pseudo-Labeling)
- Train a model on labeled data
- Predict on unlabeled data (pseudo-labels)
- Add high-confidence predictions to training set
- Retrain the model
- Repeat until convergence
7.3 Label Propagation
Build a similarity graph between all points. Propagate labels from labeled to unlabeled points through the graph. Points close to labeled points get similar labels.
7.4 Consistency Regularization
Encourage the model to produce consistent predictions under small perturbations:
Where ϵ is noise. The model must predict the same class for a data point and its augmented version.
python# runnable import numpy as np from sklearn.semi_supervised import SelfTrainingClassifier, LabelPropagation from sklearn.ensemble import RandomForestClassifier from sklearn.datasets import load_iris iris = load_iris() X, y = iris.data, iris.target # Simulate: only 10% labeled np.random.seed(42) n_labels = 15 labeled_idx = np.random.choice(len(X), n_labels, replace=False) y_mixed = np.full_like(y, -1) # -1 = unlabeled y_mixed[labeled_idx] = y[labeled_idx] # Self-training with Random Forest base_clf = RandomForestClassifier(random_state=42) self_training = SelfTrainingClassifier(base_clf, threshold=0.8, verbose=False) self_training.fit(X, y_mixed) print(f"Self-training accuracy: {self_training.score(X, y):.3f}") # Compare with supervised only (trained on labeled subset only) supervised = RandomForestClassifier(random_state=42) supervised.fit(X[labeled_idx], y[labeled_idx]) print(f"Supervised only accuracy: {supervised.score(X, y):.3f}")
📝 Practice Questions
Q1: When does semi-supervised learning help most?When: (1) labeled data is scarce, (2) unlabeled data is abundant, (3) the data has inherent cluster structure (classes are separated). It's less helpful when classes overlap heavily or when the labeled set is already representative. Q2: What's the risk of self-training?Confirmation bias: Early mistakes get reinforced. If the model confidently mislabels an unlabeled point, that error propagates in subsequent iterations. Mitigations: use high-confidence thresholds, ensemble methods, or mix labels. Q3: How does label propagation work algorithmically?
- Build a k-NN graph connecting all points (edge weights = similarity)
- Initialize: labeled points have one-hot label vectors; unlabeled = zeros
- Iteratively update: Ft+1=αPFt+(1−α)Y, where P is the transition matrix
- Fixed labeled points at each iteration
- Converges to a harmonic solution Join Discord PreviousAnomaly DetectionNextML System Design