Most annotation budgets are spent on the classes a model already handles well. If 92% of your images contain cars and 0.4% contain wheelchairs, labeling another random batch of 10,000 images gets you about 40 new wheelchair examples and 9,200 more cars you didn't need. This post covers practical ways to point labeling effort at the rare classes that actually limit model performance, with code you can run on your own unlabeled pool.
Why random sampling fails for long-tail classes
Random sampling is unbiased, which is exactly the problem. It reproduces the class distribution of your raw data, so rare classes stay rare in the labeled set. The model then sees too few examples to learn them, and your per-class recall on the tail stays low no matter how many total labels you buy.
A quick sanity check before any new labeling round: compute per-class counts in your current labeled set and per-class recall on a held-out set. Any class with fewer than a few hundred instances and recall well below the average is a candidate for targeted sampling.
Strategy 1: Model-guided pre-filtering
Run your current model over the unlabeled pool and keep items where the model predicts a rare class with any meaningful confidence. Precision will be low, but that is fine. You are not trusting these predictions, you are using them to raise the base rate of rare classes in what gets sent to annotators.
import numpy as np def prefilter_for_rare(probs, rare_class_ids, threshold=0.15, max_items=2000): """ probs: array of shape (n_items, n_classes) with model scores rare_class_ids: list of class indices to target Returns indices of items to send for labeling, highest rare-score first. """ rare_scores = probs[:, rare_class_ids].max(axis=1) candidates = np.where(rare_scores >= threshold)[0] order = candidates[np.argsort(-rare_scores[candidates])] return order[:max_items] # Example with fake scores rng = np.random.default_rng(0) probs = rng.dirichlet(np.ones(10) * 0.3, size=50000) picked = prefilter_for_rare(probs, rare_class_ids=[7, 9]) print(len(picked), "items selected") A low threshold such as 0.1 to 0.2 casts a wide net. Measure the hit rate on the first batch you label and adjust.
Strategy 2: Embedding nearest neighbors
If you have even 20 confirmed examples of a rare class, you can find more. Embed the whole pool with any reasonable image or text encoder, then search for nearest neighbors of the known examples.
from sklearn.neighbors import NearestNeighbors def expand_from_seeds(pool_emb, seed_emb, k=50): nn = NearestNeighbors(n_neighbors=k, metric="cosine").fit(pool_emb) _, idx = nn.kneighbors(seed_emb) return np.unique(idx.ravel()) This works well for visually distinctive classes such as specific equipment, signage or defect types. It works less well for classes defined by context, such as "pedestrian about to cross", where neighbors in embedding space often look similar but mean something different.
Strategy 3: Metadata and source filters
Often the cheapest filter is not a model at all. Rare classes cluster in particular cameras, geographies, times of day or customer segments. Night-time footage contains more headlight glare cases. Hospital-adjacent street cameras contain more wheelchairs and gurneys. Support tickets from one product line contain most of the refund-fraud language. Ask the people who collected the data where the rare cases come from before you build anything clever.
Keep a random slice anyway
Targeted sampling skews the labeled distribution, and that has two costs. First, your evaluation set no longer represents production. Second, the model can learn the sampling bias, for example predicting "wheelchair" more often on night footage simply because that is where the targeted examples came from.
The fix is simple: reserve 10 to 20% of every labeling batch for uniformly random items, and build your evaluation set only from random samples. Track per-class metrics on that random set so you can see whether targeted labeling actually moved recall on the tail.
Tell annotators what changed
When a batch is enriched for rare classes, annotators see those classes far more often than usual. That is good for throughput but can shift their judgment. A reviewer who has seen 300 wheelchairs in an hour may start labeling mobility scooters and strollers as wheelchairs too. Three things help:
- Add clear positive and negative examples of each rare class to the guideline, especially lookalikes.
- Mix a few random items into enriched batches so the task does not become "find the rare thing".
- Check agreement on rare classes separately. Overall agreement can look healthy while agreement on a 0.4% class is poor.
Platforms such as Taskmonk let you route enriched batches to a specific annotator pool and run a separate review step for them, which makes this easier to manage at scale. Its image annotation workflows include review stages, so rare-class labels can get a second check without slowing down the common classes.
A simple loop that works
- Measure per-class counts and recall on a random holdout.
- Pick the two or three tail classes that matter most to the product.
- Pull candidates with model scores, nearest neighbors or metadata.
- Label them in a batch that also includes a random slice.
- Retrain, re-measure on the same random holdout and repeat.
Most teams find that two or three rounds of targeted labeling move tail recall more than doubling the size of a randomly sampled dataset, at a fraction of the cost.
