TABS: Efficient Textual Adversarial Attack for Pre-trained NL Code Model Using Semantic Beam Search
Paper · 2022 · YunSeok Choi, Hyojun Kim and Jee-Hyong Lee
Summary
A code search system can find the right function for a description and then put it far down the results when the description changes slightly. TABS studies how sensitive code search is to such changes. The authors alter the natural-language input while leaving the code fixed. They test two kinds of decisions. In classification, the system decides whether a description matches a code snippet. In retrieval, it ranks snippets for a description. A successful adversarial example changes the classification or pushes the correct snippet past a specified rank, while meeting a minimum semantic similarity score.
The difficult part is choosing which revised descriptions to test. A word can have many plausible replacements, and a replacement that appears unhelpful by itself may work well in combination with a later edit. TABS keeps several revised descriptions in play through beam search. To control the cost of exploring those alternatives, it first narrows the possible replacements by comparing how each word is represented in the surrounding sentence. These operations serve different purposes. The contextual comparison selects words that merit testing, while the beam preserves different combinations of edits long enough for later changes to matter.
The authors fine-tune CodeBERT separately for classification and retrieval and evaluate the search on CodeSearchNet data from CodeXGLUE. On the classification test sample at a similarity threshold of 0.2, TABS records 874 successful attacks and a reported query count of 50.4, compared with 792 and 84.2 for BERT-ATTACK. On retrieval, with a similarity threshold of 0.3 and a target rank of 100, the corresponding results are 451 successes and 42.9 queries for TABS, versus 407 and 80.2 for BERT-ATTACK. The retrieval evaluation also examines changes across the top of the results list, where TABS produces a lower measured agreement at the reported cutoffs.
The component comparisons explain the tradeoff behind these results. Beam search alone often finds more successful edits, with a higher query count. Contextual filtering alone uses the fewest queries in the reported comparisons and generally finds fewer successes than the combined method. TABS brings the query cost down while retaining much of the beam’s ability to find failures. There is also a distinction between the similarity score and what a person would regard as the same request. The paper’s own examples include edits that preserve the sentence’s structure while changing the entity or concept the code is supposed to describe.
Deep dive: TABS: Efficient Textual Adversarial Attack for Pre-trained NL Code Model Using Semantic Beam Search
TABS tests how small wording changes affect code search, using contextual word filtering and beam search to find failures with fewer queries. · about 31 minutes to read
The problem and its context
When a change in wording changes the result
Natural-language code search begins with a description of behavior. The description may be paired with a particular piece of code or used to search across a collection. In the first setting the system judges whether the pair matches. In the second it places code snippets in order of relevance. These settings are closely related from a user’s perspective, but their outputs expose different kinds of weakness. A pair can receive the wrong label outright. A retrieval system can still include the correct item somewhere in its results while making it much harder to find.
The paper studies sensitivity on the description side of this interaction. The code associated with the original input stays in place. The edited description is then passed to the same system to see what happens to the decision about that code. An attack in this setting is a deliberately selected text change that causes a failure under a stated criterion. The task is part of information retrieval & search, but the study’s question concerns the conditions under which an existing system’s decisions change.
A bare search for any altered sentence that flips a prediction would have limited value. Changing the requested operation or the object of that operation could give the search system a legitimate reason to change its answer. The authors therefore require an edited description to resemble its source as measured by a sentence encoder. They also report the proportion of words changed. These measurements express two different intuitions about a small edit. A sentence may retain nearly all its words while changing a term central to the code, or it may use different wording across a larger stretch while preserving the general idea. The paper measures textual resemblance and leaves the stronger question of equivalence open.
Classification and retrieval call for different ways to express failure. In classification the decision is categorical. A pair has a reference label and the system assigns a label. In retrieval the position of the correct snippet gives a graded outcome. A snippet near the top and the same snippet hundreds of places down have very different practical visibility, even though both appear in a ranked collection. The paper separates this movement of the correct snippet from shifts across the head of the entire list. An edit that damages the position of the right answer can also give the search system a substantially different set of leading results.
Why search over edits is difficult
The paper situates the study after the adoption of pretrained systems in natural-language processing and program understanding. It cites general text pretraining work such as BERT and work on representations for code such as GraphCodeBERT. These are examples of the research context, while the actual robustness experiments use task-specific versions of CodeBERT. The authors describe their paper as the first application of adversarial attacks to natural-language code search to their knowledge.
Their starting point is earlier work on textual attacks that can operate through the system’s outputs. In this account, black-box access means that information from the evaluated system comes through queries. The method can observe the effect of submitting an alternative input without consulting the internal parameters of the system under evaluation. Other pretrained components can still be used to analyze the text. The distinction matters for cost. Evaluating a candidate with a separate language component and asking the code search system for a new prediction are separate operations.
The immediate predecessor for TABS is BERT-ATTACK. As the authors describe it, that approach identifies important positions in the input, generates potential replacements from a masked language predictor, and tests candidates against the evaluated system. A masked predictor estimates which words could fill a gap using the surrounding sentence. This is more sensitive to context than treating every possible substitute as equally plausible. Even so, a plausible word at a position can express something quite different from the word that was there originally. Fluency at a position and similarity to the original word capture different properties.
There is also a problem with how earlier decisions carry forward. The paper describes BERT-ATTACK as using greedy search. When the current set of substitutions fails to produce a successful example, the procedure advances with the edit it currently regards as strongest. All later edits build on that choice. This makes the search manageable, but it means the next replacement is evaluated in a single surviving version of the sentence. Its effect in another version, where an earlier word was changed differently, is outside that search path.
The limitation follows from the way words work together in a sentence. Suppose two alternative descriptions differ at an early position and remain otherwise identical. An edit at a subsequent position may fit one alternative better. It may also change the classifier’s behavior more in one context than the other. The earlier edit with the most immediate effect has no guarantee of being part of the best later combination. Retaining several partial alternatives offers a way to observe some of those interactions. Keeping every alternative would make the candidate collection grow, so TABS uses the bounded search strategy discussed in Sequence-to-Sequence Learning as Beam-Search Optimization.
The paper also compares methods that differ in the types of edits they consider. CLARE, for instance, can replace text, insert text, or merge text. As the TABS authors explain it, CLARE evaluates the importance of edits across these strategies, which adds to its query burden. The baseline comparisons consequently involve different proposal and search procedures. The paper’s variants of TABS give a closer comparison of what changes when the search keeps multiple alternatives or the word list is narrowed. The contextual editing baseline is described in Contextualized Perturbation for Textual Adversarial Attack.
The design problem is to spend queries where they provide new information. Testing more words at a position gives broader coverage of local substitutions. Keeping more partial descriptions gives broader coverage of combinations across positions. Either form of breadth can be expensive. TABS puts a contextual similarity check between word proposal and code search evaluation, then spends part of the saved query budget on maintaining several active descriptions. The experiments test how well that allocation works for the classification and retrieval settings.
The method, step by step
From the original description to a revised one
TABS starts with a natural-language description and the code associated with it. For the classification task there is a reference label for the pair. For retrieval, the relevant snippet has a position in the result list for the original description. The search changes the description, and the code serves as a fixed point of comparison. That fixed point lets the experiment attribute differences in the system’s output to changes on the text side.
The method first estimates which word positions have the greatest influence on the system’s output. It does this by comparing the original output with the output obtained when a word is replaced by a marker for an unknown word. The method arranges the positions by their importance scores. The order is determined from the original description, so the procedure has a shared order of positions even when later branches contain different wording.
At the next position in that order, each active description supplies its own surrounding context for potential replacements. A masked language predictor proposes likely words. TABS then evaluates the proposals in their sentence contexts. A candidate may look plausible as a completion but represent a different idea from the original term. The contextual comparison gives the method a second basis for choosing among the plausible completions, before evaluating the revised descriptions with the code search system.
The search tests the resulting descriptions against the criterion for the task. If several pass, it returns the one with the greatest measured sentence similarity to the original among those candidates. If the current group yields no qualifying example, the method keeps a bounded set of partial descriptions and continues to the next position. The beam is this surviving set. Its purpose is to let different early word choices remain available as contexts for later choices.
How TABS searches revised descriptions
The steps in order.
How the paper defines an important word
The importance calculation compares the system output for the original pair with an output after temporarily obscuring a word. The paper uses an unknown-word token for this comparison. The replacement is an analytical probe. It reveals what happens when the original lexical content is missing from that position. The eventual revised description uses words proposed by the masked predictor.
I(wᵢ) = f(T, C) − f(T ∖ wᵢ, C)
Here I(wᵢ) is the importance score assigned to the word wᵢ, and the subscript i identifies its position. T is the original description, C is the code snippet, and f denotes the evaluated system’s output for those inputs. The expression T ∖ wᵢ means the version of T with the word at position i replaced by the unknown-word token. The symbol − denotes subtraction and = gives the value assigned to the importance score. For classification the paper describes f here as an output logit, a score before the final label decision. For retrieval it is a rank, the numeric position of the code snippet in the returned ordering.
The sign convention is worth noting because a higher numeric rank means a poorer retrieval position. The paper gives the same written difference for both tasks and says the positions are ordered by descending importance. In classification, a decrease in the chosen logit after a word is obscured contributes a positive difference. With the written subtraction in retrieval, a move to a poorer numeric position contributes a negative difference. The paper’s final retrieval criterion states the intended direction of a successful attack clearly. Its description of the importance ordering leaves this difference in direction between the tasks unresolved.
The initial importance score answers a narrow question. It measures the effect of a particular unknown-word substitution in the original text. It provides an order for exploring positions, while the effect of a specific proposed replacement is assessed later in a branch’s current sentence. An important position may offer few plausible alternatives. Another position may appear less consequential under the unknown-word probe and still interact with a change made elsewhere. The authors use the importance order to organize the search, then rely on the candidate evaluations to reveal what particular substitutions do.
What gets through the contextual filter
The paper uses a masked language predictor as a source of candidate words. It reports using RoBERTa in this role for TABS. This component proposes replacements and provides word representations. CodeBERT has a different role in these experiments. It is the system whose classification or retrieval output is being studied. Keeping the roles apart helps explain how the method can reduce queries to CodeBERT while still requiring substantial work on the candidate text.
The proposed words begin as likely completions for the current position. Probability is useful here because the surrounding words already constrain what can occur in the gap. It can favor words that belong in the sentence syntactically or commonly appear in a similar local context. The same gap may nevertheless admit several words, each pointing to a different object, operation, or property. The additional question for TABS is how similar the proposed word is to the original one when both are read in context.
To make that comparison, the method uses contextual word embeddings. A contextual embedding is a vector representation of a word in a particular occurrence. Its value reflects the surrounding text. The method takes representations from the final hidden states of the masked predictor, its last internal layer of contextual representations. Each proposed replacement obtains a representation in the version of the sentence where that candidate occupies the current position. The filter compares the resulting representation with that of the original word and retains the most similar candidates for testing.
A word may occupy several pieces in the predictor’s input. The paper describes byte-pair encoding for splitting text into such pieces and average pooling for making a single contextual word vector. Average pooling means taking the average of corresponding components of the piece vectors. It lets the similarity comparison operate on the word as a unit even when the predictor processes it through subword tokenization. The paper names cosine similarity explicitly for the final sentence comparison. Its explanation of the word filter emphasizes the ranking by contextual embedding similarity.
There are therefore two filtering levels with different scopes. The first is about a word at a particular position in a particular sentence. It decides which alternatives enter the search. The second is about the full candidate description relative to the original. It decides whether a changed output qualifies and which qualifying candidate the method prefers. Similarity at the word level can make semantically close candidates easier to find, while the sentence-level score provides a common test across different edit histories.
What the beam retains
Each surviving description can generate alternatives when the search reaches a position. A replacement chosen within one branch yields a new description extending that branch. The method pools the resulting candidates across the active descriptions and evaluates their outputs. The paper describes ranking candidates by output score and uses ascending logits when it explains classification. Its retrieval equations specify the required rank change for success, while the pseudocode’s description of retaining the beam is written in terms of logits.
The search can stop as soon as the current candidate group contains a description that qualifies. If several qualify, the authors use sentence similarity to decide between them. The comparison is among the successful descriptions examined at that stage. Later stages could contain other qualifying inputs, and the search’s bounded character means earlier pruning could also remove a branch that would eventually yield a useful result. The stopping rule makes the method a search for a suitable example under a query budget, with a local preference for closeness to the original sentence.
If the current stage has no qualifying example, the beam keeps a specified number of the leading descriptions. The width refers to the count of surviving descriptions, whereas the contextual filter’s width refers to the number of word replacements allowed through for each description. Raising the first setting preserves more different edit histories. Raising the second gives each retained history more immediate alternatives. These controls matter independently because the same overall number of candidate evaluations can be distributed across the two kinds of breadth in different ways.
The connection between the beam and contextual filtering is particular to the evolving description. Once branches differ at an earlier position, the masked predictor sees those differences when it proposes words for a later position. The contextual vectors for replacements can also reflect them. Thus the same position in the original sentence can lead to different proposals or a different ordering across surviving branches. This is the mechanism through which TABS considers combinations using more than the context present in the original description.
What counts as a successful change
The classification condition requires a wrong label and sufficient sentence similarity. The highest-scoring label is the predicted class. The reference label belongs to the original example and is used to judge the result for the edited description.
argmax f(T_adv, C) ≠ Y, and Sim(T_adv, T) ≥ ϵ
Here argmax returns the class whose score is greatest, and f provides the classification scores. T_adv is the edited description, C is the unchanged snippet, and Y is the reference class of the original pair. ≠ means the predicted and reference classes differ. Sim gives the cosine similarity of the sentence vectors, with T denoting the original description. ≥ means the score must reach or exceed ϵ, the minimum allowed similarity. The word and requires both conditions to hold. Cosine similarity compares the direction of the sentence vectors, so this test judges closeness through their representation.
In retrieval the matched code has a numeric rank for both descriptions. Movement across a threshold defines the failure. The aim expressed in the formula is for the original result to sit on the better side of the threshold and the revised result to sit on the poorer side.
f(T, C) < target_rank < f(T_adv, C), and Sim(T_adv, T) ≥ ϵ
Here f gives the rank of the code snippet C for a description. T is the original description and T_adv is the edited version. target_rank is the boundary the correct snippet must cross. Each < is strict, so the original rank must be numerically smaller than the boundary and the edited rank numerically larger. Sim again compares the sentence vectors for the edited and original descriptions, ≥ includes equality with the threshold, and ϵ is the minimum similarity. The word and joins the rank and similarity requirements. In the experiments the authors obtain the sentence-level representations using the Universal Sentence Encoder.
Training, data, and the cost of evaluating candidates
The task-specific training step is CodeBERT fine-tuning. The authors fine-tune it separately for pair classification and code retrieval using the code search data from CodeXGLUE. The search over revised descriptions takes place during evaluation. The paper presents the masked predictor and sentence encoder as tools for proposing and comparing text during that search. It reports no separate training procedure for the beam or the contextual filter.
The paper expresses the approximate work of BERT-ATTACK in terms of sentence length and the number of proposed replacements.
O(LN)
O denotes asymptotic time complexity in the paper’s accounting. L is the sentence length and N is the number of proposed replacements for a position. The juxtaposition LN means the product of those quantities. This term describes the search cost as the number of positions and word proposals grows.
For TABS, the paper adds a term for the contextual filtering work.
O(LBM + LB × mlm × N)
O again denotes asymptotic time complexity. L is sentence length, B is beam width, M is the number of proposals that pass the word filter, and N is the number of initial word proposals. mlm denotes the inference cost of the masked language predictor as the authors express it. Products are indicated by juxtaposition or ×, and + joins the two cost terms. LBM accounts for candidate evaluation across positions and beam branches. LB × mlm × N represents the additional work of comparing contextual representations for the initial candidates.
In the authors’ selected configuration, N is 50, B is 5, and M is 10. The paper notes that N equals the product of B and M in this configuration. That equality concerns the nominal candidate counts in the complexity expressions. The actual query counts depend on the search’s progress, including when a qualifying candidate is found. The authors also describe batching the candidate sentences for contextual filtering on graphics processors. They report that computing contextual similarities accounts for about 3.9% of average total TABS time in their experimental setting. That is a share of TABS runtime under the measured setup, alongside the separate comparisons of target query counts.
Experiments and results
What was tested and what the metrics measure
The authors use the CodeXGLUE natural-language code search tasks with CodeSearchNet. Their dataset statistics give 251,820 training examples, 9,604 validation examples, and 19,210 test examples. The reported average text length is 11 and the average code length is 95. The robustness experiments draw 1k test samples at random. The retrieval comparisons then restrict this sample according to the original position of the correct code. That restriction changes which cases are eligible and matters when comparing counts across retrieval settings.
Before applying the attacks, the classification system has 97.96% accuracy on the test dataset. The test-set retrieval mean reciprocal rank is 0.6796. Mean reciprocal rank averages the reciprocal of the correct item’s position, which gives early positions greater influence. These are measurements of the fine-tuned systems on the test data before the edits. The attack results use the sampled inputs and their particular success criteria.
The reported metric called Success is a count of successful attacks. Perturb is the change ratio, which describes how much of the original wording is replaced in a successful attack. Query is the reported number of evaluations of the code search system, summarized in the tables with fractional values. USE is the original-to-edited sentence similarity measured through the Universal Sentence Encoder. This score helps determine eligibility and gives a way to compare successful outputs within an eligibility setting. A higher threshold offers a stricter test of resemblance according to that encoder.
The retrieval results add original and changed ranks for the correct code. They also report normalized discounted cumulative gain, abbreviated nDCG, at the positions denoted by nDCG@10 and nDCG@20. In the paper’s analysis those values describe changes in the leading recommendations between the original and revised queries. Lower scores there indicate more disruption under the reported comparison. The rank values and nDCG describe distinct effects. One follows the single correct snippet, while the other concerns a leading portion of the returned list.
The classification baselines are Textfooler, BERT-ATTACK, CodeBERT-Attack, and CLARE. CodeBERT-Attack is the paper’s variation on BERT-ATTACK with a CodeBERT masked predictor to propose alternatives. The other baseline names refer to earlier attack methods. Textfooler appears in Is BERT Really Robust?. The retrieval table includes Textfooler, BERT-ATTACK, and CLARE. The paper reports setting the initial proposal parameter N to 50. It also compares beam search alone and contextual filtering alone with their combination in TABS.
Classification at the main similarity settings
At a minimum sentence similarity of 0.2, TABS achieves 874 successful attacks. CLARE has the largest baseline success count, 814. BERT-ATTACK and CodeBERT-Attack each record 792 successes, and Textfooler records 699. Beam search alone reaches 882, the highest count in that comparison. These counts describe the number of edited inputs meeting both the classification and similarity requirements under the reported setting.
Successful attacks on CodeSearchNet classification at similarity threshold 0.2
TABS exceeds the external baselines, and beam search alone has the highest count.
The numbers
| System or setting | successful attacks |
|---|---|
| Textfooler | 699 |
| BERT-ATTACK | 792 |
| CodeBERT-Attack | 792 |
| CLARE | 814 |
| Beam search alone | 882 |
| Contextual filtering alone | 780 |
| TABS (this paper) | 874 |
TABS records 50.4 queries at this setting, compared with 67.5 for Textfooler, 84.2 for BERT-ATTACK, 90.5 for CodeBERT-Attack, and 923.1 for CLARE. Query count makes CLARE’s position in the comparison look different from its position on success. Its broader edit strategies accompany a strong baseline success result and a much larger number of evaluations. Among the paper’s own configurations, the fastest by this measure is contextual filtering alone at 29.2. Beam search alone reaches 162.7.
In the same classification comparison, TABS has a USE score of 0.498. Beam search alone reaches 0.507, and CLARE leads the external baselines at 0.484. TABS has a perturbation value of 15.9, while CLARE has 13.4 and BERT-ATTACK has 13.9. The combination of a higher similarity score and a higher change ratio illustrates why both measures appear in the table. The number of changed words and the resemblance expressed by the sentence encoder track different properties of the output.
At a similarity threshold of 0.3, the classification comparison has 751 successful attacks for TABS and 49.9 queries. CLARE reaches 689 successes with 969.7 queries. BERT-ATTACK reaches 667 successes with 83.7 queries, and CodeBERT-Attack reaches 663 with 90.2. Textfooler records 578 successes and 67.8 queries. These results show the same ordering between TABS and the external baselines on success at this setting, with the combined method using fewer evaluated queries.
The 0.3 setting also yields a TABS similarity of 0.537, the same as beam search alone. CLARE’s similarity is 0.525, with BERT-ATTACK at 0.514 and Textfooler at 0.511. Beam search alone records 787 successes, while filtering alone records 634. Their query values are 163.2 and 29.4. The combined method occupies the middle of those two configurations in query count and success, while sharing the higher of their two measured sentence similarities. Its change ratio is 14.9, compared with 13.9 for beam search alone and 12.8 for CLARE.
Retrieval when the correct code starts near the top
The main retrieval table reports a similarity threshold of 0.3 and a target rank of 100. Its experiment header gives the original-rank sample filter as original_rank ≤ 100. The success equation uses strict inequalities for the boundary itself. Thus the reported eligibility heading and the written condition for success differ in how they treat an original rank exactly on the boundary. The paper does not give a separate count of observations at that boundary.
In the main retrieval setting, TABS yields 451 successful attacks with 42.9 queries. BERT-ATTACK yields 407 with 80.2 queries, CLARE reaches 395 with 907.9, and Textfooler reaches 328 with 61.3. Beam search alone obtains the largest success count at 461. Filtering alone records 405 successes, close to the BERT-ATTACK count in this comparison, and uses the fewest queries at 27.6. For TABS the improvement over the external baselines therefore holds for the count of successes alongside the reported query measure. The beam-only result shows that the largest success count in the comparison involves a different allocation of query effort.
Query counts on CodeSearchNet retrieval at similarity threshold 0.3 and target rank 100
Contextual filtering alone uses the fewest queries, and TABS uses fewer than the external baselines.
The numbers
| System or setting | queries |
|---|---|
| Textfooler | 61.3 |
| BERT-ATTACK | 80.2 |
| CLARE | 907.9 |
| Beam search alone | 124.6 |
| Contextual filtering alone | 27.6 |
| TABS (this paper) | 42.9 |
The paired original and changed ranks for TABS are 7.2/800.3. The corresponding entries are 7.7/737.6 for BERT-ATTACK, 8.0/725.9 for CLARE, and 8.8/642.8 for Textfooler. Beam search alone produces 7.0/794.0. In this comparison the TABS value for changed rank is the numerically largest, indicating the lowest resulting position for the correct code according to that measure. The paired entries summarize each method’s results. They are distinct from an individual example’s original and changed ranks.
For this setting, TABS has a USE score of 0.535, compared with 0.531 for BERT-ATTACK and 0.537 for CLARE. Beam search alone has the highest similarity of the compared systems at 0.557. The perturbation values include 15.6 for TABS, 13.5 for beam search alone, and 13.3 for CLARE. The retrieval comparison therefore rewards TABS on several measures while giving other configurations the higher measured similarity or the smaller change ratio.
TABS produces the lowest nDCG@10 in the main comparison, at 0.1688, followed by contextual filtering alone at 0.1721. At nDCG@20, the order between these variants changes. Filtering alone records 0.2129 and TABS records 0.2130, with both below the external baselines. This distinction matters because a statement about one cutoff can hide the difference at the other. The head of the list and the larger leading portion both change under the tested edits, with slightly different orderings among the variants.
Leading-list disruption on CodeSearchNet retrieval at similarity threshold 0.3 and target rank 100
TABS has the lowest agreement at the reported cutoff, followed by contextual filtering alone.
The numbers
| System or setting | nDCG@10 |
|---|---|
| Textfooler | 0.2033 |
| BERT-ATTACK | 0.2007 |
| CLARE | 0.2065 |
| Beam search alone | 0.2097 |
| Contextual filtering alone | 0.1721 |
| TABS (this paper) | 0.1688 |
Retrieval under other starting-rank and similarity conditions
The appendix changes the retrieval comparison in two ways. It relaxes the required sentence similarity in one setting and narrows the eligible starting ranks in others. The changes distinguish the effect of admitting a greater range of edited descriptions from the effect of testing a different subset of initially well-ranked answers. The target rank remains 100 in the appendix settings.
With a similarity threshold of 0.2 and the original-rank filter still at original_rank ≤ 100, TABS records 525 successes and 45.7 queries. Beam search alone records 516 and 144.7, and filtering alone records 514 and 27.5. BERT-ATTACK records 478 and 82.6. Unlike the ordering at 0.3, TABS has the highest success count among the compared configurations in this setting. Its reported paired ranks are 6.5/841.9, and its USE score is 0.496. Beam search alone has a higher USE score of 0.525. TABS has nDCG@10 of 0.1530 and nDCG@20 of 0.1974. The filter-only values are 0.1552 and 0.1938, repeating the change in ordering between the two cutoffs seen in the main results.
With original_rank ≤ 10 and the similarity threshold back at 0.3, TABS records 378 successes and 47.1 queries. BERT-ATTACK records 333 and 84.2. Beam search alone records 386 and 148.9. The TABS rank pair for this subset is 2.0/793.3 and its USE score is 0.513. CLARE records a USE score of 0.518, while beam search alone records 0.538. The measured disruption extends to inputs for which the correct code initially ranked very well. TABS has nDCG@10 of 0.1262, with filtering alone at 0.1337. At nDCG@20, the two values are 0.1758 and 0.1753.
The narrowest appendix comparison starts with original_rank = 1, also at a threshold of 0.3. TABS records 241 successes with 54.0 queries in this setting. The beam-only method records 240 and 178.1, while BERT-ATTACK records 213 and 91.1. The original and changed ranks listed for TABS are 1.0/762.2. The USE score is 0.512, compared with 0.537 for beam search alone and 0.510 for CLARE. TABS has nDCG@10 of 0.1094 and nDCG@20 of 0.1599. Filtering alone gives 0.1138 and 0.1524. These counts belong to the first-ranked subset. A comparison with counts from broader starting-rank settings also reflects the change in eligible cases.
Taken together, the retrieval settings expose a difference between two questions about robustness. One asks whether the initial correct result can be displaced from a strong position. The other asks how closely the revised list resembles the original among its leading entries. The appendix supports both kinds of change. It also shows how an interpretation specific to the right snippet can differ from an interpretation of the overall recommendations, particularly when the nDCG cutoff changes which configuration appears most disruptive.
What the ablations show
The beam and the filter contribute differently
The closest tests of the method’s design are the comparisons with beam search alone and contextual filtering alone. These use the paper’s own configurations alongside TABS. The beam-only version keeps alternative edit histories and lacks the contextual narrowing used in the combined version. The filter-only version applies that narrowing without maintaining a beam of alternative descriptions. Their results make it possible to connect the measured costs to particular parts of the search.
The strongest case for beam search in classification is its success count. At a similarity threshold of 0.2, the beam-only and filtering-only configurations find 882 and 780 successful attacks, respectively. Their query values are 162.7 and 29.2. The combined method finds 874 at 50.4 queries. In this setting, most of the success count associated with the beam is preserved in the combination, and candidate evaluations are substantially lower. Measured sentence similarity also moves toward the beam-only result, from 0.461 for filtering alone to 0.498 for TABS, with the beam alone at 0.507.
The same components behave somewhat differently when the test gets stricter. At a similarity threshold of 0.3, beam search alone reaches 787 on classification and TABS 751, while both achieve 0.537 on USE. Filtering alone reaches 634 with a USE score of 0.509. This is consistent with the authors’ explanation that a beam offers a larger choice of qualifying descriptions, improving the chance of finding a close candidate. The aggregate comparison leaves open which individual branches account for the differences. It measures the outputs after the search has run under each configuration.
In the main retrieval setting, the results for filtering alone show how much work the word-level comparison can save on its own. Its 405 successes compare with 407 for BERT-ATTACK, while its query value is 27.6 against 80.2. Adding the beam raises the TABS result to 451 successes and 42.9 queries. Here contextual selection on its own reaches a success count close to the greedy predecessor’s at a smaller query cost. The combined configuration spends additional queries on maintaining multiple descriptions and finds more qualifying cases.
The result across these comparisons is a tradeoff among multiple measurements. Beam search alone repeatedly scores well on sentence similarity, and it has the highest success count in the main classification and retrieval settings. Filtering alone has the smallest query counts. TABS usually sits between the variants on these measures, while its retrieval rank movements and leading-list comparisons can favor the combination. An account focused solely on success would overlook the purpose of narrowing the candidate words. An account focused solely on queries would miss the results attributable to keeping multiple partial descriptions.
How the sentence similarity threshold changes classification results
The paper varies ϵ, the minimum allowed sentence similarity, and reports classification behavior across the tested values. A larger value makes the success condition more selective about the resemblance of the final description. It can disqualify an edit even when the classifier gives the wrong answer. Comparisons at a fixed threshold therefore matter for deciding whether a method’s success count improves under the same standard of resemblance.
At ϵ = 0.4, TABS records 599 classification successes, 49.2 queries, and a USE score of 0.583. CLARE reaches 527 successes with 1032.1 queries and a USE score of 0.580. BERT-ATTACK reaches 500 successes with 86.2 queries and a USE score of 0.568. Beam search alone reaches 632 successes and also has a USE score of 0.583, with 156.8 queries. Filtering alone has 471 successes and 30.6 queries. The stricter condition preserves the general pattern of the main comparisons, including the beam-only version’s higher count and the combined version’s lower query use.
At ϵ = 0.5, the TABS classification result is 429 successes, 48.7 queries, and a USE score of 0.637. CLARE has 376 successes, 1106.2 queries, and a USE score of 0.632. BERT-ATTACK has 335, 87.6, and 0.626 on the same measures. Beam search alone has the higher success count of 457 and a USE score of 0.633. Filtering alone records 317 successes and 30.8 queries. TABS has a perturbation value of 12.6 at this threshold, compared with 11.9 for beam search alone and 11.1 for CLARE.
Across the tested thresholds, the successful outputs become closer according to USE while the number of qualifying outcomes falls. For TABS, query count stays in a comparatively narrow range across these classification tests. The authors use the sweep to compare success, query cost, and similarity on a common scale of test conditions. Its results support a pattern across the thresholds they report. They also show that a more stringent similarity requirement can remove many outputs even when the candidate search remains relatively economical by the query measure.
How candidate breadth is allocated
The paper varies the beam width and the number of proposals passed by the contextual filter in the classification task. It writes the settings as ordered pairs, with the beam width first and the number of retained replacements second. A wider beam means more divergent sentence histories can remain in play. Passing more replacements means more possible next edits can be explored within each history. Both raise the potential work at a stage, with different consequences for where that work is spent.
The selected setting, TABS (5, 10), gives 874 successes, 50.4 queries, and a USE score of 0.498 in this comparison. With TABS (5, 20), the results are 878 successes, 80.5 queries, and 0.508 USE. Both have the same beam width. Opening the contextual filter to more words produces a higher similarity score and a somewhat higher success count, accompanied by a higher query count. The perturbation measures are 15.9 and 15.1, respectively.
The settings with the wider beam provide a second comparison. TABS (10, 5) gives 857 successes, 39.8 queries, and 0.491 USE. TABS (10, 10) gives 890 successes, 73.5 queries, and 0.510 USE. Their perturbation measures are 16.8 and 16.0. These measurements illustrate how an apparently broad search can still have limited coverage of alternatives within a branch when the local filter is narrow. With the wider beam fixed, retaining more local options is associated with more successful outputs and a higher USE score in the reported comparison.
The authors also compare TABS (10, 10) with TABS (5, 20). In that pair, allocating more breadth to the beam is associated with the higher success count and USE score, together with the lower reported query count. This comparison supports the idea that maintaining diverse histories can matter even when the per-branch replacement list is shorter. TABS (5, 10) is the configuration chosen for the main comparisons. The choice gives a smaller query count than the settings with the highest success and similarity values, while retaining a higher success count than TABS (10, 5).
What the edited examples reveal
The paper includes examples that allow a reader to inspect what similarity means in an edited description. One concerns code that computes a radial position for a node. TABS produces a description referring to vectors. The surrounding wording continues to suggest the same kind of computation, yet the entity being described has changed. Alternatives produced by other methods refer to such things as a rope or a compass. The example makes visible a possible source of high sentence-level similarity. A role in the sentence remains recognizable even as its occupant changes.
Another example concerns code that composes a value associated with a state parameter. The TABS output refers to a computed parameter. The procedural framing of the description remains recognizable, but the original reference to state conveys information about the parameter’s role. In the remaining example, the original description names an xtUML metamodel class. TABS substitutes a term denoting an identifier for the word denoting the class. Such distinctions can matter directly when a person uses the description to judge what a snippet operates on.
These examples illustrate behavior that the numerical comparisons alone cannot show. They help explain why a sentence can be close under an embedding measure while having different implications for the associated code. They also show that a small perturbation score offers limited information about where a change occurs. A single substitution can fall on a technical term that carries much of the description’s meaning. The appendix gives individual cases for inspection. It does not report how often comparable changes occur across the evaluation.
Limitations
Limits stated by the authors
The authors identify applicability beyond natural-language code search as an open question. The experiments cover pair classification and code retrieval using natural-language descriptions. They name general text classification and natural-language inference as settings for future testing. Those tasks can also be sensitive to word changes, but their decisions concern different relationships between input and output. A result on deciding whether code matches a description gives evidence for the code search task under study. The authors leave the performance of TABS on those other tasks to future experiments.
Limits visible in the evaluation
The results describe a particular benchmark and particular fine-tuned systems. Both task evaluations use CodeBERT, trained specifically for the respective task on the authors’ code search data. The paper includes alternative systems for generating adversarial text and tests multiple settings, while the architecture used for judging the code search inputs is shared. The observed patterns leave open how decisions and rankings from other search architectures would respond to the same descriptions. Transfer of a successful edited input from one evaluated system to another also remains unmeasured.
The evaluation begins with 1k randomly selected test samples, and the retrieval subsets depend on the original ranking of the correct code. This is appropriate for asking whether an initially good placement can be made substantially worse. It leaves out the behavior of initially poor results from those comparisons. The paper reports counts for the attack outcomes and gives selected starting-rank conditions. The eligible subset sizes for each retrieval setting are unspecified, which limits comparisons of success rates across those settings. In particular, fewer successes on the first-ranked subset can accompany fewer eligible cases.
The original-rank boundary also illustrates a reporting ambiguity. The retrieval equation requires the starting rank to be strictly smaller than the target rank. The main table describes eligibility with an inclusive bound at the same value. Both can coexist if the inclusive filter retains cases that cannot satisfy the written success condition, but the paper does not say how it handles cases exactly on the boundary. A reader can interpret the results at the stated settings while leaving the treatment of those cases unresolved.
Semantic preservation is a separate limitation. The edited description qualifies through a threshold on the Universal Sentence Encoder’s similarity measure. This criterion places an operational bound on how much the representation can change. Whether the text continues to describe the same code behavior is a stronger question. The qualitative cases show how an edited phrase can remain close to the original in general structure and alter a referent or a technical category. Human judgments of equivalence or code-aware checks are unreported. The results consequently support claims about failures under the similarity rule the authors used. The prevalence of failures under exact meaning preservation remains unknown.
The method’s stopping and pruning rules also shape the claims that can be drawn from Success. The beam covers a bounded collection of descriptions. Word proposals are restricted by probability and then by contextual similarity, and the method stops at a stage with a qualifying result. For a test case on which TABS fails, the search establishes that it found no qualifying result along the explored paths. There may be other paths through different replacements or edit combinations. The closest output selected from a successful candidate group likewise represents the best sentence similarity among that group, with global optimality over possible edits unestablished.
The query comparisons measure a particular form of efficiency. The saving concerns calls to the evaluated code search system. The separate contextual work still requires masking, candidate representations, and sentence comparisons. Batching makes a difference to the authors’ runtime observation, and their reported 3.9% share for contextual similarity belongs to the setting they used. Full end-to-end timing comparisons across all baselines and hardware conditions are unreported. The evidence supports lower query counts in the reported comparisons and a small runtime share for contextual similarity in the authors’ setup. The relationship between these quantities will depend on the costs of the components in a given evaluation.
Finally, the paper reports aggregate comparisons from its sampled evaluation. The tables establish what each configuration achieved in those runs, at those similarity and rank settings. Variation across repeated samples and uncertainty intervals for the reported counts are unspecified. This is especially relevant where configurations are close, as in the first-ranked retrieval success counts or the comparison of the two lower nDCG@20 values in the main table. Those entries are measurements of the tested runs, while the strength and stability of their ordering in new samples remain open.
What came after
No later work is documented here that extends, evaluates, or adapts TABS. Whether subsequent studies reproduced its query savings, tested the method on other language tasks, or used stronger checks for preservation of code meaning remains unestablished.
Cite
Cite as YunSeok Choi, Hyojun Kim and Jee-Hyong Lee. 2022. TABS: Efficient Textual Adversarial Attack for Pre-trained NL Code Model Using Semantic Beam Search. Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing.
@inproceedings{choi2022tabs,
title = {{TABS: Efficient Textual Adversarial Attack for Pre-trained NL Code Model Using Semantic Beam Search}},
author = {YunSeok Choi, Hyojun Kim and Jee-Hyong Lee},
booktitle = {Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing},
year = {2022},
doi = {10.18653/v1/2022.emnlp-main.369},
url = {https://doi.org/10.18653/v1/2022.emnlp-main.369}
}This page in Markdown https://md.research.elamur.ai/free/en/papers/choi-2022-tabs-efficient-textual-adversarial-attack/