What’s in a Name? Are BERT Named Entity Representations just as Good for any other Name? (2020)

Abstract: We evaluate named entity representations of BERT-based NLP models by investigating their robustness to replacements from the same typed class in the input. We highlight that on several tasks while such perturbations are natural, state of the art trained models are surprisingly brittle. The brittleness continues even with the recent entity-aware BERT models. We also try to discern the cause of this non-robustness, considering factors such as tokenization and frequency of occurrence. Then we provide a simple method that ensembles predictions from multiple replacements while jointly modeling the uncertainty of type annotations and label predictions. Experiments on three NLP tasks shows that our method enhances robustness and increases accuracy on both natural and adversarial datasets.

## introduction contextual word embeddings from heavily pretrained language models @xcite now form the basis of many nlp tasks. while they have lead to improved accuracy for most tasks, there are mounting concerns on how well these embeddings encapsulate syntactic and semantic constructs such as synonyms, misspellings, and knowledge representations. indeed, it has been shown that even bert based models are not robust to synonym swaps or spelling mistakes in a sentence @xcite @xcite . in this work, we investigate how well these contextual representations fare for named entities. designing robust representations of named entities is challenging due to the sheer variety of named entities. named entities diversify with language, geographical location, time of history, and even with the fine types. adding to this the varying † equal contribution, sorted alphabetically by last name length of such entities combined with out of vocabulary names, the complexity only increases. we quantify how well current systems understand named entities by studying their robustness to substitutions of name mentions in a sentence with other names within an entity class. the entity class within which we seek such robustness is taskdependent and easy for humans to provide. for example, we may require a natural language inference model to be robust to the replacement of company names within the input sentence pairs. in the contributions of this work are three-fold. first, we investigate the robustness of trained nlp models using a generic algorithm that we develop. we empirically demonstrate a lack of robustness of state of the art bert-based models for different user-specified typed classes spanning three nlp tasks: natural language inference (nli), coreference resolution (coref), and grammar error correction (gec). the lack of robustness is specifically of concern for an entity-focused task like coref, where 85% of test sentences have change in their predictions with a single person name change. second, we try to seek explanations for such lack of robustness, by observing performance vs. frequency of named entities occurring in the finetuning dataset or based on the count of tokens sentence 1: magner , who is 54 and known as marge , has been the consumer group 's chief operating officer since april 2002 , and sits on facebook microsoft 's management committee sentence 2: she has been the consumer unit 's chief operating officer since april 2002 , and sits facebook microsoft 's management committee. gold: 1 ; prediction: original: 1; perturbed: 0 sentence 1: the workers accuse goldman novell of " reverse age discrimination " because of a change in retirement benefits in 1997 . sentence 2: goldman novell was sued when it changed its retirement benefits in 1997 . gold: 0 ; prediction: original: 0; perturbed: 1 in a named entity. we also explored if bert's wordpiece-level masking was particularly unfavorable to entities by switching to span-bert, the recent span based masking model. while overall accuracy improved for all datasets with span-bert, we found no change in the robustness of the model. finally, we develop a simple approach that ensembles predictions from multiple replacements (resemble) while modeling the uncertainty of type annotations and label predictions. our approach not only improves performance on adversarial datasets but also on the original datasets, and achieves higher stability on all the tasks. ## evaluating robustness to named-entity replacements we study the robustness of bert-based nlp models w.r.t. type-specific named-entity substitutions, for tasks like nli, gec and coref. algorithm 1 describes our method of probing nlp models for lack of robustness. let v be a dictionary of candidate named entities of a given type c, and d denote a dataset consisting of sentence-label pairs (x, y). let g be a model fine-tuned on a pre-trained bert. for each sentence (x, y) ∈ d, we identify the mentions of named-entities of the type c in x 1 . we obtain a perturbed sentence x m by replacing all mentions of a distinct name in x by a random entry from v . we repeat this process b times where b is a budget (we used 50), with replacement of names. over the b perturbations, the sentence with the lowest accuracy is added to the set d worst and the highest accuracy added to the set d best . a lower variance in model's performance across the datasets {d, d worst , d best } is indicative of higher robust1 we pre-filtered using a named entity tagger in the spacy library, and made manual corrections so that all tagged entity mentions are correct in d. ## enhancing robustness we propose a simple ensembling with replacements approach (referred to as resemble) that does not require any retraining and can work with any existing pre-trained language model. we assume a type annotator t that marks mentions of entities of the type c for which robustness needs to enhanced. the type-annotator might be noisy. we identify a small set m of entities of type c on which the model provides high accuracy on a validation set. we call these the list of canonical entities. given any input x, we invoke the task-specific model g to obtain predicted labels ŷ and the type annotator t to obtain type annotations ẑ. if ẑ denotes that a named entity of type c is present in one or more spans of x, we generate new sentences x m by replacing the named entities with canonical named entities @xmath0. the model g when applied to x m generates prediction ŷm . let the true labels of x and x m be y and y m respectively, and the true type of x be z. if the type annotator correctly identified the spans corresponding to concept class c (i.e., @xmath1, y and all y m s have to agree as per our requirement of robustness. we use this to define a revised distribution over true y from the individual predictions as follows: the above is an annotator confidence weighted average of two terms: the first half calculates the probability of y from the default model g when the type annotator may be wrong and the y m predictions should be ignored. the second half calculates the ensembled agreement probability when the type annotator is correct. we calculate that as a geometric mean of the predictions from the different replacements. in the above equation, the ensembled released span-bert checkpoints were not compatible with the gec model probability is under the simplifying assumption that all entity replacements have the same number of tokens. during implementation, we remove this assumption, and implement a more detailed span-level agreement for variable-length entities. an important requirement for the above expression is that the probabilities provided by the different models express true uncertainty of predictions, that is, they be well-calibrated. unfortunately, modern neural networks tend to be uncalibrated. to calibrate the probabilities, we use a popular method called temperature scaling @xcite where probabilities are raised by an exponent, which is the inverse of the temperature. temperature scaling flattens the probability distribution over output classes thus reduces the confidence until it is correctly calibrated. the expression is as follows: the temperature hyper-parameter t is fixed from a validation dataset. note we do not apply temperature scaling to the predictions from the canonical entries. ## conclusions and future work in this work we show that state of the art bertbased models are surprisingly brittle to named entity replacements. we propose resemble, a simple ensembling approach to increase robustness while also improving nominal accuracy. the gen-eral paradigm of enhancing robustness via ensembles on guided instance perturbations is a promising direction and needs to be explored for other tasks too.