Adaptive Testing and Debugging of NLP Models (2022)

Abstract: Current approaches to testing and debugging NLP models rely on highly variable human creativity and extensive labor, or only work for a very restrictive class of bugs. We present AdaTest, a process which uses large scale language models (LMs) in partnership with human feedback to automatically write unit tests highlighting bugs in a target model. Such bugs are then addressed through an iterative text-fix-retest loop, inspired by traditional software development. In experiments with expert and non-expert users and commercial / research models for 8 different tasks, AdaTest makes users 5-10x more effective at finding bugs than current approaches, and helps users effectively fix bugs without adding new bugs.

## introduction although nlp models are often underspecified and exhibit various generalization failures, finding and fixing such bugs remains a challenge. current approaches include frameworks for testing (e.g. checklist; @xcite , error analysis @xcite , or crowdsourcing (e.g. dynabench; @xcite , all of which depend on highly variable human creativity to imagine bugs and extensive labor to instantiate them. out of these, only crowdsourcing can potentially fix bugs when enough data is gathered. on the other hand, fully automated approaches such as perturbations @xcite , automatic adversarial examples @xcite , and unguided data augmentation @xcite are severely restricted to specific kinds of problems (e.g. @xcite only deal with inconsistent predictions on paraphrases). despite their usefulness, current approaches do not allow a single user to easily specify, discover, and fix undesirable behaviors. in this work, we present adaptive testing (adatest), a process and tool foot_0 that leverages the complementary strengths of humans and large scale language models (lms) to find and fix bugs in nlp models. the lm is tasked with the slow "creative" burden @xcite of generating a large quantity of tests adaptively targeted against the model being tested, while the user steers the lm by only selecting high quality tests and organizing them into semantically related topics -which drastically improves lm generation and guides it towards areas of interest. in an inner testing loop (figure 1 , unrolled in figure 2 ), users start with a set of unit tests in a topic. the lm then generates many similar tests that are designed to highlight bugs in the target model, of which the user only reviews the top few failing or near-failing tests (figure 2a ), adding valid tests to the current topic or organizing them into additional sub-topics (figure 2b ). these user-filtered tests are included in the lm prompt for the next round of suggestions, nudging them toward the intersection between user interest and model failure. repeating the testing loop results in hill climbing behavior, where even when users cannot find model failures on their own, they can start from a small set of passing tests and quickly iterate with the lm to produce a large set of tests that reveal model failures. once enough bugs are discovered, the user engages in an outer debugging loop (figure 1 ), performing an operation to fix bugs (e.g. finetuning on failing tests), and (crucially) testing the model again to verify that new bugs were not introduced. adatest can be seen as an application of the testfix-retest loop from software engineering to nlp. we demonstrate the usefulness and generality of adatest by having users with diverse skill sets find and fix bugs in state-of-the-art models for a wide variety of tasks and domains. in controlled user studies, expert users consistently discovered ∼5x more bugs per minute with adatest (compared to checklist), while users with no technical background discovered ∼10x more (compared to a tool similar to dynabench). our experiments indicate adatest's debugging loop reliably fixes bugs without introducing new ones, in contrast to other forms of data augmentation (templates, counterfactuals @xcite , manual gpt-3 prompting). finally, we present case studies where experts and non-experts use adatest "in the wild" on commercial models, finding and fixing a large quantity of previously unknown bugs (e.g. resulting in an 11.1 f1 improvement over expert gpt-3 augmentation). ## adaptive testing the fundamental unit of specification in adatest is a test, defined as an input string or pair and an expectation about the behavior of the model @xcite . the expectation can specify what the output should or should not be (e.g. for sentiment analysis f("this is so great!!") = pos, f("it's not bad") neg), a property on perturbations such as invariance (e.g. f("good") = f("good.")), or a property of the output (e.g. substring containment in translation; f en-to-pt ("the cake's icing") "cereja", or the output of a classifier c(•) for text generation; c(f gen ("immigrants are")) toxic). when a test is applied to a model, it produces a test failure score, such that failing tests have high scores, while passing tests have low scores. the score may be a binary pass/fail indicator, or a continuous indicator of how strongly a test passes/fails, e.g. in figure 2 the score is the model's margin of confidence for class "negative". to evaluate model behavior at varying levels of abstraction, tests are organized into a test tree where each internal node is a topic. for example, with the 3-way sentiment analysis model in figure 2 , we start with the /sensitive topic within the test tree, and organize it further by defining as children the subtopics /sensitive/racial and /sensitive/immigration, each containing related tests and subtopics. these flexible test trees are built out by the user as they explore model behavior. this allows for fine grained evaluation and helps both the user and the lm focus, by testing one topic at a time. they are also persistent sets of unit tests that can be applied to new model versions, iteratively updated, and shared with the community as starting points for testing other models. ## evaluation we present controlled user studies on the testing loop with both expert and non-expert users (3.1), followed by controlled experiments on the debugging loop (3.2). finally, we present case studies where adatest is used "in the wild" (3.3). ## related work even though we used checklist and dynabench as baselines in the previous section, our results indicate that these and other approaches @xcite where human creativity and effort are bottlenecks @xcite would benefit from the greatly enhanced bug discovery productivity made possible by adatest. on the other hand, checklist as a framework provides great guidance in organizing the test tree, enumerating important capabilities and perturbations to be tested, as well as a tool for systematically applying the test tree to future models. similarly, dynabench provides model serving capabilities and a crowdsourcing platform that would greatly enhance adatest, especially as users share test trees and adapt them to new models. in terms of fixing bugs, fully automatic data augmentation with lms @xcite cannot incorporate human "specification" beyond already existing data, nor debug phenomena that is very far from the existing data. on the other hand, general purpose or contrastive counterfactuals have shown mixed or marginally positive results @xcite similar to what we observed in section 3.2, except when large quantities of data are gathered @xcite . our hypothesis is that underspecification (d'amour et al., 2020) is a major factor limiting the benefit of many counterfactual augmentation techniques. we observed that the first rounds of the debugging loop often decrease or maintain overall performance until additional data from later rounds specifies the correct behavior more thoroughly, which indicates that counterfactual data targeted precisely where the model is underspecified is often more effective than non-targeted data. if true, this hypothesis argues for adatest's fast iteration in the debugging loop, rather than longer cycles (e.g. dynabench rounds can take months). ## conclusion adatest encourages a close collaboration between a human and a language model, yielding the benefits of both. the user provides specification that the lm lacks, while the lm provides creativity at a scale that is infeasible for the user. adatest offers significant productivity gains for expert users, while also remaining simple enough to empower diverse groups of non-experts. the debugging loop connects model testing and debugging to effectively fix bugs, taking model development a step closer towards the iterative nature of traditional software development. we have demonstrated adatest's effectiveness on classification models (sentiment analysis, qqp, toxicity, media selection, task detection), generation models (gpt-2, translation), and per-token models (ner), with models ranging from well-tested production systems to brand new applications. our results indicate that adaptive testing and debugging can serve as an effective nlp development paradigm for a broad range of applications. to help support this, adatest (with various test trees) is open sourced at https://github.com/microsoft/adatest .