Skip to content

Robustness, label quality, and active data acquisition · Robustness, label quality, and active data acquisition · ROB008 · Algorithm

BADGE batch active learning

Choose an unlabeled batch using both predictive uncertainty and diversity in a hypothetical last-layer gradient representation.

Runs in CodeSplash (Predict) Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash feature runs this entry inside the app, not as a Python and R method. There's no Set up button; open it where the label says.

Do it in CodeSplash Run it on your own data in the app: Predict run page › Label issues tab › Acquire labels (rows missing the target; gradient embeddings on the input features, k-means++ batch).

Availability
Runs in CodeSplash (Predict)
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
The reference's example ran here in one language.
The reference's record
Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Choose an unlabeled batch using both predictive uncertainty and diversity in a hypothetical last-layer gradient representation.

Question / hypotheses

Which examples should receive the next labeling budget? This is an acquisition rule; evaluation requires a separate learning-curve experiment and independent test set.

Architecture / computational structure

A classifier supplies penultimate features and class probabilities. Its predicted class acts as a hypothetical label to construct a last-layer gradient embedding. A k-means++-style diversity sampler chooses a batch in that embedding space.

Assumptions

A meaningful labeled seed set, representative unlabeled pool, and usable annotation process are needed. The final linear softmax layer and the gradient representation must be defined. Pool acquisition can over-select outliers or ambiguous cases when uncertainty is not useful.

Formula / computational definition

gx=(pθ(⋅∣x)−ey^x)⊗hθ(x),y^x=arg⁡max⁡cpθ(c∣x),Pr⁡(x next)∝min⁡s∈S∥gx−gs∥22.g_x=(p_\theta(\cdot\mid x)-e_{\widehat y_x})\otimes h_\theta(x),\quad \widehat y_x=\arg\max_c p_\theta(c\mid x),\qquad \Pr(x\text{ next})\propto \min_{s\in S}\|g_x-g_s\|_2^2.

Parameters and notation

Learned: current classifier. Acquisition choices: label batch/budget, seed set, pool filters, feature layer, retraining strategy and random seed. The method does not require a manually weighted uncertainty/diversity mixture, but the overall experiment still has design choices and model hyperparameters.

Fitting, fine-tuning, and adaptation

After labels arrive, retrain or warm-start under a prespecified rule and rebuild embeddings. Keep annotation cost and training compute explicit. A new domain may require different pool filtering and query units, such as a patient or whole document instead of individual correlated rows.

How to use and calibrate

Plot task performance against total labels and annotation time over several acquisition seeds. Compare random selection with the same starting labels, annotation access, and training budget. Freeze the independent evaluation set across rounds.

Example application

Select a batch of unlabeled documents for expert categorization while avoiding a batch composed entirely of near duplicates.

Interpretation / pitfalls

Watch out

Acquired labels are not a random population sample. Adaptive training curves can be biased by repeated test inspection. High gradient norm can identify noise; difficult cases may be costly to label. The snippet computes embeddings and distances, not the full acquisition/training loop.

Python and R code examples

Scope: Exact hypothetical last-layer gradient embeddings and diversity distances. Python: NumPy; R: base R.

Validation: Python executed successfully on the supplied fixture; R reviewed but not executed.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Exact hypothetical last-layer gradient embeddings and diversity distances. Python: NumPy; R: base R. · needs numpy

import numpy as np
H=np.array([[1.,0.],[0.,1.],[1.,1.]])
P=np.array([[.9,.1],[.55,.45],[.6,.4]])
Y=np.eye(2)[P.argmax(1)]; G=np.einsum('nc,nd->ncd',P-Y,H).reshape(3,-1)
D=((G[:,None,:]-G[None,:,:])**2).sum(-1)
assert np.allclose(np.diag(D),0) and np.allclose(D,D.T)
print(G); print(D)
R

Complete calculation — Exact hypothetical last-layer gradient embeddings and diversity distances. Python: NumPy; R: base R.

H <- rbind(c(1,0),c(0,1),c(1,1)); P <- rbind(c(.9,.1),c(.55,.45),c(.6,.4))
Y <- diag(2)[max.col(P,ties.method="first"),,drop=FALSE]
G <- t(vapply(1:3,function(i) as.vector(t(outer(P[i,]-Y[i,],H[i,]))),numeric(4)))
D <- as.matrix(dist(G))^2
stopifnot(all(abs(diag(D))<1e-12),isTRUE(all.equal(D,t(D))))
print(G);print(D)

Sources

From the CodeSplash reference, entry ROB008.