On the Robustness of Language Encoders against Grammatical Errors (2020)

Abstract: We conduct a thorough study to diagnose the behaviors of pre-trained language encoders (ELMo, BERT, and RoBERTa) when confronted with natural grammatical errors. Specifically, we collect real grammatical errors from non-native speakers and conduct adversarial attacks to simulate these errors on clean text data. We use this approach to facilitate debugging models on downstream applications. Results confirm that the performance of all tested models is affected but the degree of impact varies. To interpret model behaviors, we further design a linguistic acceptability task to reveal their abilities in identifying ungrammatical sentences and the position of errors. We find that fixed contextual encoders with a simple classifier trained on the prediction of sentence correctness are able to locate error positions. We also design a cloze test for BERT and discover that BERT captures the interaction between errors and specific tokens in context. Our results shed light on understanding the robustness and behaviors of language encoders against grammatical errors.

## introduction pre-trained language encoders have achieved great success in facilitating various downstream natural language processing (nlp) tasks @xcite @xcite . however, they usually assume training and test corpora are clean and it is unclear how the models behave when confronted with noisy input. grammatical error is an important type of noise since it naturally and frequently occurs in natural language, especially in spoken and written materials from non-native speakers. dealing with such a noise reflects model robustness in representing language and grammatical knowledge. it would also have a positive social impact if language encoders can model texts from non-native speakers appropriately. recent work on evaluating model's behaviors against grammatical errors employs various methods, including (1) manually constructing minimal edited pairs on specific linguistic phenomena @xcite @xcite ; (2) labeling or creating acceptability judgment resources @xcite @xcite ; and (3) simulating noises for a specific nlp task such as neural machine translation @xcite , sentiment classification @xcite . these studies either focus on specific phenomena and mainly conduct experiments on designated corpora or rely heavily on human annotations and expert knowledge in linguistics. in contrast, our work automatically simulates natural occurring data and various types of grammatical errors and systematically analyzes how these noises affect downstream applications. this holds more practical significance to understand the robustness of several language encoders against grammatical errors. specifically, we first propose an effective approach to simulating diverse grammatical errors, which applies black-box adversarial attack algorithms based on real errors observed on nus corpus of learner english (nucle) @xcite , a grammatical error correction benchmark. this approach transforms clean corpora into corrupted ones and facilitates debugging language encoders on downstream tasks. we demonstrate its flexibility by evaluating models on four language understanding tasks and a sequence tagging task. we next quantify model's capacities of identifying grammatical errors by probing individual layers of pre-trained encoders through a linguistic acceptability task. we construct separate datasets for eight error types. then, we freeze encoder layers and add a simple classifier on top of each layer to predict the correctness of input texts and locate error positions. this probing task assumes if a simple classifier behaves well on a designated type of error, then the encoder layer is likely to contain knowledge of that error @xcite . finally, we investigate how models capture the interaction between grammatical errors and contexts. we use bert as an example and design an unsupervised cloze test to evaluate its intrinsic functionality as a masked language model (mlm). our contributions are summarized as follows: our work is related to studies on analyzing models with manually created noise. for example, @xcite evaluate whether lstms capture the hierarchical structure of language by using verbal inflection to violate subject-verb agreement. @xcite present a new dataset consisting of minimal edited pairs with the opposite linguistic acceptability on three specific linguistic phenomena and use it to evaluate rnn's syntactic ability. @xcite adjusts previous method to evaluate bert. @xcite further compare five analysis methods under a single phenomenon. despite the diversity in methodology, these studies share common limitations. first, they employ only a single or specific aspects of linguistic knowledge; second, their experiments are mainly based on constructed datasets instead of real-world downstream applications. in contrast, we propose a method to cover a broader range of grammatical errors and evaluate on downstream tasks. a concurrent work @xcite facilitates diagnosing language models by creating linguistic minimal pairs datasets for 67 isolate grammatical paradigms in english using linguistcrafted templates. in contrast, we do not rely heavily on artificial vocabulary and templates. ## method we first explain how we simulate ungrammatical scenarios. then, we describe target models and the evaluation design. ## to what extent models identify grammatical errors? our goal in this section is to assess the ability of the pre-trained encoders in identifying grammatical errors. we use a binary linguistic acceptability task to test the model ability in judging the grammatical correctness of a sentence. we further study whether the model can precisely locate error positions, which reflects the token-level ability. data we construct separate datasets for each specific type of grammatical error. for each dataset, we extract 10,000 sentences whose lengths fall within 10 to 60 tokens from 1b word benchmark @xcite . then, we introduce the target error type to half of these sentences using probabilistic transformation and keep the error rate over each dataset around 3% (resulting in one or two errors in each sentence). sentences are split into training (80%), development (10%) and test (10%). ## how bert captures the interaction between tokens when errors present we aim to reveal the interaction between grammatical errors and their nearby tokens through studying the masked language model (mlm) component of bert. we investigate bert as it is a typical transformer-based encoder. our analysis can be extended to other models. ## adversarial training finally, we explore a data augmentation method based on the proposed grammatical error simulations. we apply the greedy search algorithm to introduce grammatical errors to the training examples of a target task and retrain the model on the combination of original examples and the generated examples. we take the mrpc @xcite dataset as an example to demonstrate the results. we augment the training set of mrpc with different proportions of adversarial examples, fine-tune bert on the augmented training set and then evaluate on both the original development set and the corrupted development set. results are shown in figure 5 . we find that by adding a small number of adversarial examples, the accuracy is recovered from 46% to 82%. as the proportion of augmented adversarial examples increases, the accuracy continues to increase on the corrupted set, with negligible changes to the original validation accuracy. this fact also demonstrates that our simulated examples are potentially helpful for reducing the effect of grammatical errors. ## conclusion in this paper, we conducted a thorough study to evaluate the robustness of language encoders against grammatical errors. we proposed a novel method to simulating grammatical errors and facilitating our evaluations. we studied three pre-trained language encoders, elmo, bert, and roberta and concentrated on three aspects of their abilities against grammatical errors: performance on downstream tasks when confronted with noised texts, ability in identifying errors and capturing the interaction between tokens in the presence of errors. this study shed light on understanding the behaviors of language encoders against grammatical errors and encouraged future work to enhance the robustness of these models.