{'fraction_non_alphanumeric': 0.05827987387191475, 'fraction_numerical': 0.017070783951288464, 'mean_word_length': 4.121380846325167, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Notes on Margin Training and Margin p-Values for Deep Neural Network Classifiers

We provide a new local class-purity theorem for Lipschitz continuous DNN classifiers. In addition, we discuss how to achieve classification margin for training samples. Finally, we describe how to compute margin p-values for test samples.


I. INTRODUCTION
Robust DNNs have been proposed to defeat bounded-perturbation test-time evasion attacks -i.e., small perturbations added to nominal test samples so that their class decision changes. One family of approaches controls Lipschitz-continuity parameter and targets training-set classification margin. Estimation and engineering of the Lipschitz parameter for a DNN is discussed in, e.g., [11], [1], [2], [12], [14], [6], [4]. How to engineer class purity (class decision consistency) in an convex neighborhood (open ball) of a certain size about every training samples is addressed in [12], [7]. In the following, we give an alternative local class purity result. Also, we show how to achieve classification margin on training samples by choice of a simple "dual" training objective, cf., (8) and (9). We numerically show how margin-based training can result in reduced accuracy (by overfitting the training set). Finally, we define a p-value associated with classification margin.

II. MARGIN IN DNN CLASSIFIERS
Consider the DNN f : R n → (R + ) C where C is the number of classes. Further suppose that for an input pattern x ∈ R n to the DNN, the class decision iŝ where f i is the ith component of the C-vector f . That is, we have defined a class-discriminant output layer of the DNN. Here assume that a class for x is chosen arbitrarily among those that tie for the maximum. In the following, we assume that the functions f i are rectified: Define the margin of x as Now suppose the ∞ / 2 Lipschitz continuity parameter L ∞ for f , i.e., the smallest L ∞ > 0 satisfying is estimated. Note that we have used two different norms in this definition. Now consider samples in a open 2 ball centered at x, i.e., The following is a locally consistent (robust) classification result is an example of Lipschitz margin [12].
If we instead write |f i (y)| ∞ − |f i (x)| ∞ in the triangle inequality above and then replaceĉ(x) by any i =ĉ(x), we get that So, by (4) and (5), < fĉ (x) (y) Theorem 2.1 is similar to Proposition 4.1 of [12]. Let the 2-norm Lipschitz parameter of f be L 2 , i.e., using the 2-norm on both sides of (3). Since |z| ∞ ≤ |z| 2 for all z, L 2 ≥ L ∞ . Without assuming f is rectified as (1), [12] shows that y is assigned the same class as [12]) may or may not be larger than 2L ∞ (Theorem 2.1). On the other hand, if the right-hand-side of (3) is changed to the ∞ norm, then using |z| 2 ≤ n|z| ∞ for all z, and arguing as for Theorem 2.1) leads to a weaker result than Prop. 4.1 of [12] (especially when n 1).

III. MARGIN TRAINING
Robust training is surveyed in [13]. Lipschitz margin training to achieve a class-pure convex neighborhood (open ball) of prescribed size about every training sample is discussed in [12], combining margin training (2) and Lipschitz continuity parameter control. (Also see e.g. [2] for Lipschitz parameter control and the approach for bounding margin gradient of [9].) [7] relaxes the constraints of ReLU based classifiers toward this same objective (assuming ReLU neurons with bounded outputs). For a given classifier, the approach of [7] can also check class purity of a prescribed-size convex neighborhood of test samples; using this method to detect small-perturbation test-time evasion attacks may have a significant false-positive rate. Generally, these methods cannot certify a test sample is not test-time evasive if the associated perturbation is larger than the prescribed neighborhood size, and they may be associated with reduction in classification accuracy [12], [9].
We focus herein on just achieving a prescribed margin for training samples (2). Let θ represent the DNN parameters. Let T represent the training dataset and let c(x) for any x ∈ T be the ground truth class of x. The following is easily generalized to sample-dependent margins (µ(x) > 0). [12] suggests to add the margin "to all elements in logits except for the index corresponding to" c(x). For example, train the DNN by finding: For a softmax example, one could train the DNN using the modified cross-entropy loss 1 : These DNN objectives do not guarantee the margins for all training samples will be met. Alternatively, one can perform (dual) optimization of the weighted margin constraints, e.g., or just where the DNN mappings f i obviously depend on the DNN parameters θ, and the weights λ x ≥ 0 ∀x ∈ T . For hyperparameter δ > 1, training can proceed simply as: 0 Select initially equal λ x > 0, say λ x = 1 ∀x ∈ T . 1 Optimize over θ (train the DNN).
2 If all margin constraints are satisfied then stop.
3 For all x ∈ T : if margin constraint x is not satisfied then λ x → δλ x . 4 Go to step 1.
Again, the parameters of the previous DNN could initialize the training of the next, and an initial DNN can be trained instead by using a logit or cross-entropy loss objective, as above. There are many other variations including also decreasing λ x when the x-constraint is satisfied, or additively (rather than exponentially) increasing λ x when they are not, and changing λ x in a way that depends on the degree of the corresponding margin violation. Given a thus margin trained classifier, one could estimate its Lipschitz continuity parameter, e.g., [14], [6], [4], and apply Theorem 2.1 or Proposition 4.1 of [12] to determine a region of class purity around each training sample.

IV. SOME NUMERICAL RESULTS FOR CLASSIFICATION MARGIN
In this section, we give an example using loss function (9). Training was performed on CIFAR-10 (50000 training samples and 10000 test/held-out samples) using the ResNet-18 DNN (ReLU activations are not used after the fully connected layer). The training was performed for 200 epochs using a batch size 32 and learning rate 10 −4 . The results for margins µ = 50 and µ = 150 are given in Figures 1,2 and Table I.
All training-sample margins were achieved with one training pass using initial λ x = 1 for all x ∈ T ; see Figures 1(a) and 2(a). Figures 1(b) and 2(b) show the margins of the dataset held out from training, i.e., to compute the margins, the true class label was used. Here, one can clearly see that many test samples have margins less than µ and some are misclassified (negative margins), cf., Table I. Figures  1(c) and 2(c) show the margins based on the class decisions of the classifiers themselves, as would be the case for unlabelled test samples (so all measured margins are not negative). The held-out set and test set are the same. Finally, Figures 1(d) and 2(d) show the margins of FGSM [5] adversarial samples with parameter/strength ε = 0.1 created using a surrogate ResNet-18 DNN of the same structure trained using standard cross-entropy loss (all such samples were used, including those based on the 13.3% of test samples that were misclassified).
In Table I, we show the accuracy of the classifiers, including a baseline classifier trained using the same dataset and ResNet-18 DNN structure but with standard cross-entropy loss objective. As Figures 1(d) and 2(d), the accuracy performance reported here is for FGSM adversarial samples that were crafted assuming the attacker knows the baseline DNN trained by cross-entropy loss. These attacks are transferred to the margin-trained classifiers.

V. LOW-MARGIN ATYPICALITY OF TEST SAMPLES
Given an arbitrary DNN f : R n → (R + ) C , let T κ be the (clean) training samples of class κ ∈ {1, 2, ..., C}, i.e., ∀x ∈ T κ ,ĉ(x) = c(x) = κ. Recall (2) and suppose a Gaussian Mixture Model (GMM) is learned using the log-margins of the training dataset {log µ f (x) : x ∈ T κ } by EM [3] using BIC model order control [10] as, e.g., [8]. (Instead of margin (2), one could use an estimate the radius of the largest 2 ball of class purity about each training and test sample, e.g., directly [7] or via estimated Lipschitz constant as discussed above.) Let the resulting GMM parameters be {w i , m i , σ i } Iκ k=1 , where I κ ≤ |T κ | is the number of components, the w i ≥ 0 are their weights ( Iκ i=1 w i = 1), the m i are their means, and the σ i > 0 are their standard deviations. So, we can simply compute the margin p-value of any test sample x, where F is the standard normal c.d.f. That is, π f (x) is the probability that a randomly chosen sample from the same distribution as that of the training samples has smaller margin than the test sample x. So, one can can compare π f (x) to a threshold to detect whether a test sample x has abnormally small classification margin. The example of margin-trained DNN of Figures 1(a) and 2(a) has a single component for the entire training set T = C κ=1 T κ . In an unsupervised fashion, the threshold criterion could be a bound on false positives based on the training set. Alternatively, the threshold could be set by using a clean set of labelled samples that were held out from (not used for) training and consider both false-positive and false-negative performance.