On the Robustness of Language Encoders against Grammatical Errors

Fan Yin, Quanyu Long, Tao Meng, Kai-Wei Chang

Introduction

State-of-the-art Natural Language Processing (NLP) models, often referred to as "foundation models," are typically trained on massive, professionally edited corpora like Wikipedia. While these models achieve superhuman performance on standard benchmarks, they often encounter "noisy" text in real-world applications—ranging from social media posts to essays by non-native speakers. This paper investigates a critical vulnerability: the sensitivity of pre-trained language encoders like ELMo, BERT, and RoBERTa to common grammatical errors.

Methodology

The researchers employed a multi-faceted approach to diagnose model behavior under linguistic stress:

  1. Grammatical Error Simulation: Using the NUCLE corpus (NUS Corpus of Learner English), the authors defined confusion sets for eight frequent error types, including Subject-Verb Agreement (SVA), Noun Number (Nn), and Word Choice (Wchoice).
  2. Adversarial Stress-Testing: To identify the "worst-case" scenarios, black-box adversarial attacks (Greedy, Beam Search, and Genetic Algorithms) were used to find specific grammatical mistakes that maximize performance degradation on downstream tasks like sentiment analysis and inference.
  3. Linguistic Probing: The authors froze the encoder layers and trained simple diagnostic classifiers to determine if the models internally recognize grammatical "acceptability" and can "localize" where an error occurs.
  4. Cloze Testing: Using BERT’s Masked Language Model (MLM) objective, the study measured how an error in one part of a sentence affects the prediction of neighboring tokens.

Comparative Robustness

The study evaluated performance across several GLUE tasks and Named Entity Recognition (NER). A primary finding is that model robustness scales with pre-training data and architecture complexity. RoBERTa consistently emerged as the most resilient model, likely due to its larger and more diverse pre-training set, which allows it to learn more stable linguistic representations.

Figure 1: Attack success rate across different models as the perturbation rate increases. RoBERTa shows the highest resistance to adversarial grammatical perturbations.

As shown in Figure 1, while all models are susceptible to targeted attacks, the success rate of attacks against RoBERTa is significantly lower than that of BERT or ELMo at comparable perturbation rates.

Probing Internal Representations

One of the paper's most intriguing insights is that models often "know" an error exists even when their downstream performance suffers. Probing results indicate that internal contextual layers are highly effective at identifying and locating errors.

Figure 2: Sentence-level and token-level error detection accuracy across different encoder layers. Middle and higher layers significantly outperform raw embeddings.

As illustrated in Figure 2, the contextual layers (particularly layers 8 and 12) achieve much higher accuracy in error localization than the initial embedding layers (layer 0). For instance, in Subject-Verb Agreement tasks, BERT’s internal layers reached approximately 93% accuracy in identifying ungrammaticality, compared to only 70% at the input level. This suggests that the models develop a sophisticated internal understanding of grammar that is not always fully utilized by the final task-specific layers.

Neighborhood Pollution and Mitigation

Cloze tests revealed that grammatical errors have a "pollution" effect: a single error significantly drops the prediction likelihood of neighboring tokens, especially those with strong syntactic dependencies (e.g., an incorrect article affecting the following noun).

To address these vulnerabilities, the authors proposed a defense strategy based on adversarial data augmentation. By incorporating a small fraction (e.g., 10%) of simulated adversarial errors into the training set, they were able to recover BERT's accuracy on corrupted data from 46% to 82% without sacrificing performance on clean text.

Conclusion

This research highlights that while modern language encoders are sensitive to grammatical noise, they possess latent capabilities to identify these errors internally. By prioritizing robustness through adversarial training and diverse pre-training data, the NLP community can build models that are not only accurate in "clean-room" environments but also reliable in the messy reality of human communication.

Summary updated

BibTeX
@inproceedings{yin2020robustness,
  author = {Fan Yin and Quanyu Long and Tao Meng and Kai-Wei Chang},
  title = {{On the Robustness of Language Encoders against Grammatical Errors}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-main.310},
}
Figure