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.
Glossary
Online Clustering

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.
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.
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.
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.
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.
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.
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.
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.
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 Kmatrix (batch size x prototypes), which is typically much smaller than theB x Bsimilarity 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.
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.
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.
| Feature | Online Clustering | Offline 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) |
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.
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.
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.
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.
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.
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.
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.
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.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Online clustering is a core technique within self-supervised continual learning. The following terms define the key concepts, algorithms, and evaluation methods that enable models to learn from unlabeled data streams.
SwAV (Swapping Assignments between Views)
SwAV is a seminal self-supervised learning method that directly utilizes online clustering. It works by:
- Creating multiple augmented views of an image.
- Assigning each view to a set of trainable prototype vectors (cluster centroids) via an online clustering step.
- Learning by predicting the cluster assignment (code) of one view from the representation of another view. This creates a supervisory signal without pre-computed labels, making it highly efficient and scalable for continual pre-training on data streams.
Self-Supervised Learning (SSL)
Self-supervised learning is the overarching paradigm where models generate their own supervisory signals from unlabeled data. This is foundational for continual learning on streams where labels are scarce. Core techniques include:
- Pretext tasks like predicting image rotation or solving jigsaw puzzles.
- Contrastive learning, which learns by comparing data points.
- Online clustering, used in methods like SwAV to create pseudo-labels on-the-fly. SSL provides the raw, general-purpose representations that can be continually adapted to new data.
Continual Self-Supervised Learning
This is the specific problem setting where online clustering operates. It involves training a model on a non-stationary, potentially infinite stream of unlabeled data. Key challenges include:
- Learning new visual concepts or data distributions over time.
- Avoiding catastrophic forgetting of previously learned representations.
- Managing feature drift, where the statistical properties of embeddings change detrimentally. Algorithms must update cluster assignments and model parameters incrementally without access to past data.
Non-Contrastive Learning
Non-contrastive learning is a category of SSL methods that, like online clustering, avoids the need for explicit negative samples. This is computationally advantageous for continual learning. Key methods include:
- BYOL: Uses a momentum encoder and predictor to learn from different views.
- Barlow Twins: Reduces redundancy between embedding dimensions.
- VICReg: Applies variance, invariance, and covariance constraints. While online clustering (SwAV) uses a form of contrast against other clusters, these methods show that stable learning can be achieved through architectural asymmetry and regularization alone.
Pretext Task
A pretext task is an artificially constructed learning objective used to train models on unlabeled data. It is an alternative supervisory signal to online clustering. Common examples include:
- Masked Autoencoding: Reconstructing randomly masked portions of an input (used in MAE).
- Rotation Prediction: Predicting the applied rotation angle of an image.
- Jigsaw Puzzle Solving: Reassembling shuffled image patches. In continual learning, designing pretext tasks that remain valid across a shifting data distribution is a significant challenge, whereas online clustering adapts its targets (the centroids) dynamically.
Linear Evaluation Protocol
The linear evaluation protocol is the standard benchmark for assessing the quality of representations learned via online clustering or other SSL methods. The process is:
- A model is pretrained on a large unlabeled dataset (e.g., using SwAV).
- The learned encoder is frozen.
- A single linear classifier (e.g., a logistic regression layer) is trained on top of the frozen features using a labeled dataset (e.g., ImageNet). The final classification accuracy measures how transferable and semantically meaningful the learned representations are, which is critical for evaluating continual learning performance.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us