1. Deep Clustering¶
Motivation¶
PCA is a classical linear method for dimensionality reduction. For high-dimensional data with complicated nonlinear structure (images, text, speech), it is often beneficial to first learn a nonlinear feature representation before clustering.
Deep clustering combines deep representation learning with clustering. The main idea is to learn a representation in which clustering becomes easier.
Two-Stage Deep Clustering¶
Approach:
Learn a low-dimensional representation with an autoencoder:
Apply a classical clustering algorithm (e.g., K-means) to the learned features.
The K-means objective in the embedded space:
subject to and .
Advantages:
Easy to implement
Can use any representation learner and any clustering algorithm
Limitation: The learned representation is not directly optimized for clustering.
Joint Optimization: Deep Embedded Clustering (DEC)¶
DEC learns the feature extractor and cluster assignments simultaneously.
Soft assignment. DEC first maps each sample into a latent feature and maintains cluster centers . The soft assignment of sample to cluster is:
where is a parameter (often set to 1). This is a Student’s t-distribution kernel measuring similarity.
Target distribution. DEC does not directly optimize . Instead it constructs an auxiliary target distribution from :
This target distribution:
Sharpens confident assignments (squaring emphasizes high probabilities)
Reduces the influence of very large clusters through normalization by
Objective. DEC minimizes the KL divergence between the target distribution and the soft assignments :
Minimizing this with respect to and refines both the representation and the clustering structure simultaneously.
DEC Algorithm:
Initialization: Train an autoencoder to obtain an initial encoder . Compute latent features and initialize cluster centers by K-means.
Iterative refinement: Repeat until convergence:
Compute soft assignments
Construct target distribution
Update and by minimizing
Final clustering: Assign each sample to
2. Contrastive Learning¶
Motivation¶
Supervised learning requires massive amounts of labeled data, which is expensive to collect. Unlabeled data is often vast. The goal of self-supervised learning is to learn a general-purpose feature extractor from unlabeled data without human annotations. These learned features can then be used for downstream tasks with only a small number of labeled examples.
Key Idea¶
The main principle of contrastive learning is:
Similar examples should have similar representations.
To achieve this:
Bring together representations of similar examples (positive pairs)
Push apart representations of dissimilar examples (negative examples)
Constructing Positive and Negative Pairs¶
In unsupervised contrastive learning, we do not have labels. Instead, we construct positive pairs from the same image using data augmentation:
where is an augmented view of . All other images in the batch are treated as negative examples.
Common augmentations include random cropping, color distortion, Gaussian blur, and horizontal flipping.
Triplet Loss¶
A basic contrastive loss is the triplet loss. For each anchor , we have:
A positive example (similar to )
A negative example (dissimilar to )
where is a margin parameter. The loss encourages the anchor to be closer to the positive than to the negative by at least .
Compared with an autoencoder, contrastive learning wants similar/dissimilar data to have similar/dissimilar representations, rather than pixel-wise reconstruction.
N-way Contrastive Loss¶
Triplet loss considers one positive and one negative at a time. A more general approach treats contrastive learning as an -way classification problem: for an anchor representation , identify its positive pair among many negatives .
where is a distance function (e.g., cosine distance).
SimCLR Algorithm¶
SimCLR is a simple framework for contrastive learning of visual representations.
Algorithm:
Sample a minibatch of examples
Augment each example twice to get
Embed examples with to get
Compute pairwise cosine distances:
Update with respect to the -way loss:
The key idea is to compare augmentations of the data itself, treating the two augmented views of the same image as a positive pair and all other pairs as negatives.