Inferensys

Glossary

Online Clustering

Online clustering is a self-supervised learning technique where data points are dynamically assigned to cluster centroids during training to generate supervisory signals without pre-computed labels.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
SELF-SUPERVISED CONTINUAL LEARNING

What is Online Clustering?

Online clustering is a core technique in self-supervised continual learning where data points are dynamically assigned to cluster centroids during training to generate supervisory signals without pre-computed labels.

Online clustering is a machine learning technique where data points are assigned to cluster centroids incrementally during model training, without requiring a pre-computed, static dataset of labels. This method, central to algorithms like SwAV (Swapping Assignments between Views), creates a self-supervised learning objective by enforcing consistency between different augmented views of the same data point, which are assigned to the same cluster code. The cluster assignments and centroids are updated on-the-fly using only the current mini-batch of data, making the process inherently streaming and compatible with continual learning scenarios.

The technique operates by maintaining a set of prototype vectors (cluster centroids) within a projection space. As new data arrives, an online assignment step, often solved via the Sinkhorn-Knopp algorithm for balanced clustering, assigns each sample's embeddings to these prototypes. The model then learns by predicting the cluster assignment of one augmented view from another. This avoids the computational bottleneck of offline clustering on the entire dataset and enables the model to adapt its representations to evolving data distributions, a key requirement for continuous model learning systems.

SELF-SUPERVISED CONTINUAL LEARNING

Core Mechanisms of Online Clustering

Online clustering is a technique used in self-supervised learning where data points are assigned to cluster centroids on-the-fly during training, as seen in methods like SwAV, to create supervisory signals without pre-computed labels.

01

Online Code Assignment

The core mechanism where incoming data points (e.g., augmented image views) are dynamically assigned to a set of trainable prototype vectors, or cluster centroids, within the same training batch. This assignment creates a pseudo-label, or code, for each view. The model then learns by predicting the code of one view from the representation of another, forcing the encoder to learn semantically meaningful features that are consistent across different augmentations. This process is online because assignments are computed on the fly using the current model parameters, not from a fixed, pre-computed dataset of codes.

02

Sinkhorn-Knopp Iterations

A critical optimization step used to compute the code assignments. Directly assigning each sample to its nearest centroid can lead to a degenerate solution where most samples collapse into a few clusters. The Sinkhorn-Knopp algorithm is applied to the similarity matrix between batch samples and prototypes to enforce two constraints:

  • Equipartition: Each prototype is selected roughly equally often within a batch.
  • Uniform Assignment: Each sample is assigned uniformly across the prototypes. This results in a soft, normalized assignment matrix that prevents collapse and ensures all prototypes (clusters) are used productively during training.
03

Swapped Prediction Objective

The specific learning objective that leverages the online codes. Given two augmented views of the same image, the model generates representations and code assignments for each. The SwAV loss is computed by swapping the assignments: the representation from the first view is used to predict the code generated from the second view, and vice versa. This cross-view prediction task is the supervisory signal. The loss function is typically a cross-entropy loss between the predicted code distribution (from a softmax over prototypes) and the swapped target code. This mechanism enforces invariance to the applied augmentations.

04

Prototype Vectors

A small set of learnable parameters, C = {c_1, ..., c_K}, that represent the cluster centroids in the embedding space. These K prototype vectors are jointly optimized with the encoder network parameters. They live in the same dimensionality as the projected features from the encoder's projection head. Their role is to discretize the continuous embedding space into K representative clusters. The quality and separation of these learned prototypes are directly tied to the quality of the learned representations. They act as an implicit, evolving 'codebook' for the dataset.

05

Integration with Continual Learning

Online clustering presents unique challenges and opportunities for continual self-supervised learning. The primary challenge is prototype drift: as new data streams in, the prototype vectors may shift to represent new concepts, potentially causing catastrophic forgetting of patterns from previous data. Mitigation strategies include:

  • Using a memory buffer of past samples for replay during Sinkhorn assignment.
  • Applying regularization to prevent prototypes from moving too far from their previous positions.
  • Dynamic prototype expansion, where new prototypes are added to accommodate emerging clusters in the data stream without disrupting old ones.
06

Advantages Over Contrastive Learning

Online clustering methods like SwAV offer several operational advantages compared to standard contrastive learning frameworks (e.g., SimCLR, MoCo):

  • Eliminates explicit negative pairs: Avoids the need to maintain large dictionaries or use massive batch sizes to gather negatives.
  • Computationally efficient: The Sinkhorn-Knopp scaling is performed on a B x K matrix (batch size x prototypes), which is typically much smaller than the B x B similarity matrix used in contrastive loss.
  • Avoids trivial solutions intrinsically: The equipartition constraint of the Sinkhorn algorithm naturally prevents representation collapse, whereas contrastive methods rely on careful engineering of negative samples to achieve the same effect.
SELF-SUPERVISED CONTINUAL LEARNING

How Online Clustering Works: The SwAV Example

Online clustering is a core technique in self-supervised continual learning, where data is assigned to clusters during training to create supervisory signals without labels.

Online clustering is a technique where data points are dynamically assigned to cluster centroids during model training, creating a supervisory signal without pre-computed labels. In the SwAV (Swapping Assignments between Views) method, this process is applied to different augmented views of the same image. The model learns by predicting the cluster assignment (or 'code') of one view from the representation of another, enforcing consistency and learning robust features in a self-supervised manner.

This online process is computationally efficient as it avoids pre-clustering the entire dataset. The cluster assignments are computed on-the-fly for each mini-batch using a sinkhorn-knopp algorithm, which ensures balanced assignments. By swapping predictions between views, SwAV effectively performs a form of cross-view prediction, making it a powerful method for continuous pre-training on unlabeled data streams without catastrophic forgetting of learned representations.

COMPARISON

Online Clustering vs. Offline Clustering

A comparison of clustering paradigms based on when and how cluster assignments are computed, critical for self-supervised continual learning systems.

FeatureOnline ClusteringOffline Clustering (Traditional)

Data Processing Paradigm

Incremental, stream-based

Batch-based

Cluster Assignment Timing

On-the-fly, during forward/backward pass

Pre-computed, before or separate from model training

Memory Overhead

Low (operates on mini-batches)

High (requires full dataset in memory)

Suitability for Continual Learning

Adaptability to Concept Drift

Primary Use Case

Creating supervisory signals in methods like SwAV

Exploratory data analysis, static dataset organization

Computational Cost per Update

< 1 sec per mini-batch

Minutes to hours for full dataset

Integration with Backpropagation

Tightly coupled (loss computed from assignments)

Decoupled (assignments are fixed inputs)

ONLINE CLUSTERING

Applications and Use Cases

Online clustering, a core technique in self-supervised continual learning, creates supervisory signals from unlabeled data streams by dynamically assigning data to clusters. Its real-time, incremental nature makes it critical for modern AI systems that must adapt without forgetting.

01

Self-Supervised Pre-training (SwAV)

Online clustering is the foundational mechanism behind methods like SwAV (Swapping Assignments between Views). During training, it:

  • Assigns cluster codes to different augmented views of an image on-the-fly.
  • Enforces consistency by predicting the code of one view from another.
  • Eliminates the need for a pre-computed, static dataset of cluster centroids, enabling true online learning from a continuous stream of unlabeled data.
02

Continual Visual Representation Learning

In production systems receiving non-stationary image or video feeds, online clustering enables models to learn incrementally.

  • Dynamic Centroids: Cluster assignments and centroids update with each mini-batch, allowing the model's feature space to evolve with new visual concepts.
  • Mitigates Feature Drift: By providing a stable, clustering-based learning objective, it helps anchor the representation space, reducing catastrophic forgetting compared to training with only a contrastive loss on drifting data.
03

Anomaly Detection in Data Streams

Online clustering operates directly on streaming data, making it ideal for real-time anomaly and novelty detection.

  • On-the-Fly Profiling: Normal behavior is continuously clustered. New data points that fall outside existing clusters or form low-density micro-clusters can be flagged as anomalies.
  • Adapts to Concept Drift: As the definition of 'normal' evolves, the cluster centroids shift accordingly, preventing the system from becoming stale. This is crucial for monitoring IT infrastructure, financial transactions, or sensor networks.
04

Real-Time Customer Segmentation

For e-commerce and digital marketing platforms, online clustering enables dynamic user segmentation without retraining from scratch.

  • Incremental Updates: As new user interaction data (clicks, views, purchases) streams in, user embeddings are reassigned to the most relevant segment in real-time.
  • Hyper-Personalization: Enables live recommendation engines and content delivery systems to adjust to shifting user interests and emerging trends by referencing the current cluster mappings.
05

Foundation Model Data Curation

Before large-scale training, massive, uncurated web-scale datasets must be filtered and organized. Online clustering can:

  • Deduplicate Data: Identify and remove near-duplicate images or text passages by clustering embeddings on-the-fly as data is scraped.
  • Balance Datasets: Monitor the distribution of data across emerging clusters to identify and sample under-represented concepts, improving dataset diversity and model robustness.
06

Edge AI and Federated Learning

In constrained or private environments, online clustering provides a lightweight, local learning signal.

  • On-Device Adaptation: A model on a smartphone or IoT device can use online clustering on local sensor data to personalize its representations without sharing raw data.
  • Federated Continual Learning: Devices in a federated network can perform local online clustering. Only the updated cluster assignments or centroids—not the raw data—need to be shared for global model aggregation, preserving privacy while enabling learning from non-IID data streams.
ONLINE CLUSTERING

Frequently Asked Questions

Online clustering is a core technique in self-supervised continual learning, enabling models to generate supervisory signals from unlabeled data streams. These FAQs address its mechanisms, applications, and relationship to broader machine learning concepts.

Online clustering is an unsupervised learning technique where data points are dynamically assigned to cluster centroids during the training process itself, without requiring a pre-computed, static set of clusters. Unlike traditional offline clustering (like K-Means on a fixed dataset), online clustering updates cluster assignments and centroids incrementally as new data arrives. This makes it essential for continual learning and self-supervised learning frameworks where models must learn from non-stationary data streams. In methods like SwAV (Swapping Assignments between Views), online clustering creates pseudo-labels by assigning different augmented views of an image to prototype vectors, providing a supervisory signal for representation learning without human annotations.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.