Skip to content
ExponaBLOG
PRACTICAL AI & MACHINE LEARNING · DAY 075 / 100

Active learning: what every AI & ML developer should know

Label the examples that teach the model most.

Expona Admin8 min read

Active learning: what every AI & ML developer should know

You've built a classifier that works reasonably well on test data, but in production it stumbles on edge cases nobody labeled. Labeling thousands more examples to improve performance is expensive and time-consuming. Active learning offers a smarter path: instead of labeling randomly, we label the examples that teach the model most. This approach has reshaped how teams at scale handle the cost and complexity of training data preparation across e-commerce recommendation systems, fraud detection pipelines, and content moderation platforms.

The core insight behind active learning is that not all examples are equally valuable for training. Some predictions come with high confidence; others sit near the decision boundary where the model is genuinely uncertain. By focusing labeling effort on those uncertain cases, we reach the same accuracy with a fraction of the labels—often 50–70% fewer depending on the task and model architecture.

The loop — Train, find uncertain predictions, label them, retrain

Active learning is fundamentally iterative. We start with a small labeled dataset, train a model, then use that model to identify which unlabeled examples would be most informative to label next. We label those examples, retrain, and repeat.

Here's how the cycle works in practice:

  1. Train a baseline model on your initial labeled set (often just a few hundred examples).
  2. Run inference on your unlabeled pool to generate predictions and uncertainty scores.
  3. Select the top k most uncertain examples for human annotation.
  4. Add those labeled examples to your training set.
  5. Retrain and measure performance gain.
  6. Repeat until you hit your accuracy target or labeling budget is exhausted.

In a real fraud detection workflow, you might start with 500 labeled transactions. After one iteration of active learning, you'd label 200 more examples chosen because the model was most uncertain about them. After retraining, your recall on fraud might jump from 0.72 to 0.81 with just 700 total labels instead of the 2,000 you'd need with random sampling.

The key is that each labeled example feeds back into the selection process. You're not committing to a fixed dataset upfront; instead, you steer labeling dynamically based on model feedback.

Uncertainty sampling — Pick examples near the decision boundary

The most common strategy in active learning is uncertainty sampling. We measure how uncertain the model is about each prediction, then prioritize the most uncertain ones for labeling.

For classification tasks, uncertainty is typically measured in three ways:

  • Least confidence: 1 - max(probabilities). We label the example where the highest predicted class probability is lowest.
  • Margin sampling: max_prob - second_max_prob. We label when the gap between top two classes is narrowest, meaning the model struggles to decide between them.
  • Entropy: -sum(p_i * log(p_i)). We measure the overall spread of probability across classes; high entropy means the model is confused across many classes.

Here's a practical example in Python:

python
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from scipy.stats import entropy

# Train model on labeled data
model = RandomForestClassifier()
model.fit(X_labeled, y_labeled)

# Get predictions on unlabeled pool
proba = model.predict_proba(X_unlabeled)

# Calculate uncertainty metrics
least_confidence = 1 - np.max(proba, axis=1)
margin = np.max(proba, axis=1) - np.partition(proba, -2, axis=1)[:, -2]
ent = entropy(proba.T)

# Pick top 200 most uncertain examples
uncertainty_scores = least_confidence  # or margin, or ent
top_indices = np.argsort(uncertainty_scores)[-200:]

# Send top_indices to labeling team
examples_to_label = X_unlabeled[top_indices]

Why does this work? Examples near the decision boundary are precisely where the model's predictions are least reliable. Labeling those examples provides the most information gain because they directly constrain where the decision boundary should be. A point deep in class A territory tells us little we don't already know; a point sitting ambiguously between A and B forces the model to recalibrate.

In practice, margin sampling often outperforms simple least confidence because it focuses on cases where the model truly can't choose between two similar possibilities—which tend to be more informative than cases where the model is simply confused across many classes equally.

Saves labeling cost — Reach the same accuracy with far fewer labels

The business case for active learning is straightforward: labeling is expensive. Domain experts, crowd workers, or manual review teams cost money and time. The fewer labels you need to hit your target accuracy, the faster you ship and the lower your labeling budget.

Real-world impact varies by task, but we routinely see:

  • Image classification: 40–60% fewer labels to reach the same accuracy as random sampling.
  • Text classification: 50–70% fewer labels, especially for rare classes.
  • Named entity recognition: 30–50% fewer labels, depending on entity rarity.
  • Fraud detection: 45–65% fewer labels when fraud rate is low (because active learning finds the rare positive cases efficiently).

Consider a churn prediction model for a SaaS platform. Random sampling might require 5,000 labeled customer accounts to reach 0.85 F1-score. Active learning with margin sampling could hit the same target with 1,500–2,000 labels. If each label costs $3 in annotator time, that's $9,000 to $15,000 saved—plus faster iteration cycles.

The gains compound over time. Early iterations yield the largest jumps because the initial model's uncertainty is highest. Later iterations show diminishing returns, which is why active learning often plateaus; at that point, switching to random sampling or stopping is rational.

One caveat: the savings depend heavily on your selection strategy and model calibration. A poorly calibrated model (one that outputs overconfident predictions that don't match true probability) will mislabel which examples are actually uncertain, reducing the benefit. Well-calibrated models—trained with proper regularization and validation—extract much more value from active learning.

Tooling — Label Studio supports model-assisted labeling

Building active learning from scratch requires infrastructure: a labeling interface, a way to serve predictions, uncertainty calculation, and feedback loops. Open-source and commercial tools now handle much of this.

Label Studio (open source, supported by Heartex) is a popular choice for teams. It integrates model predictions directly into the labeling interface—showing annotators the model's guess so they can confirm, correct, or override it. More importantly, it can prioritize which examples show up in the queue based on model confidence.

Here's a simplified flow using Label Studio's ML backend:

python
from label_studio_ml.model import LabelStudioMLBase

class ActiveLearningBackend(LabelStudioMLBase):
    def predict(self, tasks, **kwargs):
        # Get predictions from your model
        predictions = self.model.predict(tasks)
        proba = self.model.predict_proba(tasks)
        
        # Calculate uncertainty
        uncertainty = 1 - np.max(proba, axis=1)
        
        # Return predictions + confidence scores
        results = []
        for task, pred, conf in zip(tasks, predictions, uncertainty):
            results.append({
                'id': task['id'],
                'value': {'choices': [self.id_to_label[pred]]},
                'confidence': float(conf),  # Label Studio can sort by this
                'model_version': self.model_version
            })
        return results

Label Studio stores these confidence scores. You can configure the interface to show examples with lowest confidence first, effectively implementing uncertainty sampling without writing your own backend. The annotator sees "Model confidence: 62%" and knows the model was uncertain.

Other tools to consider:

  • Prodigy (Explosion AI): Tightly integrated with spaCy NLP models; strong for text and NER tasks.
  • Argilla (formerly Rubrix): Designed for NLP; tracks model predictions and annotations side-by-side.
  • Custom pipelines: For teams with strong ML infrastructure, building on Kafka, PostgreSQL, and a custom Flask backend is common in trading and e-commerce platforms.

The key is that your labeling tool and your training pipeline must communicate. Annotators need to see model predictions; your training loop needs to fetch newly labeled examples and measure which uncertainty metrics correlate with annotation quality.

Common mistakes

Relying on uncalibrated model confidence. If your neural network outputs probabilities that don't reflect true uncertainty (common with deep learning), active learning will pick the wrong examples. Always validate model calibration on a held-out set before deploying active learning. Tools like sklearn.calibration.calibration_curve help diagnose this.

Labeling in large batches without retraining. Some teams label 1,000 examples selected by active learning, then retrain once. It's better to retrain every 100–200 labels and recalculate uncertainty. The model's view of what's uncertain changes as it improves, and you want to follow that shift.

Ignoring label quality. Active learning amplifies annotator errors. If your most uncertain example gets mislabeled, the model learns a bad boundary. Implement consensus labeling (multiple annotators per example) or quality checks on high-uncertainty selections.

Assuming one uncertainty metric fits all classes. In imbalanced datasets (fraud, rare diseases), margin sampling might ignore the minority class because it's already low-confidence on everything. Consider stratified active learning or query-by-committee (ensemble disagreement) for better minority class coverage.

Not monitoring annotation distribution. Over many iterations, active learning can push annotators toward a narrow slice of your data distribution. Set up alerts if certain subgroups stop appearing in the selection queue; you may need to periodically add random examples to maintain diversity.

Key takeaways

  • Active learning reduces labeling cost by 40–70% on many tasks by focusing on uncertain predictions near the decision boundary.
  • The core loop is train → find uncertain examples → label them → retrain. Repeat until you hit your accuracy target or labeling budget.
  • Uncertainty sampling (least confidence, margin, entropy) is the most practical strategy; margin sampling often outperforms simpler metrics because it targets genuinely ambiguous cases.
  • Use calibrated models; an uncalibrated network will pick the wrong examples and waste labeling budget.
  • Tools like Label Studio integrate model predictions into the annotation interface, making uncertainty sampling easy to deploy. Custom pipelines work well for teams with mature ML infrastructure.
  • Retrain frequently (every 100–200 new labels), monitor annotation quality, and guard against distribution drift in which examples get selected.
  • Active learning is most valuable early in a project (when your dataset is small and model uncertainty is high) and on imbalanced classification tasks where rare examples are hard to find.
ShareXLinkedInReddit

Found this useful? Support the writing.

Buy me a coffee
Written by
Expona Admin
Site administrator

Comments

Loading comments…

Leave a comment

Comments are reviewed before they appear. Be kind and stay on topic.

Related articles