Generating Adversarial Examples in Chinese Texts Using Sentence-Pieces

Linyang Li, Yunfan Shao, Demin Song, Xipeng Qiu, Xuanjing HuangarXiv 2020 · OpenReview

Abstract

Adversarial attacks in texts are mostly substitution-based methods that replace words or characters in the original texts to achieve success attacks. Recent methods use pre-trained language models as the substitutes generator. While in Chinese, such methods are not applicable since words in Chinese require segmentations first. In this paper, we propose a pre-train language model as the substitutes generator using sentence-pieces to craft adversarial examples in Chinese. The substitutions in the generated adversarial examples are not characters or words but 'pieces', which are more natural to Chinese readers. Experiments results show that the generated adversarial samples can mislead strong target models and remain fluent and semantically preserved.

Introduction

Adversarial attacks—small, intentional perturbations designed to fool machine learning models—have long been a challenge in computer vision. In Natural Language Processing (NLP), however, these attacks are significantly harder to execute because text is discrete. Unlike shifting a pixel's value, changing a word or character often destroys the meaning or makes the text appear nonsensical to a human reader.

In Chinese NLP, this difficulty is compounded by two factors: the Segmentation Trap and the Character Problem. Because Chinese lacks spaces between words, models must segment sentences first; if a segmenter fails on adversarial text, the attack fails. Furthermore, replacing a single character in a multi-character word often results in a non-existent word or a total change in meaning, making the attack obvious to humans. This research proposes a "middle ground" using Sentence-Pieces to capture the natural structure of Chinese without rigid word boundaries.

Methodology

The proposed framework utilizes Sentence-Piece tokenization, a data-driven approach that treats text as a sequence of sub-word units (pieces) trained directly from raw text. The method consists of two primary components:

  1. The Substitution Generator: A piece-level Masked Language Model (MLM) similar to BERT, with a vocabulary expanded to 60,000 pieces (primarily 2-3 character combinations). This model predicts which pieces naturally fit into specific slots in a sentence.
  2. The Attack Algorithm: The system identifies "important" pieces by observing drops in the victim model's confidence when they are masked. It then replaces these pieces with candidates from the generator, allowing for synonym replacement, rewriting, or expansion.
Figure 1: Overview of the piece-level adversarial attack process, showing how a sentence is modified to change a model's classification from 'anger' to 'happy'.

Experimental Results

The researchers evaluated the piece-level attack (Pce-R) against character-replacement (Char-R) and word-replacement (Word-R) baselines across four datasets: Sogou (genre classification), IflyTek (119-class genre task), Weibo (sentiment analysis), and Law34 (legal prediction).

Figure 6: Quantitative comparison of attack methods across four datasets, highlighting original accuracy, attack accuracy, and human evaluation metrics.

Key Findings

  • Effectiveness: The Pce-R method significantly reduced model accuracy. For instance, on the Weibo dataset, the victim model's accuracy dropped from 92.0% to 35.0%.
  • Fluency and Naturalness: Piece-level attacks consistently outperformed character-based methods in human evaluations. On the Law34 dataset, the method achieved a fluency score of 4.8/5.0.
  • Semantic Preservation: Human judges agreed with the original label of the adversarial text 90-97% of the time, proving that the attacks successfully changed the model's prediction without altering the underlying meaning for a human reader.

Conclusion

Sentence-pieces represent a "Goldilocks" granularity for Chinese adversarial attacks, offering more flexibility than character-level swaps and more reliability than word-level segmentation. While there is a trade-off between the number of candidates ($K$) and fluency, the piece-level approach ensures that adversarial examples remain remarkably fluent and semantically consistent. Future work may extend this methodology to complex tasks such as Machine Translation or Text Summarization.

Summary updated

Abstract

Adversarial attacks in texts are mostly substitution-based methods that replace words or characters in the original texts to achieve success attacks. Recent methods use pre-trained language models as the substitutes generator. While in Chinese, such methods are not applicable since words in Chinese require segmentations first. In this paper, we propose a pre-train language model as the substitutes generator using sentence-pieces to craft adversarial examples in Chinese. The substitutions in the generated adversarial examples are not characters or words but \textit{'pieces'}, which are more natural to Chinese readers. Experiments results show that the generated adversarial samples can mislead strong target models and remain fluent and semantically preserved.
BibTeX
@misc{li2020generating,
  author = {Linyang Li and Yunfan Shao and Demin Song and Xipeng Qiu and Xuanjing Huang},
  title = {{Generating Adversarial Examples in Chinese Texts Using Sentence-Pieces}},
  year = {2020},
  eprint = {2012.14769},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.14769},
}
Figure