A learning machine is prone to be attacked by adversarial examples contaminated by perturbations. Adversarial training (AT) is developed to build a defense model against adversarial attacks. Most of previous works were conducted in supervised setting. To release the demand of data labeling, self-supervised learning is required to carry out the self-supervised AT. This study presents a contrastive view in AT where a self-supervised AT is developed by enhancing instance discrimination based on contrastive learning (CL). The connection between AT and self-supervised learning is used to consolidate self-supervised AT by merging a classification perspective in contrastive objective. This study analyzes two potential sources of mismatch in existing CL and AT pipelines, namely, the implicit class definition in instance discrimination and the distributional discrepancy induced by different augmentation strategies. Based on this analysis, this study develops a self-supervised AT framework that integrates a classification perspective into CL. A self-supervised AT with a contrastive view is performed to calculate the perturbed image embeddings to train a robust classifier. The contrastive objective is also reformulated to train a self-supervised sentence encoder as the defense model. The experiments on image and text representations for adversarial robustness show that this method improves the previous unsupervised methods, and even surpasses some other supervised methods.
1. Introduction
Deep neural networks are vulnerable in the presence of adversarial examples. In light of this vulnerability, an emerging research trend is to build a defense model based on adversarial training (AT) (Madry et al., 2018). The adversarial learning objective is typically formulated as a minimax optimization problem (Lio et al., 2022) where the additive perturbations to input data are first estimated by maximizing the loss via gradient ascent, and then the model parameters are trained by minimizing the loss with gradient descent by using AT examples. Such a two-stage training process has been implemented for a variety of downstream tasks in computer vision and natural language processing. The resulting models generally improve the adversarial robustness, but likely degrade the performance on clean data. In Zhu et al. (2020) and Pan et al. (2022), the robustness was even generalized to clean data. For text representation, the resulting model becomes noise-invariant by adding the worst-case perturbations onto word embeddings during training (Chien et al., 2025). The adversarial instances with the perturbed data in embedding space are used to improve model generalization. However, most existing AT methods (Shafahi et al., 2019; Zhang et al., 2019; Wong et al., 2020) were developed under a supervised setting where the labels of training data were required (Li et al., 2023). It is challenging to carry out a practical solution to self-supervised AT. Previously, there have been very few works dedicated to self-supervised AT in image representation, and there has been limited exploration of self-supervised AT for text representation. This paper presents a contrastive view in self-supervised AT by deliberating the perspective of instance discrimination.
Contrastive learning (CL) (Li et al., 2022; Chien and Chen, 2026) is seen as a recent breakthrough in modern machine learning. CL has been advanced to extract vital information which is feasible to upgrade the learning performance. State-of-the-art (SOTA) results have been achieved in numerous applications. The learning process is motivated from the task of instance discrimination (Wu et al., 2018) where each data instance is viewed as an individual class, and a neural encoder is learned to calculate the features which are discriminative among different instances or self-defined classes. It is obvious that such a CL task is essentially implemented for unsupervised learning but implicitly connected to a classification problem in supervised learning (SL). The contrastive perspective is fulfilled for self-supervised learning. CL has its fundamentals originated from metric learning and information theory. In Chen et al. (2020), a simple framework for CL of visual representation (SimCLR) was proposed to upgrade learning an image classifier which was comparable with that based on SL. CL was then extended to enable a significant performance in text representation. In Gao et al. (2021), a simple contrastive sentence embedding (SimCSE) was exploited to train a contrastive sentence encoder, which obtained desirable results on unsupervised or self-supervised learning in various tasks (Sun et al., 2025; Tu et al., 2024).
This study revisits the connection between CL and supervised classification, and leverages this connection to design a self-supervised AT framework. While contrastive objectives such as the information noise-contrastive estimation (InfoNCE) or the normalized temperature-scaled cross entropy (CE) (NT-Xent) in SimCLR can be interpreted as implicit classification over instances, the existing formulations treat each sample differently across views, which may lead to inconsistencies when combined with AT. We explicitly reformulate the instance discrimination as a batch-wise classification problem and integrate it with adversarial optimization. This perspective provides (i) a unified view bridging CL and AT, and (ii) a practical framework that improves robustness while maintaining computational efficiency.
The remaining of this paper is organized as follows. Section 2 introduces the background of CL and supervised/self-supervised AT. Section 3 addresses how the classification perspective is strengthened and merged in a new self-supervised AT. In Section 4, a series of experiments on image and text representations are conducted to evaluate robustness, efficiency and accuracy by using various defense models. Section 5 concludes some findings drawn from this study.
2. Adversarial training with contrastive view
The safety and reliability of deep models have been very crucial when practically deploying an information system. There have been a number of solutions proposed to enhance the robustness to domain shift, random noise, rotation or color changes in images or typos in sentences. The most common robustness highlighted recently is adversarial robustness. The defenses in visual and textual models against adversarial attacks are our main focus. Previously, the adversarial attacks for images (Carlini and Wagner, 2017; Madry et al., 2018) and sentences (Gao et al., 2018; Jin et al., 2020) have been addressed. Among various defense methods, the AT is seen as the most effective method to improve adversarial robustness.
2.1 Contrastive learning
This paper presents a contrastive perspective to develop a self-supervised AT. The instance discrimination is implemented to initiate a unified view toward AT. First, the multi-view CL is studied. CL is used for self-supervised learning (Gan et al., 2024) where class labels are not required. Originally, CL is performed by using SimCLR (Chen et al., 2020) where the representation with parameter is trained through a task where individual instances are mutually discriminative. Each sample in a batch of size B is transformed to a variant to form M batch views where is the kth view of . Random samples are drawn from strong data augmentation where denotes the set of variants for CL such as random cropping and resizing, random horizontal flip, strong random color jitter and random gray-scale conversion using image data. In the implementation, each variant can be viewed as an anchor, and its latent representation will attract (shown by green) that of positive sample , i.e. the same sample in different views, and simultaneously repel (shown by red) from those of the remaining samples within and between batches as the negative samples as illustrated in Figure 1 where and is seen as an anchor. For this case of two-view CL (), the CL objective due to individual samples from two batch views (1 term) and (2 term) as an InfoNCE objective is therefore yielded with encoder by:
The diagram begins with original inputs, including x 1. Transformations t a and t b create x 1 a and x 1 b, alongside additional augmented inputs. These inputs pass through f theta to produce corresponding representations, including z 1 a and z 1 b. Arrows labelled attract connect z 1 a and z 1 b. Arrows labelled repel connect the other representations with the matching representations.Contrastive learning is implemented with data augmentation and instance discrimination. acts as an anchor
The diagram begins with original inputs, including x 1. Transformations t a and t b create x 1 a and x 1 b, alongside additional augmented inputs. These inputs pass through f theta to produce corresponding representations, including z 1 a and z 1 b. Arrows labelled attract connect z 1 a and z 1 b. Arrows labelled repel connect the other representations with the matching representations.Contrastive learning is implemented with data augmentation and instance discrimination. acts as an anchor
where is the temperature. In equation (1), the encoder outputs are normalized in the calculation of cosine similarity between two samples. A crucial component in such a SimCLR process for image representation is the data augmentation (Luo et al., 2023a) through two or multiple views which are used in the task of instance discrimination (Zhang et al., 2024b). It is worth noting that the contrastive objective in equation (1) (Chien et al., 2024b) can be interpreted as a form of CE loss over a dynamically constructed set of classes defined by the batch samples. However, unlike standard classification, the implicit class assignments depend on the choice of anchor and vary across different views, which will be further analyzed in Section 3.
Relative to image data, the augmentation of text data is harder to visualize due to the discreteness of word tokens. Previously, the augmentation strategies such as back-translation, word deletion, reordering and substitution were used (Yan et al., 2021). For CL of a text model, a successful solution based on SimCSE (Gao et al., 2021) was developed by using an alternative augmentation called dropout. Using dropout, the latent sample is calculated by using a model with dropout rate p and encoder parameter . Each instance passes through the encoder twice to produce two representations and due to random dropout. The instance discrimination is then defined within a mini-batch. The representation of an anchor gets close to that of positive sample and at the same time gets separate from those of negative samples, which correspond to the views and of the remaining samples in a mini-batch . This study works on AT for image and text defense models from contrastive perspective (Chien et al., 2024a).
2.2 Supervised adversarial training
AT was developed to estimate a supervised defense model where learning procedure consists of attack generation and model training, as shown in Figure 2, which are performed to achieve adversarial robustness with the number of classes . The parameters of perturbation , encoder and classifier are jointly estimated by solving a minimax optimization problem (Tu et al., 2020; Chien and Sun, 2023), which is decomposed into an upper half and a lower half in the figure. The CE loss between the logit outputs , driven by parameters and softmax function, and the one-hot target vector is first maximized to estimate the worst-case perturbation by using attack data as shown in the upper half. In the lower half, the attack data (dashed blocks) are used as the training data to update parameters of encoder and classifier (shaded by grey) by minimizing the loss. The formulation turns out as:
The diagram has two connected stages labelled Attack Generation and Model Training. Original samples, including x 1, pass through t S L and then f theta e. The resulting representations are combined by dot product with W, followed by softmax, to produce output logits y hat. Target labels y and cross-entropy loss L C E are used to generate delta i through epsilon sign of the gradient with respect to t S L of x i. The perturbations are added to the transformed samples to create attack samples such as t S L of x 1 plus delta 1. These attack samples pass through f theta e. Their representations are combined with W by dot product and softmax to produce another set of output logits y hat. Cross-entropy loss is calculated against the same targets. Gradients with respect to W and theta e are used to update W and f theta e.Supervised adversarial training consists of attack generation for and model training for and
The diagram has two connected stages labelled Attack Generation and Model Training. Original samples, including x 1, pass through t S L and then f theta e. The resulting representations are combined by dot product with W, followed by softmax, to produce output logits y hat. Target labels y and cross-entropy loss L C E are used to generate delta i through epsilon sign of the gradient with respect to t S L of x i. The perturbations are added to the transformed samples to create attack samples such as t S L of x 1 plus delta 1. These attack samples pass through f theta e. Their representations are combined with W by dot product and softmax to produce another set of output logits y hat. Cross-entropy loss is calculated against the same targets. Gradients with respect to W and theta e are used to update W and f theta e.Supervised adversarial training consists of attack generation for and model training for and
where the augmented data from original data are drawn and used in SL for adversarial robustness. In equation (2), denotes the set of labeled data , and denotes the set of possible perturbations which are bounded within norm ball of a small radius as . The classification loss in SL is seen as a negative log likelihood of one-hot targets given by inputs , which is formed as a CE between , where is the class conditional likelihood, and based on:
In the first stage, the projected gradient descent (PGD) for bounded adversary in (Kurakin et al., 2018) is repeatedly performed at each iteration to estimate the perturbation via the fast gradient sign method (FGSM) in a form of with a step size . The iterative updating is performed by:
where . In the second stage, the model parameters are estimated by allowing perturbation noises presented in individual samples .
In general, the adversarial attacks on sentences are very different from those on images. Human eyes are not possible to tell the difference between an original image and its attack image within a small norm ball. For text data, it is hard to evaluate how much the sentence is perturbed when its semantic meaning is changed. The continuous essence of image data naturally results in using the gradient-based attacks. But, the attack in embedding space will produce non-existing tokens in the vocabulary. In Gao et al. (2018) and Jin et al. (2020), the black-box adversarial attacks were developed. Typically, AT for image representation aims to improve the model robustness to adversarial attacks. In this process, the accuracy on clean images would decrease due to the trade-off between robustness and accuracy. In text modeling, the adversarial perturbations were added onto the word embeddings during training. High performance was achieved in various classification tasks. The adversarially trained model was able to prevent overfitting problem. The perturbations in noisy samples were beneficial to protect unknown attacks. In Zhu et al. (2020), a low-cost AT method (Shafahi et al., 2019) was developed to improve model generalization. In Pan et al. (2022), the adversarially perturbed text examples were used to perform CL. All of these methods were designed in a supervised setting which required data labels . This paper presents a self-supervised defense model for adversarial attacks in presence of image and text data.
2.3 Self-supervised adversarial training
To handle the AT without labeled data , i.e. , the previous methods (Kim et al., 2020; Jiang et al., 2020) generally followed an objective similar to equation (2) while the CE loss was replaced by a CL loss in equation (1). The minimax optimization for self-supervised AT is performed by:
where CL loss is maximized to estimate the perturbation and is minimized to train the encoder . Figure 3 shows the attack procedure of self-supervised AT by using the robust contrastive learning (RoCL) (Kim et al., 2020) with . The dashed blocks denote the perturbed instances. In the adversarial procedure, each clean batch view and the perturbation of another batch view , denoted by:
The diagram begins with x a. Delta is added to x a to create adversarial x a. Adversarial x a and x b pass through f theta to produce latent representations. The contrastive loss L C L is calculated using adversarial x a, x b and theta. The representation z 1 a adversarial serves as an anchor in one branch, while z 1 b serves as an anchor in another branch. Arrows labelled attract connect each anchor with its corresponding paired representation. Arrows labelled repel connect each anchor with the other representations. The gradient of L C L with respect to delta is used to update delta.Self-supervised adversarial training adopts the perturbation estimated according to contrastive learning loss where instance discrimination is performed
The diagram begins with x a. Delta is added to x a to create adversarial x a. Adversarial x a and x b pass through f theta to produce latent representations. The contrastive loss L C L is calculated using adversarial x a, x b and theta. The representation z 1 a adversarial serves as an anchor in one branch, while z 1 b serves as an anchor in another branch. Arrows labelled attract connect each anchor with its corresponding paired representation. Arrows labelled repel connect each anchor with the other representations. The gradient of L C L with respect to delta is used to update delta.Self-supervised adversarial training adopts the perturbation estimated according to contrastive learning loss where instance discrimination is performed
alternatively take the role of anchor samples, and the negative samples will contain the other samples in both and . The multi-view CL loss due to perturbation and augmentation is then calculated for each individual batch data . The pairs of latent samples and from the same sample are attracting while those , , , from different samples are repelling. An additional regularization term is further introduced to enforce together the clean input and the perturbed input . The CL loss in equation (5) is then replaced by the regularized objective:
where and are regularization parameters.
Different from RoCL, the adversarial contrastive learning (ACL) (Jiang et al., 2020; Lin et al., 2026) presented a dual stream approach to self-supervised AT where the encoder was trained according to standard CL via SimCLR by using the clean examples as well as the corresponding adversarial examples. In addition, a potential result of self-supervised AT was obtained by the adversarial CL (AdvCL) (Fan et al., 2021), where an adversarial example view and a high-frequency component view via Fourier transform were introduced to conduct a multi-view CL for classification task. AdvCL used the pseudo labels (PLs) generated by a pretrained encoder for both attack generation and model training. A kind of pseudo-labeled AT was implemented. A recent method called graph ACL (Luo et al., 2023b) was proposed by learning a bank of negative samples for self-supervised graph encoding from graph-structured data. Basically, the above-mentioned methods involved in different methods, which complicated the training procedure. The computation and memory requirements are demanding. The connection to supervised AT was disregarded in previous studies.
3. Instance discrimination in contrastive learning and adversarial training
This study is motivated by incorporating the contrastive view via instance discrimination into an implementation of a new self-supervised adversarial training (Chien and Chen, 2024; Zhang et al., 2024a). A unified view of CL and AT is presented to allow richer information in a more compact model with lower computation cost. Figure 4 illustrates the flow diagram from a motivation for developing a self-supervised AT to a final solution based on two-view AT and an extended solution based on two-view CL where the self-supervised tricks of conducting classification in instance discrimination and using separate views of anchors and classes are implemented through handling the problems of inconsistencies in class definition and augmentation bias in traditional CL (Chen et al., 2020) and AT (Madry et al., 2018).
The flowchart begins with Self-Supervised Adversarial Training under Motivation. It branches under Models to Contrastive Learning and Adversarial Training. These lead under Problems to Inconsistent Class Definition and Inconsistent Distribution Bias. The problems connect under Implementation to Classification in Instance Discrimination and Separate Views Anchors slash Classes. Both implementations lead to the Extended Solution stage. This contains Two-View Contrastive Learning and, under Target Solution, Two-View Adversarial Training.Illustration of how self-supervised solutions to two-view contrastive learning and two-view adversarial training are developed
The flowchart begins with Self-Supervised Adversarial Training under Motivation. It branches under Models to Contrastive Learning and Adversarial Training. These lead under Problems to Inconsistent Class Definition and Inconsistent Distribution Bias. The problems connect under Implementation to Classification in Instance Discrimination and Separate Views Anchors slash Classes. Both implementations lead to the Extended Solution stage. This contains Two-View Contrastive Learning and, under Target Solution, Two-View Adversarial Training.Illustration of how self-supervised solutions to two-view contrastive learning and two-view adversarial training are developed
3.1 Formalization of instance discrimination and augmentation mismatch
To better understand the proposed method, we first formalize the relationship between CL and classification, and clarify the potential inconsistencies discussed in this work.
3.1.1 Relation to InfoNCE and cross entropy.
The contrastive loss in equation (1) can be rewritten as a CE loss or classification loss over a set of batch-wise classes, where each instance is treated as a distinct class, as detailed later in equation (10). Under this interpretation, the probability of assigning an anchor representation to its positive counterpart can be expressed as a classification output logit:
This reveals that standard CL implicitly performs classification with dynamically changing class definitions. We analyze two potential inconsistencies in previous CL and supervised adversarial learning.
3.1.2 Inconsistency in class definition.
In conventional CL, each sample alternates between being an anchor and a class representative. As a result, the conditional distributions being optimized considerably differ across views, which may introduce inconsistency when integrating with adversarial objectives that assume a fixed classifier for instance discrimination. In particular, the classes in CL using equation (1) are defined inconsistently at the individual steps for parameter updating. Notice that for those 2B data samples derived from two views of , each sample follows a different classification problem. Then, even the anchors from the same sample but with different views and are defined and treated as different instances or classes. This is because, as shown in equation (1), each data sample is alternatively acted as the anchor sample and positive/negative sample. When viewing CL as a classification task, there does exist an inconsistency in instance discrimination in equations (1) and (10). Such varying class definitions may introduce ambiguity in optimization and affect downstream performance. Prior contrastive objectives based on InfoNCE implicitly redefine instance classes depending on the anchor view and batch composition. Although effective empirically, this dynamic role switching may introduce ambiguity when adversarial perturbations are iteratively optimized. Our formulation explicitly separates anchor and class representations to stabilize the optimization target during adversarial updates.
3.1.3 Inconsistency in augmentation bias.
In CL and supervised AT, different augmentation pipelines and for the augmented samples and from the same original sample are used, respectively. This leads to a mismatch in the data distributions during representation learning and adversarial optimization:
The augmented data in previous CL (Chen et al., 2020) and AT (Madry et al., 2018) adopted different views of images in data augmentation as illustrated in Figure 5. Relative to the original image , the augmented images in previous works on CL and AT were distributed with strong bias and weak bias , respectively. The inconsistent biases in the views of augmented images did exist in the previous CL and AT. The inconsistent distribution view did happen in previous data augmentations for CL and AT. Such discrepancy may affect the stability of AT when combined with contrastive objectives. These observations motivate a unified formulation that aligns instance discrimination with a consistent classification perspective and harmonizes augmentation strategies. This paper presents a self-supervised AT driven by a unified view for instance discrimination where these two inconsistencies are handled through bridging CL and AT via a classification task for individual instances. Without loss of generality, in the application of sentence representation, two views of augmented training data and for self-supervised AT are implemented by using an encoder without and with neural network dropout, respectively. Recent studies in ACL have also observed that discrepancies between augmentation policies and adversarial objectives may affect robustness and representation stability. Dynamic ACL (DynACL) in Luo et al. (2023a) addressed this issue through dynamic augmentation scheduling, while adversarial invariant regularization (AIR) in Xu et al. (2023b) regularized augmentation-induced style variations. These observations are consistent with our motivation that inconsistent augmentation views may hinder stable adversarial optimization. Table 1 shows a convention of notations for ease of comprehension for the proposed method.
The original sample contains a car parked beside a building. The augmented data with strong bias contains three transformed samples. These focus on the front wheel, the side section and the rear section of the car. The augmented data with weak bias contains three transformed samples. Each retains most of the car and surrounding building, with changes in framing and orientation.Original sample and augmented samples and with strong bias and weak bias, respectively
The original sample contains a car parked beside a building. The augmented data with strong bias contains three transformed samples. These focus on the front wheel, the side section and the rear section of the car. The augmented data with weak bias contains three transformed samples. Each retains most of the car and surrounding building, with changes in framing and orientation.Original sample and augmented samples and with strong bias and weak bias, respectively
Convention of the notations in the proposed method
| Notation | Meaning |
|---|---|
| Original sample vector | |
| Weak augmentation function | |
| Strong augmentation function | |
| Anchor sample matrix or batch | |
| Class sample matrix or batch | |
| Class representation matrix or batch | |
| Self-supervised instance label vector | |
| B | Batch size |
| Notation | Meaning |
|---|---|
| Original sample vector | |
| Weak augmentation function | |
| Strong augmentation function | |
| Anchor sample matrix or batch | |
| Class sample matrix or batch | |
| Class representation matrix or batch | |
| Self-supervised instance label vector | |
| B | Batch size |
3.2 Implementation via classification in instance discrimination
Considering an instance discrimination (Wu et al., 2018) task in CL, every instance is viewed as a class, and the model is learned to classify each input sample in a B-way classification problem where B is the size of mini-batch. Let a memory bank or store the representations of all data samples. The softmax loss in a form of CE loss, or equivalently the negative log conditional likelihood for discrimination of B samples can be minimized via:
where and denotes the one-hot target matrix for instance discrimination, which is fixed as a B-dimensional identity matrix . Notably, the instance conditional likelihood can be seen as the output logits of an instance classification network for . A self-supervised learning (Yu and Dai, 2024) is performed without the need of class labels . When looking at each logarithmic term in equation (1), it is interesting that SimCLR similarly follows a classification task as seen in equation (10). In case of , equation (1) also expresses a softmax function as the CE loss for classification. Such a task plays a key role in CL. Basically, equation (10) shows that the classes in B-way classification problem are consistently defined by individual data samples in the data set throughout the training process. From an optimization perspective, this formulation can be viewed as approximating a robust classification objective over instance identities, where the adversarial perturbation seeks to maximize the classification loss while the encoder minimizes it. Compared to pairwise contrastive loss, the batch-wise classification view provides a more stable gradient signal, especially when integrated with adversarial updates:
The InfoNCE objective in equation (1) is equivalent to a batch-wise cross-entropy loss over dynamically constructed instance classes.
When adversarial perturbations are introduced, dynamically changing instance roles in standard contrastive learning induce inconsistent optimization targets across attack iterations.
Implication. Separating anchor and class samples stabilizes the adversarial optimization objective.
Algorithm 1. Enhancing instance discrimination for a new contrastive learning or self-supervised learning
3.3 Implementation for two-view contrastive learning
To cope with these inconsistencies, this paper strengthens the classification perspective in standard CL (Chen et al., 2020) in equation (1) by separating the views of anchor samples and class samples. As the inconsistent class definition is caused by using each sample as both anchor and positive/negative samples, this study explicitly separates both roles and sufficiently uses different views or batches. In addition, data augmentation may cause a severe mismatch between the distributions in training and test data. But, the previous CL (Chen et al., 2020) performed well by using augmented data with strong bias. This study is motivated by incorporating different views by using various augmented data. In particular, the anchor samples are drawn from a view batch via weak data augmentation. These anchor samples are analogous to those input samples in previous supervised AT (Madry et al., 2018). Notably, these anchor samples are only used as the anchors in instance discrimination. On the other hand, since strong augmentation is still required for instance discrimination to fulfill CL, the class samples are formed as a view batch by using strong data augmentation. These class samples with strong distribution biases are only used as the samples in either positive or negative classes. With the view batches defined by the augmented data due to weak and strong biases, respectively, a self-supervised classification task is formulated by feeding the class samples into a model or an encoder to obtain a batch of class representations for instance discrimination:
Therefore, a two-view classification problem is formulated in a learning procedure. In this procedure, the classification logits of an input example are first calculated by feeding an anchor sample with the view of weak data augmentation, and then passing this sample through an encoder , multiplying the encoder output by the class representation matrix based on the view of strong data augmentation, and measuring the class or instance posterior probabilities by softmax function. Given the class representation matrix , each weakly augmented anchor sample is projected into the same embedding space to obtain the instance classification logits:
Next, the output logits of an input are used to calculate the sample-based CE loss by:
where denotes the self-supervision label for an anchor . This one-hot label is defined by the index of the corresponding class sample, i.e. and if . The number of classes corresponds to that of samples B in a view batch, and the collection of one-hot target vectors is formed as a B-dimensional identity matrix . Figure 6 shows an implementation of a new self-supervised classification task for CL. Importantly, the classification perspective in CL is strengthened by consistently handling a unified classification problem from the views of anchor and class samples by using weak and strong data augmentations, respectively. The issue of inconsistent class definition is addressed because the samples of anchor and class are separately defined over individual examples. The same example will not be mixed as different classes. In addition, two views of augmented data are both adopted in a single task so that the inconsistent augmentation bias does not exist. Algorithm 1 illustrates the procedure of enhancing instance discrimination for a new contrastive or self-supervised learning.
The diagram begins with x 1 and additional samples. Weak transformation t w produces anchor samples, including x 1 anch. Strong transformation t s produces class samples, including x 1 cls. Both sets pass through f theta. The anchor samples produce anchor features, including z 1 anch. The class samples produce class features, including z 1 cls. A dot product combines the anchor and class features. Softmax produces output logits y hat. The targets y tilde form an identity matrix with 1 along the diagonal and 0 elsewhere. The output logits and targets are passed to cross-entropy loss L C E. Theta is updated using the gradient of the summed cross-entropy losses over B samples.Instance discrimination in contrastive learning is enhanced by using two-view augmented data with weak bias and strong bias relative to as the anchor samples and class samples , respectively
The diagram begins with x 1 and additional samples. Weak transformation t w produces anchor samples, including x 1 anch. Strong transformation t s produces class samples, including x 1 cls. Both sets pass through f theta. The anchor samples produce anchor features, including z 1 anch. The class samples produce class features, including z 1 cls. A dot product combines the anchor and class features. Softmax produces output logits y hat. The targets y tilde form an identity matrix with 1 along the diagonal and 0 elsewhere. The output logits and targets are passed to cross-entropy loss L C E. Theta is updated using the gradient of the summed cross-entropy losses over B samples.Instance discrimination in contrastive learning is enhanced by using two-view augmented data with weak bias and strong bias relative to as the anchor samples and class samples , respectively
3.4 Implementation for two-view adversarial training
This study connects the supervised, unsupervised and self-supervised learning and presents a contrastive view to derive a new self-supervised AT. First, the classifier with parameter in SL consists of an encoder and a linear layer with parameters and , respectively. The output logits are calculated by:
Alternatively, the softmax or CE loss in equation (13) is minimized to train a self-supervised classifier for instance discrimination in CL. The connection between SL and CL tasks is illustrated by looking at how the classification logits are related in equations (14) and (12). Here, the only alteration is made by replacing C-dimensional for SL in equation (14) with B-dimensional for CL in equation (12), i.e. . With this connection between classification tasks in SL and CL, it is meaningful to introduce an unsupervised setting for standard AT (Madry et al., 2018) in equation (2). By replacing the supervised classifier weights with the instance representation matrix, the standard supervised AT objective can be reformulated into a self-supervised adversarial optimization:
where the simulated targets are imposed. Notably, two-view augmented data with weak [] and strong [ via in equation (11)] distribution biases relative to are merged in equation (15). In the implementation, the adversarial attack data are first updated through PGD attack (Kurakin et al., 2018) by maximizing CE loss in equations (13) and (15) with the perturbation given by:
or equivalently updated with K attack iterations based on:
The perturbations are then added to anchor samples to obtain attack data and used as new anchor samples to minimize CE loss again to train encoder where the class samples from alternative view are also used. The proposed self-supervised AT is implemented by incorporating contrastive view in a B-dimensional AT which consistently implements instance discrimination via a classification problem in equation (15).
This study bridges supervised and self-supervised AT and builds an efficient solution to self-supervised AT, which is configured as shown in Figure 7 and implemented by using Algorithm 2. Given an input sample and a set of target classes in standard supervised AT, the perturbation is estimated to trick the model to predict a wrong class. However, in previous self-supervised AT (Kim et al., 2020; Jiang et al., 2020), the classes were defined from positive/negative samples, in which some of them were attack data. Since PGD attack was iterative, in every attack iteration, some of the classes might be changed while the others stayed the same. An ambiguity ascent direction was caused during optimization over attack data. The issue of inconsistent class definition became even severe with adversarial attack.
The diagram contains Attack Generation and Model Training stages. Input samples, including x 1, receive weak transformation t w and strong transformation t s. The weakly transformed samples pass through f theta to produce anchor features. The strongly transformed samples pass through f theta to produce class features z cls. A dot product combines the anchor and class features. Softmax produces output logits y hat, which are compared with targets y tilde using cross-entropy loss L C E. Delta i is calculated using epsilon sign of the gradient of L C E with respect to t w of x i. Delta 1 is added to t w of x 1 to create an attacked weakly transformed sample. These attacked samples pass through f theta to produce another set of anchor features. A dot product combines these anchor features with the class features. Softmax produces another set of output logits y hat, which are compared with the same targets using L C E. The gradient of L C E with respect to theta is used to update f theta.A new self-supervised adversarial training is developed by enhancing the instance discrimination via two-view augmented data and separate anchor and class samples
The diagram contains Attack Generation and Model Training stages. Input samples, including x 1, receive weak transformation t w and strong transformation t s. The weakly transformed samples pass through f theta to produce anchor features. The strongly transformed samples pass through f theta to produce class features z cls. A dot product combines the anchor and class features. Softmax produces output logits y hat, which are compared with targets y tilde using cross-entropy loss L C E. Delta i is calculated using epsilon sign of the gradient of L C E with respect to t w of x i. Delta 1 is added to t w of x 1 to create an attacked weakly transformed sample. These attacked samples pass through f theta to produce another set of anchor features. A dot product combines these anchor features with the class features. Softmax produces another set of output logits y hat, which are compared with the same targets using L C E. The gradient of L C E with respect to theta is used to update f theta.A new self-supervised adversarial training is developed by enhancing the instance discrimination via two-view augmented data and separate anchor and class samples
Compared with RoCL (Kim et al., 2020) and ACL (Jiang et al., 2020), the proposed framework does not rely on additional contrastive streams or auxiliary adversarial objectives. Compared with the DynACL in Luo et al. (2023a), our method does not require dynamic augmentation scheduling. Instead, robustness is achieved through a unified classification-based instance discrimination mechanism with explicit separation between anchor and class representations.
Compared with the solutions to supervised AT in equation (2) and self-supervised AT in equation (5), the proposed self-supervised AT carries out a self-supervised method in equation (15) with three essential refinements including:
Algorithm 2. Enhancing instance discrimination for a new self-supervised adversarial training
replacement with the instance class matrix ;
assignment with the self-supervised target matrix ; and
incorporation of two-view augmented data for anchor and class samples , respectively.
The proposed method addresses the issue of inconsistent instance labels which is caused when the same sample in CL alternatively acts as anchor and positive/negative samples. The classes in this self-supervised AT are defined by the class samples which are consistent within a training step. The attack perturbation is only added to the anchor samples as seen in equation (17), thus the attack target stays the same throughout the attack iterations. These steps provide a clear ascent direction for the attacker and generate a strong attack during AT, which ultimately results in a robust model. Importantly, this paper presents a meaningful solution to self-supervised AT by transforming a supervised AT into a self-supervised variant through the replacement of in equation (14) with in equation (12). Attractively, such a connection provides an avenue to extend any existing or future supervised AT methods to realize their corresponding self-supervised AT methods. This framework takes a further step toward unifying the supervised and self-supervised AT. This paper presents a contrastive perspective for implementing self-supervised AT. The instance discrimination in CL is enhanced to develop a new self-supervised AT. The resulting solution is simple and efficient. The extra views and costs in previous methods (Jiang et al., 2020; Fan et al., 2021) are avoided.
3.5 Further extension and investigation
In addition, the proposed two-view AT can be extended by incorporating two-view representation in a previous supervised AT (Zhang et al., 2019) to build a new variant of self-supervised AT as well as in implementation of a robust self-supervised text embedding. For example, the adversarial attack in the previous method called TRADES (Zhang et al., 2019) was generated by maximizing the Kullback-Leibler (KL) divergence between and . Then, the image encoder parameter in a supervised AT framework was estimated by minimizing:
where is a regularization parameter. A robust image encoder was trained in a supervised setting where C-dimensional one-hot target matrix of classifier was given. This study presents an approach to bridge supervised and self-supervised AT. In particular, a new self-supervised TRADES is proposed and extended by solving:
where two views of augmented data via anchor and class samples are adopted to enhance the instance discrimination, respectively. The perturbation is therefore generated by using PGD attack:
A self-supervised TRADES is obtained from supervised TRADES by simply replacing and setting .
This study further presents a self-supervised AT method to build a robust text representation. In the implementation, first the latent class samples for individual instances in a mini-batch consisting of words or sentences are calculated by:
using an encoder with a dropout rate p. The first view of training data is then formed via strong data augmentation . This view does contain positive and negative samples for instance discrimination which are used for CL. To enhance the consistencies in instance discrimination, a B-way classification problem is formulated to simulate a SL task by considering the weakly augmented samples or simply original samples. The latent anchor inputs using the encoder without dropout are used to form a second view to predict the corresponding classes for individual instances as given in class matrix . Accordingly, a new CL is proposed to simulate an SL task via enriching the instance discrimination by replacing the classification layer , specifying the target matrix and separating the views of anchor and positive/negative class samples . The problem turns out to find the optimal encoder or encoder with dropout based on two views of latent samples from the same original samples . The resulting solution aims to estimate an informative encoder to distinguish individual samples or latent instances mutually based on two different views and without and with dropout in encoder, respectively. The CE loss between targets and the logits , which are calculated by softmax function using the dot product of and (as shown in Figure 6), is minimized.
More importantly, this new CL is fulfilled to implement AT for a defense text model. From our investigation, this is the first AT framework developed for sentence embedding in self-supervised setting where the encoder and the perturbation are jointly trained. A minimax optimization problem is formulated according to the same objective for instance discrimination in two-view CL via encoder without () and with () dropout via:
where the worst-case perturbations for a mini-batch of samples with maximal CE loss are first calculated and then added to the word embeddings to estimate the optimal encoder with minimum CE loss. The resulting encoder is robust to the worst-case perturbation . Figure 8 shows the proposed self-supervised AT procedure, which is a direct extension from standard supervised AT in Figure 2 and two-view self-supervised AT in Figure 7. Basically, the adversarial perturbation can be generated by using the proposed self-supervised FGSM attack:
The diagram contains Attack Generation and Model Training stages. Input x is represented as word embeddings and passes through f theta. One path uses no dropout to produce anchor features f theta of x. Another path uses dropout p to produce class features z cls. A dot product combines the anchor and class features. Softmax produces output logits y hat, which are compared with targets y tilde using cross-entropy loss L C E. Delta i is calculated using epsilon sign of the gradient of L C E with respect to x i. Delta is added to x to create x plus delta. The perturbed embeddings pass through f theta with no dropout to produce anchor features f theta of x plus delta. These anchor features are combined with the same class features by dot product. Softmax produces another set of output logits y hat, which are compared with the same targets using L C E. The gradient of L C E with respect to theta is used to update f theta.Self-supervised adversarial training for sentence embedding by using two-view samples without and with dropout
The diagram contains Attack Generation and Model Training stages. Input x is represented as word embeddings and passes through f theta. One path uses no dropout to produce anchor features f theta of x. Another path uses dropout p to produce class features z cls. A dot product combines the anchor and class features. Softmax produces output logits y hat, which are compared with targets y tilde using cross-entropy loss L C E. Delta i is calculated using epsilon sign of the gradient of L C E with respect to x i. Delta is added to x to create x plus delta. The perturbed embeddings pass through f theta with no dropout to produce anchor features f theta of x plus delta. These anchor features are combined with the same class features by dot product. Softmax produces another set of output logits y hat, which are compared with the same targets using L C E. The gradient of L C E with respect to theta is used to update f theta.Self-supervised adversarial training for sentence embedding by using two-view samples without and with dropout
By augmenting the adversarial anchor representation which is obtained via an encoder without dropout, the proposed AT method bridges the supervised and self-supervised AT and compensates the mismatch of adversarial examples between training and test phases.
Further investigation over recent works on improving ACL is addressed from the perspectives of data augmentation and model regularization. In Luo et al. (2023a), a dynamic augmentation scheme was proposed to build a DynACL which compensated the gap due to the inconsistency between strong and weak augmentations in CL and AT, respectively, through an annealing schedule for augmentation strengths. In Xu et al. (2023b), DynACL was further improved by imposing a causal graph to enforce the style-independence and fulfill the AIR in the learned model DynACL-AIR. The robustness in DynACL was enhanced by minimizing an AIR loss. Another approach (Zhang et al., 2022) aimed to decouple the problem in ACL into two-stage sub-problems for a non-robust CL and a pseudo-supervised AT where an efficient solution was implemented. In Xu et al. (2023a), the tremendous running time in ACL was mitigated through a robustness-aware coreset selection which was feasible to run on a large-scale data set. The resulting method was performed by minimizing the representation divergence between natural samples and adversarial variants to assure the robustness transferability (RT). In Wang et al. (2023), the adversarial robustness was enhanced by a contrastive distillation via an adaptive denoising module. Typically, this paper presents a new two-view CL (Figure 6) and a new two-view AT (Figures 7 and 8) where the inconsistencies due to class definition and augmentation bias in previous CL and AT are addressed through an instance discrimination task based on anchor features and class features from two individual views of augmented data. To the best of the authors’ knowledge, this study provides one of the first unified analyses of class-definition inconsistency and augmentation mismatch in self-supervised AT.
4. Experiments
The proposed method was examined for image and text representations where the tasks of image classification and sentence embedding were evaluated, respectively. The enhanced instance discrimination was implemented for CL and self-supervised AT.
4.1 Experimental settings
This paper conducted the evaluation on image classification over CIFAR-10 and CIFAR-100 data sets where each data set had 50 K training images and 10 K test images with a size of 32 32 3. To ensure fair comparison and reproducibility, all experiments are conducted under a unified training protocol unless otherwise specified:
Backbone architecture. For image representation, we adopt ResNet-18 (He et al., 2016; Chien and Chang, 2023) as the encoder following standard practice in CL. For text representation, we use a transformer-based encoder initialized from a pre-trained BERT-base model (Devlin et al., 2019).
Training configuration. All models are trained using the Adam optimizer with an initial learning rate of , momentum 0.9, weight decay 0.001 and temperature . The learning rate is decayed using a cosine annealing schedule. The batch size (B) is set to 256 for image experiments and 128 for text experiments. The models are trained for 800 epochs for image data sets and 200 epochs for text data sets by using the stochastic gradient descent algorithm. No ground-truth labels are used in self-supervised settings. Pseudo-labels are not used unless explicitly stated.
Adversarial attack settings. We adopt the PGD as the adversarial attack method. For image data, the perturbation is bounded by an -norm constraint with . The number of PGD steps is set to with a step size of , which is known as strong attacks. For text representation, adversarial perturbations are applied in the embedding space with norm constraint .
Data augmentation. For image experiments, the strong random cropping and resizing, random horizontal flip, random color jitter and grayscale conversion were run to find class samples or while the weak random cropping and resizing and random horizontal flip were done to find anchor samples or . For text experiments, the weak augmentation was run by using dropout rate either 0 or 0.1 while the strong augmentation was done by using either 0.2 or 0.3, where each sentence is passed through the encoder twice with independent dropout masks.
In the experiments on image classification, a three-layer projection head was added for CL. An ensemble of parameter-free attack, called AutoAttack (Croce and Hein, 2020), was included in the evaluation. The standard linear evaluation setting was implemented. The trained encoder was fixed and a linear classifier was trained on top of encoder by using the labeled data. The experimental results were compared with current self-supervised AT methods under consistent setting including RoCL (Kim et al., 2020), ACL (Jiang et al., 2020), AdvCL (Fan et al., 2021) and DynACL (Luo et al., 2023a) where the solutions were all developed via CL. The effect of AIR with details in Xu et al. (2023b) was evaluated. The cross-task adversarial and common-corruption (Hendrycks and Dietterich, 2019) RT from pretraining using CIFAR-10 to finetuning using CIFAR-100 was examined. Different methods were further accessed in terms of memory usage and computation time where a personal computer with CPU Intel Xeon E5-2620 v4, RAM 32 G and GPU Tesla V100S was used in the experiments.
The experimental setting in evaluation of sentence embedding followed that in SimCSE (Gao et al., 2021). The semantic textual similarity (STS) between two sentence embeddings was evaluated by using seven STS data sets including STS12 to STS16 (Agirre et al., 2016), STS Benchmark (STSB) (Cer et al., 2017) and SICK-Relatedness (SICKR) (Marelli et al., 2014). The Spearman’s rank correlation was used as the evaluation metric. The CLS token in BERT was extracted as the sentence representation. The model was trained by using randomly sampled sentences from English Wikipedia the same as those used in SimCSE (Gao et al., 2021). The model was evaluated every 125 training steps on development set to assure the best performance checkpoint. There was no additional regressor on top of encoder. In this comparative study, the results of sentence encoders from the previous supervised methods (Reimers and Gurevych, 2019; Li et al., 2020a; Su et al., 2021) and self-supervised methods (Carlsson et al., 2021; Yan et al., 2021; Kim et al., 2021; Gao et al., 2021) were included.
4.2 Results on image representation
4.2.1 Comparison over contrastive learning and adversarial training.
First of all, the robust accuracy (RA) (%) on attack test images (PGD), standard accuracy (SA) (%) on clean test images, memory usage and training time (CIFAR-10) using SimCLR (Chen et al., 2020), RoCL (Kim et al., 2020), ACL (Jiang et al., 2020), AdvCL (Fan et al., 2021), DynACL (Luo et al., 2023a) and the proposed self-supervised AT are compared in Table 2. This comparison shows the performance of implementing a contrastive view in AT via equations (15) and (19) to carry out a new self-supervised AT and a new self-supervised TRADES, respectively. The proposed TRADES was implemented by merging the new contrastive view in Zhang et al. (2019) for original TRADES. Among different methods, CL using SimCLR is highly affected by attacks and performs the worst. The proposed AT performs better than RoCL and ACL on CIFAR-10 and CIFAR-100 in terms of RA. It is worth noting that the accuracy on attack data (RA) is much more important than that on clean data (SA) for adversarial defense. This is because in a real-world situation one will not know whether the input sample is attacked. RA can be seen as a worst-case guarantee of accuracy assuming all input data are attacked. Notably, the proposed AT () with RA 51.15% even outperforms AdvCL with RA 50.25% on CIFAR-10 where AdvCL additionally used the PLs and extra model architecture. The computation time and memory cost are even reduced by using the proposed AT. It is further found that RAs in two tasks are degraded when the batch size B is reduced to 256. The memory and computation costs are decreased as well. In addition, similar to AdvCL, the proposed AT and TRADES are implemented by using PLs. The resulting RA is therefore increased to 52.52%. In case of CIFAR-100, the highest RA 27.62% is obtained by using the proposed self-supervised TRADES via equation (19). This result without using PLs is comparable with that of AdvCL where PL is required. The SOTA result 28.05% is obtained by using the proposed TRADES with PLs. This is because CIFAR-100 involves more classes, and the resulting performance would be more likely benefited by the KL term in TRADES, which regularizes the entire output probability instead of simply learning from hard labels. When using the proposed TRADES, the time and memory complexities are lower than those of baseline AdvCL.
Comparison of the results for CL and different self-supervised AT methods. The methods in the bottom-half used the pseudo labels (PLs) (Fan et al., 2021)
| CIFAR-10 | CIFAR-100 | |||||
|---|---|---|---|---|---|---|
| Methods | RA | SA | RA | SA | Memory (MB) | Time |
| SimCLR* | 0.03 | 91.77 | 0.48 | 66.86 | 6,409 | 7.7 h |
| RoCL* () | 39.93 | 78.37 | 18.79 | 49.53 | 19,101 | 2 d 9 h |
| ACL* | 44.23 | 79.04 | 20.97 | 47.51 | 11,649 | 2d 2.1 h |
| DynACL* | 46.82 | 79.10 | 23.21 | 47.20 | 12,023 | 2d 2.6 h |
| Ours (AT, ) | 48.74 | 79.34 | 26.49 | 47.06 | 6,409 | 20 h |
| Ours (TRADES) | 50.21 | 77.49 | 27.62 | 48.96 | 8,677 | 1 d 12.4 h |
| Ours (AT, ) | 51.15 | 76.90 | 27.21 | 45.12 | 6,409 | 1 d 4.6 h |
| Ours (AT, ) | 50.55 | 76.33 | 27.10 | 45.08 | 5,989 | 1 d 1.8 h |
| AdvCL (Fan et al., 2021) | 50.45 | 80.85 | 27.67 | 48.34 | 20,875 | 3 d |
| AdvCL* | 50.25 | 80.58 | 27.12 | 47.79 | ||
| Ours (TRADES) + PL | 51.29 | 80.89 | 28.05 | 48.46 | 11,407 | 2 d 9 h |
| Ours (AT) + PL | 52.52 | 80.36 | 28.01 | 48.05 | 8,985 | 2 d 0.6 h |
| CIFAR-10 | CIFAR-100 | |||||
|---|---|---|---|---|---|---|
| Methods | Memory ( | Time | ||||
| SimCLR* | 0.03 | 91.77 | 0.48 | 66.86 | 6,409 | 7.7 h |
| RoCL* ( | 39.93 | 78.37 | 18.79 | 49.53 | 19,101 | 2 d 9 h |
| ACL* | 44.23 | 79.04 | 20.97 | 47.51 | 11,649 | 2d 2.1 h |
| DynACL* | 46.82 | 79.10 | 23.21 | 47.20 | 12,023 | 2d 2.6 h |
| Ours (AT, | 48.74 | 79.34 | 26.49 | 47.06 | 6,409 | 20 h |
| Ours ( | 50.21 | 77.49 | 27.62 | 48.96 | 8,677 | 1 d 12.4 h |
| Ours (AT, | 51.15 | 76.90 | 27.21 | 45.12 | 6,409 | 1 d 4.6 h |
| Ours (AT, | 50.55 | 76.33 | 27.10 | 45.08 | 5,989 | 1 d 1.8 h |
| AdvCL ( | 50.45 | 80.85 | 27.67 | 48.34 | 20,875 | 3 d |
| AdvCL* | 50.25 | 80.58 | 27.12 | 47.79 | ||
| Ours ( | 51.29 | 80.89 | 28.05 | 48.46 | 11,407 | 2 d 9 h |
| Ours ( | 52.52 | 80.36 | 28.01 | 48.05 | 8,985 | 2 d 0.6 h |
*Indicates our results. The highest RAs (%) are italic. Memory and computationcosts are evaluated
4.2.2 Comparison over self-supervised adversarial training methods.
In addition, Table 3 shows RA and SA of the proposed self-supervised AT, and the new AT by incorporating the proposed contrastive view in TRADES under different hyperparameter as well as in the helper-based adversarial training (HAT) (Rade and Moosavi-Dezfooli, 2022). The main goal of the proposed HAT is to increase SA in a self-supervised AT setting. The highest SA among all of AT variants is obtained by using the proposed self-supervised HAT. By increasing in the TRADES loss, the model robustness is increased but the SA is decreased. This is consistent with the effect observed in the original TRADES (Zhang et al., 2019). The control over enables us to achieve a higher SA while still maintaining a good robustness. This investigation reveals that CL viewpoint does develop the new AT variants while maintaining the benefits and characteristics from their original AT.
Comparison of RA (%) and SA (%) of using the proposed methods based on the self-supervised TRADES under different , self-supervised HAT and self-supervised AT where CIFAR-10 was used
| Methods | RA | SA | |
|---|---|---|---|
| Ours (TRADES) | 48.67 | 78.83 | 6 |
| 49.36 | 78.67 | 12 | |
| 49.78 | 78.15 | 16 | |
| 50.04 | 78.52 | 18 | |
| 50.21 | 77.49 | 20 | |
| Ours (HAT) | 50.39 | 79.98 | |
| Ours (AT) | 51.15 | 78.90 |
| Methods | |||
|---|---|---|---|
| Ours ( | 48.67 | 78.83 | 6 |
| 49.36 | 78.67 | 12 | |
| 49.78 | 78.15 | 16 | |
| 50.04 | 78.52 | 18 | |
| 50.21 | 77.49 | 20 | |
| Ours ( | 50.39 | 79.98 | |
| Ours ( | 51.15 | 78.90 |
A key benefit of using contrastive view in the proposed AT is its intuition, simplicity and consistency. Owing to two perspectives in a hybrid CL and AT objective, the memory requirement is the same as that of the original SimCLR (Chen et al., 2020). The memory consumption is substantially reduced when compared with the other methods, and is even lower than one third of the memory relative to that used in AdvCL. Similar results are obtained in the metric of training time. Training time of the proposed self-supervised AT is generally smaller than or equal to half of the existing methods. The proposed AT with three attack iterations can reduce the training time while its RA is still higher than those using RoCL and ACL. Such a result reflects the robustness in presence of PGD attack as it can generate the challenging attacks for AT even with the reduced attack iterations. Overall, Figure 9 depicts the memory cost in GB versus the training time in seconds per epoch while RAs using different methods are shown. In this comparison, the proposed self-supervised AT or AT+PL obtains higher accuracies but smaller memory cost and computation time.
The scatter plot compares time in seconds per training epoch on the horizontal axis with memory in gigabytes on the vertical axis. Five methods are plotted. R o C L has a labelled score of 39.93 and appears at high memory with moderately high training time. A C L has a score of 44.23 and appears at intermediate memory and training time. A d v C L with P L has a score of 50.25 and appears at the highest memory and longest training time. Ours has a score of 51.15 and appears at the lowest memory and shortest training time. Ours plus P L has a score of 52.52 and appears at lower memory and intermediate training time.RA (%) versus computation time (in seconds per epoch) and memory cost (in gigabytes) by using different self-supervised AT methods where CIFAR-10 was used
The scatter plot compares time in seconds per training epoch on the horizontal axis with memory in gigabytes on the vertical axis. Five methods are plotted. R o C L has a labelled score of 39.93 and appears at high memory with moderately high training time. A C L has a score of 44.23 and appears at intermediate memory and training time. A d v C L with P L has a score of 50.25 and appears at the highest memory and longest training time. Ours has a score of 51.15 and appears at the lowest memory and shortest training time. Ours plus P L has a score of 52.52 and appears at lower memory and intermediate training time.RA (%) versus computation time (in seconds per epoch) and memory cost (in gigabytes) by using different self-supervised AT methods where CIFAR-10 was used
4.2.3 Ablation study.
To analyze the contributions of individual components, we conduct an ablation study with the results as shown in Table 4. Starting from the baseline CL model, introducing AT via RoCL (Kim et al., 2020) significantly improves the robustness but degrades the SA. Reformulating the contrastive objective in CE loss as a classification problem using equation (10) improves the representation quality with slight robustness gain. Combining both CE loss and the proposed AT loss via equation (15) yields a clear improvement in robustness, indicating the compatibility of the classification perspective with adversarial optimization. Aligning augmentation strategies stabilizes the training and improves both standard and robust performance. Finally, an additional loss based on an AIR (Xu et al., 2023b) is merged to achieve the best trade-off, demonstrating the effectiveness of the complete framework.
Ablation study on the proposed self-supervised adversarial training, which is integrated by cross entropy reformulation in equation (10), adversarial training in equation (15), augmentation alignment in equation (15) and adversarial invariant regularization (AIR) in Xu et al. (2023b) where CIFAR-10 was used
| Methods | CE reform. | AT | Aug align. | AIR | RA | SA |
|---|---|---|---|---|---|---|
| SimCLR baseline | 0.03 | 91.77 | ||||
| + AT (RoCL) | ✓ | 39.93 | 78.37 | |||
| + CE reformulation | ✓ | 40.98 | 77.42 | |||
| + CE + AT (ours (15)) | ✓ | ✓ | 48.35 | 76.34 | ||
| + CE + AT + aug alignment | ✓ | ✓ | ✓ | 51.15 | 76.90 | |
| + CE + AT + aug alignment + AIR | ✓ | ✓ | ✓ | ✓ | 53.05 | 77.21 |
| Methods | Aug align. | |||||
|---|---|---|---|---|---|---|
| SimCLR baseline | 0.03 | 91.77 | ||||
| + | ✓ | 39.93 | 78.37 | |||
| + | ✓ | 40.98 | 77.42 | |||
| + | ✓ | ✓ | 48.35 | 76.34 | ||
| + | ✓ | ✓ | ✓ | 51.15 | 76.90 | |
| + | ✓ | ✓ | ✓ | ✓ | 53.05 | 77.21 |
4.3 Evaluation for perturbation invariance
In general, AT is performed to pursue robust features holding the perturbation invariance as illustrated in Figure 10. In this study, the image data in latent representation using the trained encoder are visualized via t-distributed neighbor embedding. Figure 11 shows two-dimensional (2D) visualizations of the learned representations of clean images (blue dots) and the corresponding adversarial images (orange dots). The image samples of class “cat” on CIFAR-10 are displayed. The trained image encoder using SimCLR (Chen et al., 2020) in Figure 11(a) and the proposed self-supervised AT in Figure 11(b) are compared. It can be seen that CL encoder via SimCLR is susceptible to attack samples so that the clean and attack samples are mapped into different points in latent space. Using the proposed AT, the encoder is learned to hold the invariant property in presence of ambient attack or perturbation. Thus, the resulting classifier is able to classify attack images as good as their original images. The blue and orange dots are mostly overlapping since the proposed model views them as the same, and is accordingly robust to attacks or perturbation noises. For quantitative evaluation, this study calculates the relative invariance , which is defined as an inverse ratio of the accumulated distances between clean and attack samples for those latent samples of a method relative to SimCLR. The higher the value , the more invariant or robust the adversarial samples obtained by the learned encoder . This study compares 2D latent spaces by using the learned image encoders according to different self-supervised AT methods. Relative to CL encoder in Figure 11(a), four AT encoders in Figure 12 have higher overlapping between clean and attack samples which means better robustness. In this comparison, RoCL has the largest number of visible orange dots or sensitive attack images, which results in the lowest RAs in Table 2. The proposed AT obtained the highest relative invariance among different methods.
The diagram contains x 1, x 2 and x 3, with perturbed inputs x 1 plus delta 1, x 2 plus delta 2 and x 3 plus delta 3. All inputs pass through f theta into a latent representation space. The upper region contains f theta x 1, f theta x 2 and f theta x 3, each separated from its corresponding perturbed representation. Double-headed arrows connect each pair. An arrow labelled Adversarial Training leads to a second region. In this region, each f theta x input is positioned close to its corresponding f theta x plus delta representation.Illustration of perturbation invariance for the features after defense model through adversarial training
The diagram contains x 1, x 2 and x 3, with perturbed inputs x 1 plus delta 1, x 2 plus delta 2 and x 3 plus delta 3. All inputs pass through f theta into a latent representation space. The upper region contains f theta x 1, f theta x 2 and f theta x 3, each separated from its corresponding perturbed representation. Double-headed arrows connect each pair. An arrow labelled Adversarial Training leads to a second region. In this region, each f theta x input is positioned close to its corresponding f theta x plus delta representation.Illustration of perturbation invariance for the features after defense model through adversarial training
The visual contains two scatter plots. Panel a is labelled Sim C L R with rho 1. Adversarial and clean samples are widely dispersed and heavily intermixed across the plot. Panel b is labelled Ours with rho 2.01. Clean samples form a dense, regular central distribution, while fewer adversarial samples appear within and around it.2D latent visualizations by using (a) SimCLR and (b) the proposed AT. Blue and orange dots represent clean and attack images of class “cat” on CIFAR-10, respectively. The values of relative invariance are shown in brackets
The visual contains two scatter plots. Panel a is labelled Sim C L R with rho 1. Adversarial and clean samples are widely dispersed and heavily intermixed across the plot. Panel b is labelled Ours with rho 2.01. Clean samples form a dense, regular central distribution, while fewer adversarial samples appear within and around it.2D latent visualizations by using (a) SimCLR and (b) the proposed AT. Blue and orange dots represent clean and attack images of class “cat” on CIFAR-10, respectively. The values of relative invariance are shown in brackets
The visual contains four scatter plots. Panel a is labelled R o C L with rho 1.45. Points are broadly dispersed, with a denser concentration near the centre and many overlapping points. Panel b is labelled A C L with rho 1.75. Points form a broad distribution with a dense central region and scattered overlapping points. Panel c is labelled A d v C L with rho 1.89. Points form a regular dense distribution with additional overlapping points and a concentrated group extending towards the lower region. Panel d is labelled Ours with rho 2.01. Points form a regular, broadly distributed pattern with fewer overlapping points scattered throughout.Comparison of latent representations by using (a) RoCL, (b) ACL, (c) AdvCL and (d) the proposed AT on CIFAR-10. Clean (blue) and attack (orange) images and the resulting relative invariance are shown
The visual contains four scatter plots. Panel a is labelled R o C L with rho 1.45. Points are broadly dispersed, with a denser concentration near the centre and many overlapping points. Panel b is labelled A C L with rho 1.75. Points form a broad distribution with a dense central region and scattered overlapping points. Panel c is labelled A d v C L with rho 1.89. Points form a regular dense distribution with additional overlapping points and a concentrated group extending towards the lower region. Panel d is labelled Ours with rho 2.01. Points form a regular, broadly distributed pattern with fewer overlapping points scattered throughout.Comparison of latent representations by using (a) RoCL, (b) ACL, (c) AdvCL and (d) the proposed AT on CIFAR-10. Clean (blue) and attack (orange) images and the resulting relative invariance are shown
4.4 Evaluation for transferability and generalizability
The adversarial robustness using different methods is further evaluated across two different data sets transferred from CIFAR-10 as a pretraining task to CIFAR-100 as a finetuning task (CIFAR-10CIFAR-100) under the settings of cross-task adversarial and common-corruption (Hendrycks and Dietterich, 2019) RT. Fifteen types of common corruptions with corruption severity (CS) ranging from (CS-1, CS-3, CS-5) were adopted with details in Hendrycks and Dietterich (2019) and Xu et al. (2023b). The adversarial full finetuning (Luo et al., 2023a; Li et al., 2023) was performed in a way where the weights in a pre-trained encoder in a source task were used as the initialized weights to train the whole model in a target task by using adversarial data. In addition to the evaluation of RA (%) under PGD attack, this study compares different methods in terms of accuracy under AutoAttack (Croce and Hein, 2020) (denoted as AA [%]). In this set of comparison, an additional AIR loss (Xu et al., 2023b) was minimized to enforce independence from style factors for adversarial invariance in fulfillment of ACL-AIR, DynACL-AIR (Xu et al., 2023b) and ours-AIR where ACL (Jiang et al., 2020), DynACL (Luo et al., 2023a) and the proposed AT were performed, respectively. Table 5 reports different accuracies over different methods under various RT settings. It is found that dynamic data augmentation in DynACL improves the results of ACL under two cases of cross-task RT evaluation. AIR loss for regularization increases the accuracies. The proposed two-view AT with anchor and class features consistently performs better than ACL and DynACL under two RT settings.
Comparison of different accuracies (%) by using different methods where cross-task adversarial (Adv) and common-corruption (CC) (Hendrycks and Dietterich, 2019) robustness transferability (RT) in CIFAR-10CIFAR-100 is evaluated
| Methods | Adv-RT | CC-RT | ||||
|---|---|---|---|---|---|---|
| AA | RA | SA | CS-1 | CS-3 | CS-5 | |
| ACL* | 23.36 | 30.87 | 57.00 | 52.65 | 45.12 | 36.46 |
| ACL-AIR* | 24.23 | 31.44 | 57.24 | 53.09 | 45.96 | 37.70 |
| DynACL* | 25.07 | 32.13 | 56.43 | 53.88 | 45.77 | 37.13 |
| DynACL-AIR* | 25.63 | 32.62 | 58.10 | 54.45 | 46.90 | 38.24 |
| Ours (AT) | 26.31 | 33.61 | 58.49 | 55.62 | 47.73 | 39.26 |
| Ours-AIR (AT) | 27.68 | 35.22 | 59.75 | 57.10 | 49.05 | 40.80 |
| Methods | Adv-RT | CC-RT | ||||
|---|---|---|---|---|---|---|
| CS-1 | CS-3 | CS-5 | ||||
| ACL* | 23.36 | 30.87 | 57.00 | 52.65 | 45.12 | 36.46 |
| ACL-AIR* | 24.23 | 31.44 | 57.24 | 53.09 | 45.96 | 37.70 |
| DynACL* | 25.07 | 32.13 | 56.43 | 53.88 | 45.77 | 37.13 |
| DynACL-AIR* | 25.63 | 32.62 | 58.10 | 54.45 | 46.90 | 38.24 |
| Ours ( | 26.31 | 33.61 | 58.49 | 55.62 | 47.73 | 39.26 |
| Ours-AIR ( | 27.68 | 35.22 | 59.75 | 57.10 | 49.05 | 40.80 |
The generalizability of adversarial robustness is further investigated toward realistic settings in presence of imbalanced data and small data as illustrated in Table 6. This paper adopted CIFAR-100-LT (Wu et al., 2021) and CIFAR-FS (Goldblum et al., 2020; Dong et al., 2025), constructed from CIFAR-100, as the data sets to evaluate different defense models under long-tailed distribution and few-shot condition, respectively. AIR loss was merged in our TRADES and our AT. The effect of various batch sizes B is evaluated. The settings of CIFAR-100-LT follow (Wu et al., 2021) and ours in CIFAR-100. Again, robust accuracies under AutoAttack (AA) and PGD attack (20 steps) (RA) and SA are reported. Using CIFAR-100-LT, the imbalance rate was set by 10 (Wu et al., 2021). The results of using RoCL (Kim et al., 2020), ACL (Jiang et al., 2020), TRADES (Zhang et al., 2019) and the robust balanced predictions (RoBal), obtained in (Wu et al., 2021), are included for comparison with those of using our TRADES and our AT. It is found that our AT obtains desirable robust accuracies in presence of AutoAttack and PGD attacks although SA of our AT is not as good as that of RoBal. Our two-view TRADES performs better than previous TRADES (Zhang et al., 2019). In addition, the five-way five-shot setting in CIFAR-FS is adopted to assess the effect of adversarial perturbations in few-shot learning (Goldblum et al., 2020). For comparison, a recent method to adversarially robust few-shot learning based on feature purification (FP) and cyclic reconstruction (Dong et al., 2025) is included. Our previous settings in CIFAR-100 are used. In this evaluation, our two-view AT achieves the highest SA with and the highest robust accuracies under AutoAttack and PGD attack with and , respectively. These accuracies are higher than those of FP.
Comparison of different accuracies (%) by using defense methods where the conditions of imbalanced data and few shots are evaluated by using CIFAR-100-LT and CIFAR-FS, respectively. TRADES (Zhang et al., 2019; Wu et al., 2021) is supervised while our TRADES in section 3.5 is self-supervised
| Methods | Imbalanced data | Few shots | ||||
|---|---|---|---|---|---|---|
| AA | RA | SA | AA | RA | SA | |
| RoCL* | 15.94 | 18.09 | 44.86 | 36.64 | 43.04 | 58.13 |
| ACL* | 16.86 | 18.46 | 45.48 | 39.96 | 45.43 | 58.73 |
| TRADES (Wu et al., 2021) | 18.79 | 21.24 | 43.82 | – | – | – |
| TRADES* | 18.04 | 21.12 | 45.04 | 42.84 | 47.94 | 57.96 |
| Our (TRADES) | 19.14 | 22.18 | 48.74 | 45.61 | 49.34 | 59.34 |
| RoBal (Wu et al., 2021) | 18.80 | 19.59 | 50.49 | – | – | – |
| FP (Dong et al., 2025) | – | – | – | 46.29 | 49.90 | 59.75 |
| Ours (AT, ) | 21.06 | 23.40 | 49.89 | 46.52 | 51.51 | 60.84 |
| Ours (AT, ) | 20.43 | 22.96 | 50.32 | 47.03 | 52.20 | 62.70 |
| Ours (AT, ) | 19.12 | 20.84 | 50.12 | 47.81 | 50.42 | 59.94 |
| Methods | Imbalanced data | Few shots | ||||
|---|---|---|---|---|---|---|
| RoCL* | 15.94 | 18.09 | 44.86 | 36.64 | 43.04 | 58.13 |
| ACL* | 16.86 | 18.46 | 45.48 | 39.96 | 45.43 | 58.73 |
| 18.79 | 21.24 | 43.82 | – | – | – | |
| TRADES* | 18.04 | 21.12 | 45.04 | 42.84 | 47.94 | 57.96 |
| Our ( | 19.14 | 22.18 | 48.74 | 45.61 | 49.34 | 59.34 |
| RoBal ( | 18.80 | 19.59 | 50.49 | – | – | – |
| – | – | – | 46.29 | 49.90 | 59.75 | |
| Ours (AT, | 21.06 | 23.40 | 49.89 | 46.52 | 51.51 | 60.84 |
| Ours (AT, | 20.43 | 22.96 | 50.32 | 47.03 | 52.20 | 62.70 |
| Ours (AT, | 19.12 | 20.84 | 50.12 | 47.81 | 50.42 | 59.94 |
4.5 Results on text representation
The proposed self-supervised AT is further evaluated for sentence embedding. Table 7 shows the results of the proposed method and compares them with the previous methods under supervised and unsupervised settings across different data sets. Results of Spearman’s rank correlation are shown. The higher the correlation value, the better the sentence embedding. The strong augmentation, working well for image encoder, is here applied for text encoder. Strong augmentation in SimCSE was implemented by using a strong dropout by increasing dropout rate p to 0.2. The proposed CL via enhancing the instance discrimination is therefore implemented to carry out a new SimCSE through Algorithm 1. The proposed SimCSE performs better than original SimCSE in most of STS tasks. The consistent implementation of CL view in Section 3.3 does improve the performance of CL. The proposed SimCSE performs better than the previous unsupervised methods, and even achieves higher score than supervised baselines by using sentence BERT (SBERT) (Reimers and Gurevych, 2019) and the advanced post-processing techniques on top of SBERT such as SBERT-flow (Li et al., 2020a) and SBERT-whitening (Su et al., 2021). The improvement was obtained by holding the consistencies in class definition and augmentation bias between CL and AT, which could build a robust model to generalize in test phase.
Comparison of Spearman’s rank correlation on the proposed method without/with AT compared to the previous methods. The last four rows show our results.Supervised (S) and unsupervised (U) settings were evaluated on STS datasets
| Methods | S/U | STS12 | STS13 | STS14 | STS15 | STS16 | STSB | SICKR | Avg. |
|---|---|---|---|---|---|---|---|---|---|
| SBERT (Reimers and Gurevych, 2019) | S | 70.97 | 76.53 | 73.19 | 79.09 | 74.30 | 77.03 | 72.91 | 74.89 |
| SBERT-flow (Li et al., 2020a) | S | 69.78 | 77.27 | 74.35 | 82.01 | 77.46 | 79.12 | 76.21 | 76.60 |
| SBERT-whitening (Su et al., 2021) | S | 69.65 | 77.57 | 74.66 | 82.27 | 78.39 | 79.52 | 76.91 | 77.00 |
| BERT (Devlin et al., 2019) | U | 39.70 | 59.38 | 49.67 | 66.03 | 66.19 | 53.87 | 62.06 | 56.70 |
| CT-BERT (Carlsson et al., 2021) | U | 61.63 | 76.80 | 68.47 | 77.50 | 76.48 | 74.31 | 69.19 | 72.05 |
| ConSERT (Yan et al., 2021) | U | 64.64 | 78.49 | 69.07 | 79.72 | 75.95 | 73.97 | 67.31 | 72.74 |
| SG-BERT (Kim et al., 2021) | U | 66.84 | 80.13 | 71.23 | 81.56 | 77.17 | 77.23 | 68.16 | 74.62 |
| SimCSE (Gao et al., 2021) | U | 68.40 | 82.41 | 74.38 | 80.91 | 78.56 | 76.85 | 72.23 | 76.25 |
| SimCSE* | U | 67.38 | 81.29 | 73.15 | 80.95 | 78.01 | 77.04 | 70.35 | 75.45 |
| Ours (SimCSE, ) | U | 68.79 | 80.83 | 73.38 | 81.60 | 78.92 | 78.20 | 72.89 | 76.37 |
| Ours (SimCSE, ) | U | 70.30 | 80.97 | 73.33 | 82.05 | 79.35 | 78.88 | 71.69 | 76.65 |
| Ours (SimCSE, ) | U | 70.19 | 81.97 | 73.96 | 81.72 | 79.24 | 78.28 | 71.81 | 76.74 |
| Ours (AT, ) | U | 71.67 | 82.45 | 74.32 | 82.92 | 80.02 | 79.95 | 73.29 | 77.80 |
| Methods | S/U | STS12 | STS13 | STS14 | STS15 | STS16 | Avg. | ||
|---|---|---|---|---|---|---|---|---|---|
| S | 70.97 | 76.53 | 73.19 | 79.09 | 74.30 | 77.03 | 72.91 | 74.89 | |
| SBERT-flow ( | S | 69.78 | 77.27 | 74.35 | 82.01 | 77.46 | 79.12 | 76.21 | 76.60 |
| SBERT-whitening ( | S | 69.65 | 77.57 | 74.66 | 82.27 | 78.39 | 79.52 | 76.91 | 77.00 |
| U | 39.70 | 59.38 | 49.67 | 66.03 | 66.19 | 53.87 | 62.06 | 56.70 | |
| CT-BERT ( | U | 61.63 | 76.80 | 68.47 | 77.50 | 76.48 | 74.31 | 69.19 | 72.05 |
| ConSERT ( | U | 64.64 | 78.49 | 69.07 | 79.72 | 75.95 | 73.97 | 67.31 | 72.74 |
| SG-BERT ( | U | 66.84 | 80.13 | 71.23 | 81.56 | 77.17 | 77.23 | 68.16 | 74.62 |
| SimCSE ( | U | 68.40 | 82.41 | 74.38 | 80.91 | 78.56 | 76.85 | 72.23 | 76.25 |
| SimCSE* | U | 67.38 | 81.29 | 73.15 | 80.95 | 78.01 | 77.04 | 70.35 | 75.45 |
| Ours (SimCSE, | U | 68.79 | 80.83 | 73.38 | 81.60 | 78.92 | 78.20 | 72.89 | 76.37 |
| Ours (SimCSE, | U | 70.30 | 80.97 | 73.33 | 82.05 | 79.35 | 78.88 | 71.69 | 76.65 |
| Ours (SimCSE, | U | 70.19 | 81.97 | 73.96 | 81.72 | 79.24 | 78.28 | 71.81 | 76.74 |
| Ours (AT, | U | 71.67 | 82.45 | 74.32 | 82.92 | 80.02 | 79.95 | 73.29 | 77.80 |
Next, looking at the results by using the proposed AT relative to those of previous CL methods including BERT (Devlin et al., 2019), CT-BERT (Carlsson et al., 2021), ConSERT (Yan et al., 2021), SG-BERT (Kim et al., 2021) and SimCSE (Gao et al., 2021), it is meaningful that the proposed two-view self-supervised AT via and can improve the performance by using the adversarial sentence encoder. In average, the proposed self-supervised AT even performs better than the advanced post processing method via whitening (SBERT-whitening) (Su et al., 2021) which is seen as the supervised SBERT (Reimers and Gurevych, 2019). This is because that AT is capable of improving the model by using adversarial or worst-case examples in the training. Similar to standard data augmentation, these examples improve the representation by enhancing the model generalization. The proposed AT performs better than the proposed SimCSE with one view via p and with two views via and .
In addition, Table 8 shows the Spearman’s rank correlation of different methods on the validation set and test set where STSB data set (Cer et al., 2017) was used. In the experiments, since the final checkpoint is selected based on the best performance of the validation set, such a saved checkpoint is fitted to the set but the overfitting problem may likely occur. When investigating the difference between the performance on validation and test sets, it is found that the proposed SimCSE can reduce the difference between the results on two sets and accordingly alleviate the effect of overfitting. Using the proposed AT, such an effect is further released as the performance gap between two sets is reduced. This effect coincides with that found in the first work (Miyato et al., 2017) on using AT in different natural language tasks.
Top-10 similar sentences given a query sentence
| Query: gray cat looking out the window (STSB data set) | |
|---|---|
| BERT | 1. A cat looking out of a window |
| 2. Two cats are looking at a window | |
| 3. Black and white dog in living room standing on… | |
| 4. A rooster pecks at a dead mouse | |
| 5. A black dog running along the edge of the ocean | |
| 6. A brown dog squatting on grass | |
| 7. A dog closes a refrigerator door | |
| 8. A black and white cat laying on the ground in the… | |
| 9. A man looks out the window | |
| 10. Cow walking under the tree in a pasture | |
| SBERT | 1. A cat looking out of a window |
| 2. A cat, perched on a table, looks out the window | |
| 3. The cat is standing on the window sill looking… | |
| 4. A man looks out the window | |
| 5. The sheep is standing under the trees | |
| 6. The white train is sitting on the tracks | |
| 7. A small black and white goat in a pen looking up… | |
| 8. Two cats are looking at a window | |
| 9. The train is riding on the tracks in the snow | |
| 10. Close up of a white sheep with a black head | |
| Ours (SimCSE) | 1. A cat is rubbing against a baby |
| 2. A cat looking out of a window | |
| 3. A cat is playing with a camera | |
| 4. A cat is playing on the floor | |
| 5. A cat and a boy play together | |
| 6. A tiger is walking around | |
| 7. A brown dog running through the grass | |
| 8. A grey cat with green eyes looking into the camera | |
| 9. A cat is licking a small bottle | |
| 10. A black and white cat playing with a blanket | |
| Ours (AT) | 1. A cat looking out of a window |
| 2. A cat is playing on the floor | |
| 3. A cat is playing with a camera | |
| 4. A cat is rubbing against a baby | |
| 5. A cat and a boy play together | |
| 6. The cat teased the dog by touching his head | |
| 7. A cat is playing | |
| 8. A grey cat with green eyes looking into the camera | |
| 9. A cat looking at the camera | |
| 10. A person throws a cat on the ceiling | |
| Query: gray cat looking out the window ( | |
|---|---|
| 1. A cat looking out of a window | |
| 2. Two cats are looking at a window | |
| 3. Black and white dog in living room standing on… | |
| 4. A rooster pecks at a dead mouse | |
| 5. A black dog running along the edge of the ocean | |
| 6. A brown dog squatting on grass | |
| 7. A dog closes a refrigerator door | |
| 8. A black and white cat laying on the ground in the… | |
| 9. A man looks out the window | |
| 10. Cow walking under the tree in a pasture | |
| 1. A cat looking out of a window | |
| 2. A cat, perched on a table, looks out the window | |
| 3. The cat is standing on the window sill looking… | |
| 4. A man looks out the window | |
| 5. The sheep is standing under the trees | |
| 6. The white train is sitting on the tracks | |
| 7. A small black and white goat in a pen looking up… | |
| 8. Two cats are looking at a window | |
| 9. The train is riding on the tracks in the snow | |
| 10. Close up of a white sheep with a black head | |
| Ours (SimCSE) | 1. A cat is rubbing against a baby |
| 2. A cat looking out of a window | |
| 3. A cat is playing with a camera | |
| 4. A cat is playing on the floor | |
| 5. A cat and a boy play together | |
| 6. A tiger is walking around | |
| 7. A brown dog running through the grass | |
| 8. A grey cat with green eyes looking into the camera | |
| 9. A cat is licking a small bottle | |
| 10. A black and white cat playing with a blanket | |
| Ours ( | 1. A cat looking out of a window |
| 2. A cat is playing on the floor | |
| 3. A cat is playing with a camera | |
| 4. A cat is rubbing against a baby | |
| 5. A cat and a boy play together | |
| 6. The cat teased the dog by touching his head | |
| 7. A cat is playing | |
| 8. A grey cat with green eyes looking into the camera | |
| 9. A cat looking at the camera | |
| 10. A person throws a cat on the ceiling | |
The performance of sentence embedding is further demonstrated by Table 9 where ten most similar sentences given a query sentence “Gray cat looking out the window” are shown by using BERT (Devlin et al., 2019), SBERT (Reimers and Gurevych, 2019) and the proposed SimCSE and AT. The semantically related words are marked by blue. Generally, using BERT, SBERT and the proposed SimCSE, there are four, five and eight sentences related to the subject of query sentence with the important word “cat.” It can be seen that the proposed self-supervised AT retrieves top-10 similar sentences which are all related to the query sentence. In combination with the dropout on both anchor and class features, the perspective of viewing CL as a classification task is implemented in the proposed SimCSE. Relative to SimCSE, applying perturbations for two views and on anchor and class features for CL, respectively, by using the proposed AT does obtain the improvement.
Comparison of Spearman’s rank correlation on validation and test sets, and their difference on STSB dataset
| Methods | Validation set | Test set | Difference |
|---|---|---|---|
| SimCSE (Gao et al., 2021) | 82.09 | 77.04 | −5.05 |
| Ours (SimCSE) | 82.92 | 78.88 | −4.04 |
| Ours (AT) | 83.78 | 79.95 | −3.83 |
| Methods | Validation set | Test set | Difference |
|---|---|---|---|
| SimCSE ( | 82.09 | 77.04 | −5.05 |
| Ours (SimCSE) | 82.92 | 78.88 | −4.04 |
| Ours ( | 83.78 | 79.95 | −3.83 |
This paper extends the experiments on text representation by evaluating the classification accuracy using two-view CL and two-view AT under the other adversarial perturbations such as TextFooler (Jin et al., 2020) and BERT-Attack (Li et al., 2020b). Table 10 shows the results of RA and SA by using different methods where sentiment classification tasks using Yelp and IMDB (Jin et al., 2020; Li et al., 2020b) are evaluated under the attacks of TextFooler and BERT-Attack. In this evaluation, the experimental settings and the BERT results (Devlin et al., 2019) of these two tasks under two different attacks are referred to those in Jin et al. (2020) and Li et al. (2020b). The results of using CL based on SimCSE (Gao et al., 2021), two-view CL based on our SimCSE with and two-view AT based on our AT with are included in the comparison. The settings of CL, two-view CL and two-view AT are the same as those of sentence embedding. It is found that two-view CL and two-view AT considerably increase RA under two different attacks in two different tasks when compared with baseline BERT and standard CL although the highest standard accuracies in two tasks are obtained by SimCSE. The highest robust accuracies are consistently achieved by using the proposed two-view AT.
5. Conclusions
This paper has presented the connection between the instance discrimination in CL and the classification task in SL, which aims to address potential inconsistencies of class definition in instance discrimination for CL and distribution view in data augmentation between CL and AT. Using this CL framework, a unified perspective for self-supervised AT was exploited. CL was reformulated as a self-supervised classification task. The instance discrimination was enhanced and extended to carry out the self-supervised variant of AT from an existing supervised AT method. A new CL was also developed. The experiments on image classification, sentence embedding and sentiment classification showed that the proposed AT achieved competitive results on robust performance while considerably reducing the time and memory complexities. The resulting sentence encoder in self-supervised mode even outperformed the other supervised methods. This paper works toward a unified solution for supervised and self-supervised AT. The scalability of implementing the proposed method needs further study in the future.
Comparison of RA (%) and SA (%) using BERT, SimCSE, two-view CL (our SimCSE) and two-view AT (our AT) under adversarial perturbations of TextFooler and BERT-Attack. Yelp and IMDB datasets are evaluated
| Perturbations | Methods | Yelp | IMDB | ||
|---|---|---|---|---|---|
| RA | SA | RA | SA | ||
| TextFooler (Jin et al., 2020) | BERT (Devlin et al., 2019; Li et al., 2020b) | 6.6 | 95.6 | 13.6 | 90.9 |
| SimCSE (Gao et al., 2021) | 7.9 | 96.4 | 15.7 | 92.0 | |
| Ours (SimCSE) | 20.3 | 95.1 | 23.8 | 88.3 | |
| Ours (AT) | 35.3 | 94.5 | 39.3 | 87.9 | |
| BERT-Attack (Li et al., 2020b) | BERT (Devlin et al., 2019; Li et al., 2020b) | 5.1 | – | 11.4 | – |
| SimCSE (Gao et al., 2021) | 6.7 | – | 13.7 | – | |
| Ours (SimCSE) | 18.4 | – | 20.4 | – | |
| Ours (AT) | 31.9 | – | 35.3 | – | |
| Perturbations | Methods | Yelp | |||
|---|---|---|---|---|---|
| TextFooler ( | 6.6 | 95.6 | 13.6 | 90.9 | |
| SimCSE ( | 7.9 | 96.4 | 15.7 | 92.0 | |
| Ours (SimCSE) | 20.3 | 95.1 | 23.8 | 88.3 | |
| Ours ( | 35.3 | 94.5 | 39.3 | 87.9 | |
| BERT-Attack ( | 5.1 | – | 11.4 | – | |
| SimCSE ( | 6.7 | – | 13.7 | – | |
| Ours (SimCSE) | 18.4 | – | 20.4 | – | |
| Ours ( | 31.9 | – | 35.3 | – | |
Jen-Tzung Chien is currently the Lifetime Chair Professor in National Yang Ming Chiao Tung University, Taiwan. He has authored more than 300 peer-reviewed articles in machine learning, natural language processing and computer vision, and three books including Bayesian Speech and Language Processing, Cambridge University Press, 2015, Source Separation and Machine Learning, Academic Press, 2018, and Machine Learning for Speaker Recognition, Cambridge University Press, 2020. He was a Tutorial Speaker of AAAI, IJCAI, ACL, MM, KDD, ICASSP, CIKM, WSDM, COLING and Interspeech. He received the Best Paper Award in the IEEE Workshop on Automatic Speech Recognition and Understanding in 2011, and the IEEE International Workshop on Machine Learning for Signal Processing in 2023. He serves as an Elected Member of the IEEE Machine Learning for Signal Processing Technical Committee and the IEEE Speech and Language Processing Technical Committee, and the Associate Editor of the IEEE Transactions on Audio, Speech and Language Processing.
Yuan-An Chen received his BS and MS degrees from National Taiwan University of Science and Technology and National Yang Ming Chiao Tung University in 2019 and 2021, respectively, both in electrical and computer engineering. His interests include adversarial learning, contrastive learning and image representation.

