Elamur Research

RobustEmbed: Robust Sentence Embeddings Using Self-Supervised Contrastive Pre-Training

Paper · 2023 · Javad Asl, Eduardo Blanco and Daniel Takabi

Summary

A sentence embedding is a vector that represents a sentence. Ideally, two sentences with much the same meaning receive nearby vectors, and a classifier can use those vectors to make consistent decisions. But an embedding can do well on ordinary examples and still change enough under a carefully chosen edit to reverse a prediction. RobustEmbed asks whether an encoder can learn to resist such changes while preserving the information that makes its vectors useful for semantic similarity and text classification.

The authors continue training an existing encoder on randomly sampled Wikipedia sentences. They pass each sentence through the encoder with different dropout masks, which gives them distinct views of the same input. They also create a harder view by adding a bounded numerical perturbation to the input’s internal vectors. The perturbation is chosen to make it difficult for the encoder to recognize the resulting representation as another view of the same sentence. Training then reverses that pressure. It teaches the encoder to bring the clean and perturbed representations together while distinguishing them from representations of other sentences in the batch. The process uses the identity of the original sentence as supervision, so it does not require people to label paraphrases or write adversarial examples.

With BERT base, RobustEmbed reaches an average Spearman correlation of 77.51 across seven clean similarity benchmarks, compared with 76.31 for USCAL. The authors report a margin of 1.20% on that comparison. On six clean transfer tasks, a classifier using fixed RobustEmbed vectors averages 86.20 accuracy, compared with 85.80 for USCAL, a margin the authors report as 0.40%. RobustEmbed also has the highest average similarity and transfer scores among the reported systems using either RoBERTa base or RoBERTa large, although the winner varies by individual dataset.

The larger changes appear in the robustness tests. Across seven classification and inference tasks, the average BERTAttack success rate is 39.62% with RobustEmbed, 58.62% with USCAL, and 75.51% with SimCSE. RobustEmbed has the lowest reported success rate for each of the five attack methods on every task in that comparison. The authors also introduce Adversarial Semantic Textual Similarity, where altered sentence pairs test the similarity judgment itself. RobustEmbed again has the lowest reported attack success rates. Together, these results show that training with numerical perturbations can improve resistance to the text edits used in the experiments, while the clean evaluations show that the resulting vectors retain their usefulness.

Deep dive: RobustEmbed: Robust Sentence Embeddings Using Self-Supervised Contrastive Pre-Training

RobustEmbed trains sentence embeddings to withstand deliberate changes and tests whether they still capture meaning on clean and altered text. · about 35 minutes to read

The problem and its context

A useful sentence vector has to do more than one job

A sentence encoder compresses a sequence of words into a vector that another system can use. One application compares vectors to find sentences with similar meanings. Another gives the vector to a classifier, which learns to predict a label such as positive or negative sentiment. The advantage of the shared representation is that people can reuse the work of encoding the sentence. The vector needs to carry enough information for decisions that the encoder may never have been trained to make directly.

The authors distinguish two qualities of that representation. Generalization concerns whether the vectors are useful on examples and tasks beyond the data used to learn them. Robustness concerns whether a small, deliberately chosen alteration can make a system using those vectors give a different or worse answer. A sentence about a film can express the same opinion after a word substitution. If the resulting text is still clearly favorable to a reader but the classifier reverses its judgment, an evaluation on ordinary reviews alone would miss that failure.

These demands can pull in different directions. The encoder needs to preserve differences that matter, including differences between sentences that share much of their wording. It also needs to tolerate differences that leave the decision intact. If every sentence received nearly the same vector, nearby vectors would be easy to obtain even after an edit, but the vectors would carry little information for a classifier or a similarity comparison. If every small change produced a very different vector, it would be easy to distinguish inputs, but shared meaning could become hard to recover. The question is which distinctions the representation learns to preserve.

The paper situates this question in the development of word embeddings. Early work drew on the idea that the contexts in which words appear provide evidence about their meaning. The authors cite work on learning word representations from context and on distributed representations of words and phrases. Contextual encoders such as BERT extended the approach by producing representations that depend on the surrounding text. Learning a sentence embedding adds a further requirement. A vector derived from the whole input must be useful at the level of the sentence, whether the task involves comparing meanings or predicting a category.

The paper places RobustEmbed alongside earlier approaches to broadly reusable sentence vectors, including Doc2vec, SkipThought, the Universal Sentence Encoder, and Sentence-BERT. The authors describe progress from both supervised and unsupervised approaches. Their rationale for another training procedure is that downstream usefulness, by itself, leaves the behavior under deliberate edits open. An encoder can produce vectors that separate ordinary positive reviews from ordinary negative ones while still leaving some decisions sensitive to changes that preserve the intended label.

How earlier work created useful comparisons

Contrastive learning supplies a way to shape the vector space using comparisons. For a given input, the training objective identifies a related example as a positive and treats other examples as negatives. It rewards assigning the positive greater similarity to the input. Training across many such comparisons makes the choice of positives important. They express which changes the encoder is expected to tolerate. The negatives provide the pressure to keep instances distinguishable.

The paper draws on SimCLR, a contrastive approach to visual representations, for this general construction. Sentence encoders face a different choice of views. Changing some values in a vector is straightforward. Changing a word in a sentence can affect both its grammatical role and its meaning. For self-supervised training, a simple way to get a reliable positive is to leave the text alone and change what happens inside the encoder.

That is the strategy the authors describe in SimCSE. The same sentence is processed with separate dropout masks. Dropout suppresses selected activations during training, so the two passes can produce different vectors even though their source text is identical. The known relationship is their common origin. The rest of the batch supplies examples against which the encoder must identify the matching view.

ConSERT explores a broader set of changes. As the paper describes it, these include shuffling tokens and cutting off part of the representation, as well as dropout and adversarial perturbation. The examples illustrate two distinct choices a training method must make. It needs a way to construct different views, and it needs an objective that specifies how those views should relate to one another. More varied views give the encoder more differences to handle. Whether that helps depends on what information the variation leaves intact and where the objective places the resulting vectors.

The paper also discusses approaches that pair adversarial training with contrastive learning. CARL seeks resilience in sentence representations, while RAR focuses on individual words. Rima and colleagues perturb input embeddings and use a contrastive objective to bring the resulting representations closer to the originals. Pan and colleagues apply related ideas when adapting a transformer encoder to a task. The line of work already supplied the basic ingredients for RobustEmbed. The authors’ changes concern how the difficult view is generated during sentence-embedding training and how the objective connects it to the clean views.

Why the training perturbation lives inside the encoder

The paper’s account of adversarial examples starts from a deliberate choice of disturbance. Random variation can reveal ordinary sensitivity. A disturbance chosen to increase the current error can reveal directions of particular sensitivity. Goodfellow and colleagues’ work on adversarial examples and Madry and colleagues’ work on adversarial training supply the background for searching for such disturbances and then training on them.

Text makes that search awkward because its input symbols are discrete. A small change in a continuous coordinate can be made in the direction indicated by a gradient. A small movement away from a written word has no comparable definition. A substitution requires choosing another word or piece of a word, and an apparently modest change in spelling or vocabulary can change what the sentence says. The paper describes earlier work that moves the search to the embedding space, where gradients can guide the search and a numerical bound can control the size of the change.

This distinction gives RobustEmbed its central empirical question. During training, the difficult example is manufactured in a continuous representation. The evaluation then asks how much of that learned stability carries over when a system receives edited text. Small changes in the training space and small changes to a sentence are different objects. The method provides a reason to expect some transfer between them, and the attack benchmarks are where the authors test that expectation.

The method, step by step

From a sentence to several views

RobustEmbed starts from the weights of a pretrained encoder. Its job is to adapt that encoder so it produces sentence vectors with the relationships the authors want. The training corpus consists of 10⁶ randomly sampled English Wikipedia sentences supplied through SimCSE. The learning signal comes from the identity of each sentence. There is no need to know whether a sentence is positive, subjective, or a paraphrase of another sentence in the corpus.

For each batch, the encoder processes the same source sentences with separate dropout masks. The first pass supplies the clean anchor, the representation from which a comparison is made. The other pass supplies its ordinary positive. They are related because they come from the same text. The encoder then gets a harder version of the anchor by changing the numerical input representation within a bound. It must learn that this version is related to the anchor too.

It helps to distinguish the vectors at the two ends of the encoder. The training perturbation acts on sub-word embeddings, the representations through which the input’s pieces enter the encoder. The contrastive objective compares sentence embeddings, the vectors that come out for whole examples. For the latter, RobustEmbed takes the contextual representation at the special [CLS] position and puts a pooler layer on top. The resulting sentence vector is what the similarity function compares. Changing the sub-word representations can affect that output through the encoder.

The inner search and the final training update use the same discrepancy for different purposes. During the search, the encoder’s parameters define the current geometry. The procedure changes the input’s numerical representation to make the ordinary positive harder to recognize. During the update, the hard view becomes part of the positive set. Training changes the encoder so that it can recognize the relationship even with the perturbation present. The negatives still matter at that stage because improving the positive comparisons requires making them stand out against other sentences.

How RobustEmbed trains the sentence encoder

The steps in order.

How RobustEmbed trains the sentence encoderStep 1: Sample a batch of Wikipedia sentences1. Sample a batch of Wikipedia sentencesStep 2: Obtain clean views with separate dropout masks2. Obtain clean views with separate dropout masksStep 3: Search for difficult bounded perturbations3. Search for difficult bounded perturbationsStep 4: Combine the perturbations into a hard view4. Combine the perturbations into a hard viewStep 5: Compare the clean anchor with both positives5. Compare the clean anchor with both positivesStep 6: Compare the hard view with the dropout positive6. Compare the hard view with the dropout positiveStep 7: Update the encoder using the combined loss7. Update the encoder using the combined loss

What the contrastive objective measures

The paper begins with the usual contrastive comparison. An encoder sees an anchor, its known counterpart, and other candidates. It should score the counterpart highly relative to those candidates. The aim is relational. There is no target coordinate that a particular sentence vector has to occupy, and no target coordinate for an individual word. The positive supplies a reference for the anchor, and the negatives set the level of competition.

The score used in the loss is cosine similarity. It compares the directions of two vectors after accounting for their lengths.

sim(u, v) = (uᵀv) / (∥u∥ · ∥v∥)

Here sim is the similarity function. u and v are sentence vectors. The superscript ᵀ denotes a transpose, so uᵀv is their dot product. ∥u∥ and ∥v∥ are their Euclidean lengths, · denotes multiplication, and / denotes division. Vectors pointing in similar directions receive a higher cosine score. The norm in this similarity formula serves to account for vector length. The norm used to bound the perturbation serves a different purpose.

The authors describe a batch with N positive pairs. For the pair indexed by i, the input views are xᵢ and xᵢ⁺, with corresponding sentence vectors zᵢ and zᵢ⁺. The superscript ⁺ marks the related view. To write the loss clearly when there can be several positives, let Pᵢ contain the positive vectors for anchor zᵢ, and let Qᵢ contain the negative vectors. In the standard case discussed by the paper, the only member of Pᵢ is zᵢ⁺. Other instances’ representations supply Qᵢ.

Lcon,θ(xᵢ, Pᵢ, Qᵢ) = −log((∑p∈Pᵢ exp(sim(zᵢ, p) / τ)) / (∑v∈Pᵢ∪Qᵢ exp(sim(zᵢ, v) / τ)))

Lcon,θ is the contrastive loss under encoder parameters θ. The input view xᵢ yields anchor vector zᵢ. The index i identifies the current pair in the batch. p ranges over Pᵢ, and v ranges over Pᵢ∪Qᵢ, the union of the positive and negative sets. ∑ means to sum over the indicated set, and ∈ means membership. sim is cosine similarity, τ is a temperature that controls how sharply differences in similarity affect the weights, and exp turns each scaled score into a positive weight. log is the logarithm. The leading minus sign makes the loss smaller when the positives receive a larger share of the weight.

The denominator gives a positive its meaning as a successful comparison. If a candidate receives a high similarity but so does every other candidate, it has little advantage. The loss can fall by making a true positive more similar to the anchor or by giving competing instances less weight. Over a batch, the objective uses the comparisons for all the positive pairs. RobustEmbed changes which views count as positives and which views need to act as anchors.

An important detail is that the displayed loss pools the positive weights in its numerator. It does not specify a separate target score for each pair of positive views. In particular, both positives can receive weight from their comparisons with the clean anchor without the objective directly scoring their similarity to each other. RobustEmbed’s additional loss supplies that missing comparison explicitly.

How the difficult view is chosen

The paper first describes the general adversarial objective in a labeled setting. Suppose an encoder or predictor is currently given the sub-word embeddings for a sentence and has a truth label against which its output can be judged. The inner problem looks for the bounded perturbation that makes the loss large.

arg maxδ:∥δ∥≤ϵ L(fθ(X + δ), y)

arg max asks for a choice of δ that maximizes the expression. δ is the perturbation, ∥δ∥ is its size under the chosen norm, ≤ specifies the constraint, and ϵ is the radius of the permitted region. X is the sub-word embedding input, and X + δ adds the perturbation to it. fθ is the encoder or predictor with parameters θ, y is the truth label in this background example, and L measures the discrepancy between the prediction and that label. The search varies δ while the parameters that define the predictor are held fixed for the comparison.

RobustEmbed replaces the labeled loss in that construction with a contrastive one. The known target is the other dropout view of the same sentence. If the perturbed anchor has trouble distinguishing that target from other examples, the contrastive loss is high. The perturbation search therefore has a training signal even when the sentence has no task label.

The algorithm uses X for the first dropout branch and X⁺ for the matching branch. In expressions for the search, the paper writes the contrastive loss using these branch inputs as arguments. The actual cosine comparisons concern the sentence representations obtained from the branches. The search starts from a Gaussian perturbation as follows.

δ₁ ∼ 𝒩(0, σ²I)

δ₁ is the initial perturbation. ∼ means it is drawn from the indicated distribution. 𝒩 denotes a Gaussian distribution, 0 is its mean, σ² is the variance scale, and I is the identity matrix in the covariance. The subscript marks the initial state of the iterative search. The subsequent updates enforce the norm constraint by projection.

At an intermediate state, the change in loss with respect to the perturbation determines the search direction.

g(δₙ) = ∇δ Lcon,θ(X + δₙ, {X⁺})

g is the function that gives the gradient at perturbation δₙ, where n indexes the current iteration of a search. ∇δ means differentiation with respect to the perturbation, and Lcon,θ is the contrastive loss for the current encoder parameters θ. X + δₙ is the perturbed anchor branch and {X⁺} is its positive set, containing the other clean dropout branch. The competing candidates from the batch are implicit here. The gradient indicates which local changes to the perturbation would increase the loss.

The authors use two iterative update rules. In the projected-gradient branch, the gradient determines a direction and is divided by its norm. The algorithm scales the result by a step size, adds it to the current perturbation, and projects back into the permitted region.

δpgd,ₖ₊₁ = Π∥δ∥P≤ϵ(δₖ + αg(δₖ) / ∥g(δₖ)∥P)

δpgd,ₖ₊₁ is the next perturbation in the projected-gradient branch, and k indexes its current iteration. δₖ is the current perturbation, g(δₖ) its contrastive-loss gradient, and ∥·∥P the norm of order P, applied here to scale the gradient and to define the constraint. α sets the step size. Π∥δ∥P≤ϵ projects the proposed perturbation onto the region in which its norm is at most ϵ. Although the branch takes its name from Projected Gradient Descent, this update moves in the direction of increasing loss because the inner search is a maximization.

The other rule uses the sign of the gradient. The sign retains the direction of change for each coordinate, with the step size setting the scale of the proposed move.

δfgsm,ₜ₊₁ = Π∥δ∥P≤ϵ(δₜ + βsign(g(δₜ)))

δfgsm,ₜ₊₁ is the next perturbation in the branch based on the Fast Gradient Sign Method. t indexes that branch’s iteration and δₜ is its current state. g(δₜ) is the contrastive-loss gradient at that state, sign takes the sign of each component, and β supplies the step size. Π∥δ∥P≤ϵ is the same kind of projection, using norm order P and radius ϵ. The paper applies this update iteratively. With the selected L∞ constraint, the radius bounds the largest absolute coordinate of the perturbation.

The two expressions make it possible to see where the branches differ. One uses a normalized gradient, retaining differences in the relative sizes of its components. The other uses componentwise signs. The branches can also use different step sizes and numbers of iterations. The numerical search is an approximation to the maximization objective. The procedure ends after its allocated steps, taking the resulting difficult directions as training material.

The method combines the terminal perturbations before making the final hard view.

δfinal = λδpgdᴷ + (1 − λ)δfgsmᵀ

δfinal is the perturbation used in the training loss. δpgdᴷ is the result of the projected-gradient branch after its K steps, and δfgsmᵀ is the result of the sign-gradient branch after its T steps. λ is the mixing weight, with 0 ≤ λ ≤ 1. The coefficient 1 − λ supplies the remaining weight to the sign-gradient result. This operation blends the input perturbations themselves. The encoder then processes the resulting hard branch as a single view. Since both inputs to the blend lie within the same norm ball, their weighted average stays within that ball.

How the encoder learns from the hard view

The motivation is a minimax problem. The inner search tries to find a bad perturbation for the current encoder. The outer training procedure changes the encoder so that the loss under difficult perturbations becomes smaller.

arg minθ 𝔼x∼D[max∥δ∥≤ϵ Lcon,θ(X + δ, {X⁺})]

arg minθ seeks encoder parameters θ that minimize the objective. 𝔼x∼D denotes an expectation over sentences x drawn from training data D. The inner max seeks the greatest loss within the perturbation budget ∥δ∥ ≤ ϵ, with δ measured in the chosen norm and ϵ the radius. X + δ is the altered anchor branch and {X⁺} contains its positive counterpart. Lcon,θ again denotes the contrastive loss, with other batch examples implicit. The displayed objective describes the training aim. In practice, a finite search supplies the adversarial example for the contrastive update.

For that update, the method puts the dropout positive and the hard view in the clean anchor’s positive set. The paper writes the objective in terms of views of a single input.

LRobustEmbed,θ = Lcon,θ(x, {xpos, xadv})

LRobustEmbed,θ is the main RobustEmbed loss for encoder parameters θ, and Lcon,θ is the same contrastive comparison defined earlier. x is the clean anchor view, xpos the positive obtained with the other dropout mask, and xadv the view generated by applying δfinal. The braces give the positive set for x. Other batch instances still act as negatives. The perturbation that made matching difficult during the search is now included among the matches that training should reward.

This loss compares the clean anchor with both alternatives. The authors also want the alternatives to agree directly. An ordinary dropout view and an adversarial view can each have a relationship with the anchor while still lying farther from one another than desired. To address that distinction, the loss includes a separate comparison with the hard view as the anchor and the dropout view as its positive.

Ltotal = LRobustEmbed,θ + γLcon,θ(xadv, {xpos})

Ltotal is the loss used for the encoder update. LRobustEmbed,θ is the main term. γ is the regularization weight, and the second Lcon,θ compares adversarial anchor xadv with positive xpos, using the other instances as competitors. The sum gives both comparisons a role in training. Raising γ increases the direct influence of the hard-to-dropout comparison relative to the main loss.

The algorithm closes the batch step by changing the encoder parameters in the direction of lower total loss.

θ ← θ − η∇θ Ltotal

θ is the set of trainable encoder parameters, ← means assignment, and η is the learning rate for the outer update. ∇θ differentiates Ltotal with respect to the encoder parameters. The subtraction moves the parameters opposite the loss gradient. The inner steps use α and β to change the input perturbation, while this step uses η to change what the encoder does with its inputs.

Which choices were used in training

The authors initialize the encoder from BERT or RoBERTa. They train for 2 epochs and evaluate checkpoints every 250 training steps. The training description says they choose the final checkpoint by its highest average STS score. For transfer tasks, they choose hyper-parameters by averaging scores on the development sets of the six tasks. The encoder thus learns its contrastive comparisons from unlabeled sentences, while evaluation scores guide the selection of settings and checkpoints.

The reported training uses batch sizes of 64 or 128. Batch size determines how many examples are available together, so it also bears on the pool of negatives. The authors report an average training time of 2-4 hours. Their chosen perturbation setup uses the L∞ norm, α = 1e-5, β = 1e-3, and K = T with 5 steps in each branch. They use λ = 0.5 for the blend and γ = 1/128 for the added loss. The sensitivity comparisons explain how those values were selected and how much of that selection relied on clean similarity scores.

The authors make the implementation available under the name RobustEmbed Repository. The core training input is the Wikipedia sentence sample distributed by SimCSE. Similarity labels, transfer labels, and the edited texts used in the robustness experiments enter at different stages of evaluation. Keeping those roles distinct matters for interpreting what the self-supervised stage learned.

Experiments and results

Clean similarity with fixed sentence vectors

The first evaluation checks whether vectors reflect the degree of similarity people assign to sentence pairs. The tasks are the annual STS datasets from 2012–2016, STS Benchmark, and SICK-Relatedness. In the clean STS evaluation, the sentence embeddings stay fixed and no regressor is trained on the benchmark pairs. The comparison therefore tests the similarities available from the learned representation without fitting a task-specific function to those pairs.

The reported score is Spearman correlation in the paper’s “all” setting. Spearman correlation measures agreement in rankings. If people rate one pair as more similar than another, the evaluation favors an encoder that puts those pairs in the same relative order. A high score therefore establishes good ordering under this test. The evaluation does not require the raw vector similarities to match the numerical scale of the human scores. This is a direct test of the geometry that RobustEmbed changes during training.

The baselines span several ways of making a sentence vector. One averages GloVe embeddings, and another averages representations from the first and last BERT layers. BERT-flow and BERT-whitening apply post-processing to the representations. The comparison with learned sentence encoders includes ConSERT and ATCL, along with SimCSE and USCAL. For the latter group, the authors report reproducing SimCSE, ConSERT, and USCAL using their own encoder configurations. The table distinguishes those reruns from several earlier baseline scores carried over from other papers.

BERT-base sentence encoders on seven clean STS tasks, average Spearman correlation

RobustEmbed scores highest among the reported approaches using the same base encoder.

BERT-base sentence encoders on seven clean STS tasks, average Spearman correlationBERT first-last average: 56.70BERT first-last average56.70BERT-whitening: 66.28BERT-whitening66.28BERT-flow: 66.55BERT-flow66.55ConSERT: 72.75ConSERT72.75ATCL: 75.11ATCL75.11SimCSE: 76.06SimCSE76.06USCAL: 76.31USCAL76.31RobustEmbed (this paper): 77.51RobustEmbed (this paper)77.51
The numbers
System or settingSpearman correlation as reported
BERT first-last average56.70
BERT-whitening66.28
BERT-flow66.55
ConSERT72.75
ATCL75.11
SimCSE76.06
USCAL76.31
RobustEmbed (this paper)77.51

For BERT base, the authors describe the lead over USCAL in average Spearman correlation as 1.20%. Individual tasks show how that average arises. On STS12, RobustEmbed has a Spearman score of 70.52 and USCAL has 69.30. On STS-B, the corresponding scores are 82.97 and 81.28. On SICK-R, they are 73.24 and 71.98. RobustEmbed leads on six of the seven tasks in its encoder group. The exception is STS16, where SimCSE has 78.09 and RobustEmbed has 77.72. The paper’s average improvement is compatible with a reversal on a particular test.

The RoBERTa results ask whether the advantage persists with a different pretrained starting point. With RoBERTa base, the average STS Spearman score is 77.33 for RobustEmbed, 77.08 for USCAL, and 76.30 for SimCSE. RobustEmbed reaches 83.70 on STS-B, compared with USCAL’s 83.34. On STS16, USCAL has 80.55 and RobustEmbed has 79.74. With RoBERTa large, the reported comparison is against USCAL. The average scores are 78.36 for RobustEmbed and 78.11 for USCAL. On SICK-R, the scores are 76.93 and 76.30, respectively. On STS13, USCAL has 81.84 and RobustEmbed has 81.53.

These comparisons address both the training procedure and the starting encoder. Comparing sentence-embedding methods within the same encoder group helps hold the starting architecture and scale constant. Comparing across groups asks whether the procedure can be applied to another initialization and still yield a useful representation. The higher average for the reported RoBERTa large RobustEmbed configuration does not establish that its training advantage is larger. Within-group comparisons provide the evidence for that question.

Transfer with a classifier fitted on top

The next evaluation uses the vectors as features for a new classifier. The authors keep the encoder fixed and fit logistic regression on top of the representations, following the SentEval procedure. The classifier learns from the task labels, while the encoder contributes the features it acquired during pretraining. This places a different demand on the vectors than clean STS. Sentences need to carry information that a classifier can turn into a category, whether or not the examples can be arranged by a single overall similarity judgment.

The transfer datasets cover several kinds of decisions. MR concerns sentiment in movie-review sentences, and CR uses customer-review opinions. SST2 is another sentiment test based on movie reviews, with 8,544 training examples and 2,210 test examples in the paper’s dataset description. SUBJ distinguishes subjective from objective sentences. MPQA concerns opinions in annotated news material. MRPC asks whether the two sentences in a news pair are semantically equivalent. The last task uses relatedness in a categorical way. The classifier has to choose a label for a pair, while the clean STS study measures agreement with a graded ranking. SST sentiment treebank · SUBJ

The reported accuracy is averaged across the six transfer tasks. BERT base with RobustEmbed reaches 86.20. USCAL reaches 85.80, and SimCSE reaches 85.71. The authors report the comparison with the strongest baseline as a margin of 0.40%. The more basic BERT [CLS] embedding has an average of 83.54, and the averaged GloVe baseline has 81.27. Several methods therefore improve substantially on simple sentence features in this evaluation. RobustEmbed’s incremental result is best read alongside the stronger learned encoders.

RobustEmbed has the highest BERT-base transfer accuracy in four of the six tasks. Its MRPC accuracy is 76.40, compared with 75.84 for USCAL. It reaches 87.45 on CR and 89.88 on MPQA. The ranking changes on SUBJ, where USCAL scores 95.24 and RobustEmbed scores 95.04, and on SST2, where SimCSE has 86.70 and RobustEmbed has 86.47. These exceptions are informative because the classifier design is common across the comparison. Different representations can make different properties accessible to the classifier even when their overall accuracies are close.

For RoBERTa base, the average transfer accuracies are 85.27 for RobustEmbed and 85.08 for USCAL. On RoBERTa large, they are 86.08 and 85.85. The pattern again depends on the dataset. With the large encoder, RobustEmbed reaches 77.11 on MRPC while USCAL reaches 76.41, but on MR the scores are 82.38 and 82.84. The clean transfer evidence supports a consistent advantage in the reported averages, with task-specific strengths varying within each encoder comparison.

Robustness after adapting the encoder to a task

The attack evaluation follows a different procedure from the frozen-vector transfer test. Here the authors use fine-tuning to adapt each BERT-based encoder to a particular task and then test the resulting classifier on deliberately altered text. This makes the result relevant to using RobustEmbed as an initialization for a downstream system. The number describes the behavior of the resulting pipeline after task training. The frozen-vector experiments address a separate use of the representation.

Five of the downstream datasets involve classification. The study includes IMDb and YELP reviews, along with MR and SST2. MRPC adds paraphrase identification. The other two datasets involve natural language inference. In such a task, a system receives a premise and a hypothesis and judges whether the premise supports the hypothesis, contradicts it, or leaves it unresolved. The attacks therefore reach beyond sentiment words. They also test whether a prediction about the relation between sentences survives an edit. IMDb reviews · YELP review classification

SNLI uses premises based on image captions. MNLI includes a broader range of text sources. The attack table uses MNLI-Mismatched, whose examples are less similar in source context to the training set than examples in MNLI-Matched. This puts an additional condition on the inference comparison. The attack result is for the mismatched test setting and should be read with that split name attached. SNLI · MultiNLI

The authors use TextAttack to run five named methods. PWWS and TextFooler are based on word replacement, while TextBugger draws on a range of perturbation types. BAE uses replacements or insertions, and BERTAttack can work with words or sub-word units. The methods differ in what changes they try and how they choose them. Running them across the same encoder comparisons tests whether an advantage is confined to one particular recipe. The inputs at this stage are text, even though RobustEmbed’s training perturbations were generated inside the encoder.

The paper reports five runs per experiment with 1000 attack samples each time and averages across the runs. The metric in the main attack table is attack success rate. A smaller value means the attack was less often able to achieve its goal under the evaluation setup. This is distinct from the system’s clean accuracy and from the amount of extra effort required to find a successful change.

BERTAttack against fine-tuned BERT-base encoders, average success rate across seven tasks

BERTAttack succeeds least often against the encoder initialized with RobustEmbed.

BERTAttack against fine-tuned BERT-base encoders, average success rate across seven tasksSimCSE: 75.51SimCSE75.51USCAL: 58.62USCAL58.62RobustEmbed (this paper): 39.62RobustEmbed (this paper)39.62
The numbers
System or settingAttack success rate %
SimCSE75.51
USCAL58.62
RobustEmbed (this paper)39.62

The same ordering holds for the other attacks in the downstream table. For TextFooler, the average attack success rates are 72.61% against SimCSE, 56.72% against USCAL, and 37.97% against RobustEmbed. TextBugger averages 48.91%, 33.40%, and 20.98% in the same order. With PWWS, the averages are 60.71%, 46.77%, and 29.06%. With BAE, they are 70.15%, 53.77%, and 34.79%. The paper also shows that the ordering survives when the averages are broken out by classifier and attack.

For instance, BERTAttack succeeds on 82.16% of the MRPC attack attempts reported against SimCSE and 39.97% against RobustEmbed. On MNLI-Mismatched, the corresponding rates are 72.22% and 37.24%. The USCAL rates for those two evaluations are 63.05% and 55.86%, respectively. The inference and paraphrase results matter because a system could have been more stable on polar reviews alone if it learned mostly to protect strong sentiment cues. The pattern in the reported table extends beyond those reviews.

There is variation within RobustEmbed’s own results. Under BERTAttack, its success rate on YELP is 45.15%, and on MR it is 34.76%. On YELP, TextBugger succeeds at 28.58%, while PWWS succeeds at 29.94%. These figures give the absolute scale of the remaining susceptibility. A relative ranking across encoders describes which performed better under a given attack. The rates themselves show that the attacks still succeed on part of the evaluation set.

For a set of 1,000 attacks, the paper also compares RobustEmbed and USCAL in terms of the average number of queries and the drop in accuracy. A query here is an interaction with the system during the search for a successful alteration. Across the attacks in that figure, RobustEmbed requires more queries and undergoes a smaller accuracy reduction. These measurements add context to the success rates. One concerns the effort expended during the search, and the other concerns the effect on performance. The study reports the same direction of advantage on both axes.

Robustness of the similarity judgment itself

The authors introduce Adversarial Semantic Textual Similarity, or AdvSTS, to test the similarity score under deliberate text changes. The task starts from sentence pairs with human similarity judgments. The attack alters the inputs with the aim of making the predicted score depart from its human reference. The resulting datasets are AdvSTS-B and AdvSICK-R, derived from the clean similarity benchmarks. This makes the object of the attack a graded relation between sentences. In the classification tests, the object was a category decision.

The description of AdvSTS names Pearson correlation as the metric for comparing the predicted scores on edited text with the human judgments. Pearson correlation measures the strength of a linear relationship between the two sets of scores. It is distinct from the rank correlation in the clean STS table. The main AdvSTS results table reports a different number again, attack success rate. These are two ways of asking what happens to scoring under perturbation. An attack success rate counts the cases that meet the attack’s success criterion. A correlation describes the agreement in scores across the evaluation set.

BERTAttack on AdvSTS-B and AdvSICK-R, average attack success rate

RobustEmbed has the lowest average success rate when the attack targets sentence-pair similarity.

BERTAttack on AdvSTS-B and AdvSICK-R, average attack success rateSimCSE: 32.23SimCSE32.23USCAL: 27.26USCAL27.26RobustEmbed (this paper): 13.09RobustEmbed (this paper)13.09
The numbers
System or settingAttack success rate %
SimCSE32.23
USCAL27.26
RobustEmbed (this paper)13.09

With BERTAttack, RobustEmbed has a success rate of 12.99% on AdvSTS-B and 13.18% on AdvSICK-R. SimCSE records 31.60% and 32.85%, respectively. The ordering recurs under TextFooler. RobustEmbed has rates of 7.48% and 8.95%, while USCAL has 16.52% and 18.71%. The same direction holds for each remaining attack on both benchmarks. Across the two datasets, BAE averages 11.98% against RobustEmbed and 24.20% against USCAL. For TextBugger, the reported averages are 12.39% and 23.20%, and for PWWS they are 14.00% and 22.47%.

AdvSTS ties the robustness claim more directly to the sentence comparison the method is designed to improve. A classifier’s resistance could run partly through the mapping from vectors to class labels. Here the evaluated outcome is the similarity score. The attack rates are lower than the rates reported in the downstream classification and inference section, but the attacks have a different target and success criterion. The meaningful comparisons are between encoders within the AdvSTS setup and within each downstream attack setup.

What the ablations show

The size and number of search steps

The authors vary the settings that govern how the perturbed view is made. Their hyper-parameter study uses BERT base and STS development data. That choice determines what the curves and tables can establish. They show how well these search settings support clean similarity performance during development. The attack experiments evaluate the complete configuration under a different set of criteria.

The two search branches have separate step sizes. In the authors’ sweep, [1e-4, 1e-6] is the reported range associated with better performance for the normalized-gradient branch, and [1e-2, 1e-4] is the corresponding range for the sign-gradient branch. The selected values are α = 1e-5 and β = 1e-3. The two updates put different quantities next to their step-size parameter, so the different settings matter for interpreting the sweep. A given numerical step size applied to a normalized gradient need not change the input by the same amount as that value applied to componentwise signs.

The authors also vary the number of search steps with K = T, so both branches gain or lose steps together. Clean STS performance improves gradually as the common setting increases from 1 to 9. Further increases yield negligible improvement in the reported comparison, while the search takes longer. They use 5 steps for each branch in the experiments. This selection expresses a tradeoff the paper makes explicitly. More steps give the method additional chances to refine a perturbation, and they also require more computation during each batch. The comparison shows diminishing returns for the tested objective. Because both counts vary together, it does not resolve how much of the change comes from each branch.

The shape of the constraint and the blend

The authors compare perturbation constraints based on L₁, L₂, and L∞. These norms give different meanings to the idea of a small perturbation. The first limits the sum of absolute coordinate changes. The second limits Euclidean length. The last bounds the largest absolute coordinate change. As a result, the constraint affects the directions the search can explore and the distribution of change across coordinates.

With BERT base in the STS hyper-parameter study, L₁ gives an average Spearman correlation of 75.28, L₂ gives 76.82, and L∞ gives 77.51. This supports the authors’ choice of L∞ for the remaining experiments. The test is about how those numerical constraints affect the resulting vectors on clean similarity data. A smaller coordinate change is a property of the internal representation. Whether a text edit is hard for a person to notice is a separate property.

The sweep over λ tests the contribution of using the two perturbations together. At λ = 0, the blend consists entirely of the sign-gradient result and scores 76.36 in average STS correlation. At λ = 1, it consists entirely of the projected-gradient result and scores 76.48. The intermediate settings λ = 0.25 and λ = 0.75 yield 76.91 and 77.04, respectively. The highest tested score is 77.51 at λ = 0.5. With the other conditions used in this sweep, each tested blend has a higher clean similarity score than either endpoint.

The comparison gives a concrete reason for keeping both branches in the reported setup. Each branch is usable by itself, and mixing them worked better on the metric used to choose the setting. It leaves open how a single branch would fare if its step size, iteration count, or computation were retuned for that comparison. The endpoint scores show the effect of dropping one contribution from the blend under the tested conditions.

The added comparison in the training loss

The regularization study varies the weight of the direct comparison between the hard view and the ordinary dropout positive. This test reports outcomes on clean STS and transfer tasks along with a downstream TextFooler success rate. It therefore gives some evidence about how a choice in the loss relates to both sides of the authors’ goal.

At γ = 1/64, the STS score is 76.46, transfer accuracy is 85.93, and the TextFooler success rate is 44.37%. At γ = 1/128, those results are 77.51, 86.20, and 37.97%, respectively. With γ = 1/256, they are 77.06, 85.87, and 40.32%. With γ = 1/512, they are 75.84, 84.66, and 42.58%. The same setting comes out ahead on all three measures, so the authors use γ = 1/128 throughout the other experiments.

The intermediate optimum matters for the explanation of the loss. A larger weight does not necessarily mean better stability, even though it increases the pressure to bring the hard view towards the dropout positive. The comparison depends on how that pressure interacts with the clean anchor’s two positive comparisons and with the rest of the batch. All the reported settings in the sweep give the additional term some weight. The results identify the best tested weight and leave the isolated effect of removing the term unresolved.

Where the changes appear in the vector space

The authors use alignment and uniformity to describe the learned vectors. Alignment focuses on pairs that are meant to be related. Uniformity focuses on pairs drawn independently from the data. An encoder can score well on alignment by bringing positive pairs together. The uniformity measure checks whether the rest of the representation space remains spread out rather than setting aside the question of how other examples are arranged.

ℓalign ≜ 𝔼(x,x⁺)∼ppos ∥f(x) − f(x⁺)∥²

ℓalign is the alignment measure and ≜ means “is defined as.” 𝔼 is an expectation, here over pairs (x, x⁺) drawn from the positive-pair distribution ppos. The inputs x and x⁺ are related views. f maps an input to its sentence vector, and f(x) − f(x⁺) is the vector difference. The squared Euclidean norm ∥·∥² measures the separation. Lower values indicate that the paired representations tend to lie closer together.

ℓuniform ≜ log 𝔼x,y i.i.d.∼pdata exp(−2∥f(x) − f(y)∥)

ℓuniform is the uniformity measure. 𝔼 averages over x and y, drawn independently from the same data distribution pdata, as indicated by i.i.d.. f(x) and f(y) are their sentence vectors, and the norm measures their distance. exp is the exponential function, with −2 scaling the distance in its argument, and log is applied to the resulting average. Nearby random pairs contribute larger values to the quantity inside the average. The paper treats a lower uniformity value as favorable because it corresponds to embeddings that are more dispersed on the hypersphere.

In its BERT-base analysis, the paper reports alignment of 0.058 for RobustEmbed against a comparison value of 0.073. The uniformity values it gives are -2.293 and -2.305. The distance between related cases is where the more pronounced change appears. Uniformity stays close by the reported diagnostic. This fits the intended role of the added positive view. The analysis measures the resulting geometry and helps explain what changed, while the attack evaluation tests what that geometry means for actual predictions.

Comparing full adversarial training recipes

In a separate comparison, the authors apply a task fine-tuning procedure that uses adversarial training similar to their pretraining procedure. They compare the resulting RobustEmbed system with PGD, FreeLB, and SMART. This study evaluates full training recipes. It complements the tests that vary one setting within RobustEmbed, because it asks how the recipe fares against other ways of training for adversarial resistance.

The table reports an STS score of 85.79 for RobustEmbed and 82.65 for SMART, the strongest comparator on that column. The reported transfer scores are 89.86 and 87.34. On the attack side, RobustEmbed has success rates of 37.12% for TextFooler, 20.43% for TextBugger, and 39.25% for BERTAttack. SMART’s corresponding entries are 45.46%, 26.08%, and 47.39%. FreeLB and PGD also trail RobustEmbed in each column. The STS and transfer figures belong to this separate fine-tuning comparison. The main fixed-embedding tables use different training and evaluation conditions.

The robustness tables, parameter sweeps, and geometry diagnostics answer different parts of the same question. The main comparison shows that the result holds across tasks and attacks in the study. The search sweeps show which ways of producing the hard view help on the development criterion. The loss sweep shows that its weight matters across several outcomes, while alignment measures the relationship the training is intended to change. Together they give more detail than a single end-to-end score could supply.

Limitations

Limits the authors identify

The authors designed RobustEmbed for encoders such as BERT, where an input representation can be pooled into a sentence vector and compared with vectors from other inputs. They identify generative systems such as GPT as a possible limit on direct applicability. Generating coherent text presents a different output and a different criterion of success. The experiments concern the properties of vectors and the behavior of systems that use them. Extending the recipe to generation would require defining what should stay invariant in that setting and testing whether training achieves it.

The authors also identify computing resources as a constraint. They report that continuing to train RoBERTa large with their procedure takes substantial GPU resources. They had to use smaller batches, and they cite 256 and 512 as examples of sizes that generally give better performance. Their training discussion also says pretrained initialization made the method usable at the reported batch sizes of 64 or 128. Those statements concern different questions. The smaller settings were practical for the study, while a comparison across a larger range of batch sizes remains limited by the resources they report. Because the batch supplies the contrastive negatives, larger batches could change the learning problem as well as the cost.

For adaptive attacks, the paper points to a mismatch between the numerical perturbation routine and the input accepted at test time. The training routine produces a continuous change in the embedding space. The downstream evaluation accepts raw text. Applying the same routine directly would therefore give an object of the wrong kind for that evaluation. This is a limitation of using the training generator itself as a text attack. The experiments test a defined suite of text perturbation techniques, leaving other ways of adapting an attack to the trained system outside the reported evidence.

Limits visible in the experimental setup

The robustness claims are empirical. The numerical constraint says how large a training perturbation can be, and the iterative search gives examples deemed difficult under the current objective. It does not certify that outputs will remain stable for every perturbation in that region. The evaluations then use several edits to text. Their results establish resistance under the reported attack settings, while the success rates themselves show that some edited examples still defeat the system. In particular, the lower BERTAttack average describes a meaningful change in the tested outcome while still indicating substantial remaining vulnerability.

The connection between a small numerical perturbation and a meaning-preserving edit is also indirect. A norm measures coordinate changes in a representation. Text edits have consequences for meaning, grammar, and the correct label. The training method avoids having to decide which words should replace each other, but that leaves the interpretation of the edited evaluation pairs important. In AdvSTS, an edit that changes what one sentence means may also change how similar the pair ought to be. The task description uses human similarity scores as its reference and does not establish fresh human ratings for every altered pair. The attack rates therefore measure the stated evaluation protocol, with preservation of the original target an assumption for interpreting an edit as a robustness failure.

The coverage of the experiments places another boundary on the result. Clean similarity and transfer tests report BERT and RoBERTa configurations. The principal attack comparisons use BERT base and compare RobustEmbed with SimCSE and USCAL. Accordingly, the study shows that the clean gains extend across more encoder settings than the text-attack comparisons cover. Likewise, the training sentences come from English Wikipedia, and the experiments give no separate evidence for applying the same setup to a training corpus in another language. Reusable sentence vectors are the aim. Their measured reuse here concerns the tasks and encoders in the paper.

Fine-tuning also changes what can be attributed to the embedding alone. In the main downstream attack study, task training intervenes between the self-supervised initialization and the test. The comparison establishes how the complete fine-tuned systems behave when started from the different embeddings. It does not isolate every feature of the initial vector space that survives that adaptation. The clean fixed-vector tests and the direct AdvSTS scores are useful complements precisely because they examine outcomes closer to the representation itself.

The parameter analyses leave several questions about causation open. The norm and mixing sweeps use clean STS development performance as their selection criterion. The regularization study includes attack outcomes but lacks a setting that removes the regularizer entirely. The separate recipe comparison also changes more than one component at a time. These results support the chosen configuration and give evidence about sensitivity to its settings. They provide less evidence for attributing the full robustness gain to any single component or for assuming the same settings would be optimal under a different evaluation.

Finally, the small average gains on clean tasks call for care about their precision. The attack study describes repeated runs and reports their averages, but the main result tables give point estimates without intervals around the comparisons. For clean benchmarks, the uneven task-level results already show that the advantage depends on the task. The strongest reading of the clean evidence is that the reported configuration preserves and modestly improves average performance while undergoing a training procedure intended to increase robustness. The consistency of the attack comparisons speaks to the robustness benchmarks themselves.

What came after

Later work building on RobustEmbed has yet to be documented. The authors’ own proposed continuation is to study hard negatives in a supervised setting. In RobustEmbed, the deliberately difficult example is a positive because it comes from the same sentence. Other examples in the batch supply the negatives. A hard negative would instead be a plausible match that supervision identifies as different in a relevant way. The proposal would test whether more informative examples on that side of the comparison can further improve the representation. The paper leaves the outcome of that extension open.

Cite

Cite as Javad Asl, Eduardo Blanco and Daniel Takabi. 2023. RobustEmbed: Robust Sentence Embeddings Using Self-Supervised Contrastive Pre-Training. Findings of the Association for Computational Linguistics: EMNLP 2023.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2023.findings-emnlp.305

@inproceedings{asl2023robustembed,
  title = {{RobustEmbed: Robust Sentence Embeddings Using Self-Supervised Contrastive Pre-Training}},
  author = {Javad Asl, Eduardo Blanco and Daniel Takabi},
  booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2023},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.305},
  url = {https://doi.org/10.18653/v1/2023.findings-emnlp.305}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/asl-2023-robustembed-robust-sentence-embeddings-self/