Robustness, label quality, and active data acquisition · Robustness, label quality, and active data acquisition · ROB001 · Training method
Projected-gradient adversarial training
Train a predictor against a specified set of input perturbations by combining an inner loss-maximization problem with an outer parameter update. This changes the training objective;
In CodeSplash
A CodeSplash method runs this entry in Python and R. Set it up from the method's page.
- Deep neural network (torch MLP) Verified in Python and R
Do it in CodeSplash Run it on your own data, in Python or R.
- Availability
- Runs in CodeSplash
- Code example
- Complete calculation
- Who ran it
- CodeSplash's run and the reference's record
- CodeSplash's run
- Verified in Python and R through learn.torch_mlp. The reference's example ran in Python and R here, and they agree.
- 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
Train a predictor against a specified set of input perturbations by combining an inner loss-maximization problem with an outer parameter update. This changes the training objective; an adversarial attack alone is an evaluation/search algorithm.
Question / hypotheses
Does minimizing empirical worst-case loss improve held-out performance within the declared perturbation set? This is not a significance test or a universal security guarantee.
Architecture / computational structure
A differentiable predictor sits inside a nested loop. The inner projected-gradient ascent loop changes the input; the outer optimizer changes model weights. A projection enforces the norm ball and legal input range. Random starts and multiple attack restarts probe different local solutions.
Assumptions
The input representation, allowable perturbation, norm, and label-preservation interpretation must be meaningful. A pixel-norm ball does not capture all physical transformations. Inner maximization is approximate for a nonlinear network; the evaluated attack must have access appropriate to the threat model.
Formula / computational definition
Parameters and notation
Learned: predictor weights θ. Input optimization variable: δ, which is not a permanent model weight. Hyperparameters: perturbation radius ε and units, norm, attack steps, step size η, restarts, clean/adversarial loss weighting, optimizer, and regularization. Attack budget and training budget must be reported separately.
Fitting, fine-tuning, and adaptation
Initialize from a baseline or pretrained model, then train on newly generated perturbations rather than a fixed finite attack file. Recheck robustness after ordinary task fine-tuning, quantization, preprocessing changes, or adapters. Changing the threat model requires a fresh evaluation; it cannot be justified by carrying forward an old score.
How to use and calibrate
Keep the final test set locked. Plot clean accuracy and robust accuracy against radius; strengthen attack iterations and restarts to look for score saturation. Compare against independent attack implementations and report failed attacks. Account for inner-loop forward/backward passes in compute and memory.
Example application
Audit an image classifier under a declared normalized L-infinity budget while preserving a clean-data baseline. The small code instead performs projected ascent against one fixed binary linear classifier so the projection is inspectable.
Interpretation / pitfalls
Watch out
Empirical attack failure is not a certificate. Gradient masking, stochastic layers, non-differentiable preprocessing, and a weak attack can inflate apparent robustness. A larger radius can violate the intended label-preservation assumption.
Python and R code examples
Scope: Complete tiny projected-ascent calculation for a fixed logistic classifier; no outer neural training or randomized restart search. 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.
Complete calculation — Complete tiny projected-ascent calculation for a fixed logistic classifier; no outer neural training or randomized restart search. · needs numpy
import numpy as np
x=np.array([.45,.55]); w=np.array([2.,-1.]); b=-.1; eps=.1; a=x.copy()
loss=lambda z: np.logaddexp(0.,-(z@w+b))
for _ in range(8):
p=1/(1+np.exp(-(a@w+b)))
a=a+.04*np.sign((p-1)*w)
a=np.clip(np.minimum(np.maximum(a,x-eps),x+eps),0,1)
assert np.max(np.abs(a-x))<=eps+1e-12 and loss(a)>=loss(x)
print(a,loss(x),loss(a))
Complete calculation — Complete tiny projected-ascent calculation for a fixed logistic classifier; no outer neural training or randomized restart search.
x <- c(.45,.55); w <- c(2,-1); b <- -.1; eps <- .1; a <- x
loss <- function(z) log1p(exp(-(sum(z*w)+b)))
for (i in 1:8) {
p <- plogis(sum(a*w)+b); a <- a+.04*sign((p-1)*w)
a <- pmin(1,pmax(0,pmin(x+eps,pmax(x-eps,a))))
}
stopifnot(max(abs(a-x))<=eps+1e-12,loss(a)>=loss(x))
print(list(adversarial=a,clean_loss=loss(x),adversarial_loss=loss(a)))
Sources
- Source 1arxiv.org
- Source 2github.com
From the CodeSplash reference, entry ROB001.