A uto P rompt: E liciting K nowledge from L anguage M odels with A utomatically G enerated P rompts (2020)

Abstract: The remarkable success of pretrained language models has motivated the study of what kinds of knowledge these models learn during pretraining. Reformulating tasks as fill-in-the-blanks problems (e.g., cloze tests) is a natural approach for gauging such knowledge, however, its usage is limited by the manual effort and guesswork required to write suitable prompts. To address this, we develop AutoPrompt, an automated method to create prompts for a diverse set of tasks, based on a gradient-guided search. Using AutoPrompt, we show that masked language models (MLMs) have an inherent capability to perform sentiment analysis and natural language inference without additional parameters or finetuning, sometimes achieving performance on par with recent state-of-the-art supervised models. We also show that our prompts elicit more accurate factual knowledge from MLMs than the manually created prompts on the LAMA benchmark, and that MLMs can be used as relation extractors more effectively than supervised relation extraction models. These results demonstrate that automatically generated prompts are a viable parameter-free alternative to existing probing methods, and as pretrained LMs become more sophisticated and capable, potentially a replacement for finetuning.

## introduction pretrained language models (lms) have had exceptional success when adapted to downstream tasks via finetuning @xcite . although it is clear that pretraining improves accuracy, it is difficult to determine whether the knowledge that finetuned lms contain is learned during the pretraining or the finetuning process. how can we directly evaluate the knowl-edge present in pretrained lms, be it linguistic, factual, commonsense, or task-specific? numerous techniques have been proposed to elicit such knowledge by analyzing pretrained lms' internal representations. a common strategy is to use probing classifiers-shallow classifiers that predict certain attributes using an lms' representations as features @xcite . however, probing classifiers require additional learned parameters and are thus susceptible to false positives; high probing accuracy is not a sufficient condition to conclude that an lm contains a certain piece of knowledge @xcite . attention visualization, another common technique, has a similar failure mode: attention scores may be correlated with, but not caused by the underlying target knowledge, leading to criticism against their use as explanations @xcite . both probing and attention visualizations also struggle to evaluate knowledge that cannot be represented as simple token-or sequencelevel classification tasks. a more direct approach for eliciting knowledge from these models, since they are language models after all, is prompting, i.e. converting tasks into a language model format. for example, @xcite frame summarization as a language modeling task by appending "tl;dr:" to the end of an article and then generating from an lm. similarly, @xcite manually reformulate a knowledge base completion task as a cloze test (i.e., a fill-in-the-blank problem). compared to existing model analysis methods, prompting is noninvasive: it does not introduce large amounts of additional parameters or require direct inspection of a model's representations. thus prompting provides a lower bound on what the model "knows", and is therefore a more useful analysis tool. however, prompting unfortunately requires manually masked lm cris marvelous worse incompetence worse philanthrop positive negative + + original input a real joy. autoprompt a real joy. atmosphere alot dialogue clone totally @xcite . ## overview of autoprompt a natural way to elicit knowledge from pretrained lms is to pose tasks as fill-in-the-blank problems. however, writing prompts is not only time consuming, but it is not clear that the same phrasing will be effective for every model, nor is it clear what crite-ria determine whether a particular phrasing the best to elicit the desired information. in light of this, we introduce autoprompt, a method that constructs customized prompts for a specific task and mlm of interest, to cause the mlms to produce the desired knowledge. 1 an illustration of autoprompt is provided in figure 1 . the prompt is constructed by taking the original task inputs-a collection of one or more sequences of tokens (e.g., the review in figure 1 )-and mapping them to a sequence of tokens using a template. in the following sections, we describe how autoprompt uses labeled training data to construct prompts, and how it uses the output of the mlm as a prediction for the task. ## sentiment analysis sentiment analysis is a fundamental task in nlp, both for natural language understanding research and real-world applications. it is also difficult to probe the extent to which mlms understand sentiment without finetuning. setup we apply our method to convert instances from the binary stanford sentiment treebank @xcite , sst-2) into prompts, using the standard train/test splits. we find label tokens using a prompt based on the template in ## natural language inference to evaluate the semantic understanding of mlms, we experiment on natural language inference (nli). nli is crucial in many tasks such as reading comprehension and commonsense reasoning @xcite , and it is used as a common benchmark for language understanding. setup we use the entailment task from the sick dataset @xcite which consists of around 10,000 pairs of human-annotated sentences labeled as entailment, contradiction, and neutral. the standard dataset is biased toward the neutral class which represent 56.7% of instances. we also experiment on an unbiased variant with 2-way classification of contradiction vs. entailment (2-way), as well as an unbiased 3-way clas- results we also examine the efficacy of autoprompt in the low-data regime (using the same procedure as sst-2) on the unbiased 3-way sick-e data. the results in figure 2 show that autoprompt performs on par with finetuned bert and significantly better than finetuned roberta in low data settings. ## fact retrieval an important question is whether pretrained mlms know facts about real-world entities. the lama dataset @xcite evaluates this using cloze tests that consist of (sub, rel, obj) triples, e.g. (obama, bornin, hawaii), and manually created prompts with missing objects, e.g. "obama was born in @xcite .". lpaqa @xcite extends this idea by systematically creating prompts that are generated by mining wikipedia, paraphrasing, and crowdsourcing. in this section, we use the same cloze-style setup but automatically generate prompts in order to better evaluate the factual knowledge of mlms. we compare our approach against lama and lpaqa, which are explicitly designed for the task of fact retrieval. setup we reformulate fact retrieval by mapping (sub,rel,obj) triples to a prompt using the template "{sub}[t]. . . @xcite .", where the trigger tokens are specific to the relation rel and the correct object obj is the label token. we use the original test set from lama @xcite , henceforth original. to collect training data for autoprompt, we gather at most 1000 facts for each of the 41 relations in lama from the t-rex dataset @xcite . for the relations that still have less than 1000 samples, we gather extra facts straight from wikidata. we ensure that none of the t-rex triples are present in the test set, and we split the data 80-20 into train and development sets. moreover, because the collected t-rex data is from a slightly different distribution than the lama test set, we also consider a separate evaluation where we split the t-rex triples into a 60-20-20 train/dev/test split and evaluate on the test set. this t-rex dataset is used to measure the performance of our prompts when the train and test data is from the same distribution. we use autoprompt with 5 or 7 tokens, and select the search parameters using the t-rex development set. we prevent proper nouns and tokens that appear as gold objects in the training data from being selected as trigger tokens. this is done to prevent autoprompt from "cheating" by embedding common answers inside the prompt. to evaluate, we observe the rank of the true object in label token distribution of the mlm, and use standard ranking metrics: mean reciprocal rank (mrr), precision-at-1 (p@1), and precision-at-10 (p@10). task prompt template prompt found by autoprompt label tokens sentiment analysis {sentence} [t]. . . [t] [p]. unflinchingly bleak and desperate writing academicswhere overseas will appear [mask]. pos: partnership, extraordinary, ##bla neg: worse, persisted, unconstitutional nli {prem}[p][t]. . . [t]{hyp} two dogs are wrestling and hugging [mask] concretepathic workplace there is no dog wrestling and hugging con: nobody, nobody, nor ent: ##found, ##ways, agency neu: ##ponents, ##lary, ##uated fact retrieval x plays y music {sub}[t]. . . [t][p]. hall overton fireplacemade antique son alto [mask]. relation extraction x is a y by profession {sent}{sub}[t]. . . [t][p]. leonard wood (born february 4, 1942) is a former canadian politician. leonard wood gymnasium brotherdicative himself another [mask]. ## relation extraction apart from evaluating whether mlms know facts, it is also important to evaluate whether they can extract knowledge from text. in this section, we use the task of relation extraction (re)-to identify how entities are related in a given sentence-an important task in information extraction. we create re prompts in a similar fashion as fact retrieval: for a given triple (subj,rel,obj) and sentence that expresses this relation, we construct a prompt as "{sent}{sub}[t]. . . @xcite .", where the trigger tokens are specific to the relation, and label token is the correct object obj (see ## discussion prompting as an alternative to finetuning the goal of prompting a language model is to probe the knowledge that the model acquired from pretraining. nevertheless, prompting has some practical advantages over finetuning for solving realworld tasks. first, as shown in section 3, prompts generated using autoprompt can achieve higher accuracy than finetuning in the low-data regime. moreover, prompting has advantages over finetuning when trying to solve many different tasks (e.g., the many users of the openai gpt-3 api brown et al. 2020). in particular, finetuning requires storing large language model checkpoints for each in- ## conclusion in this paper, we introduce autoprompt, an approach to develop automatically-constructed prompts that elicit knowledge from pretrained mlms for a variety of tasks. we show that these prompts outperform manual prompts while requiring less human effort. furthermore, the results for sentiment analysis and textual entailment suggest that, in some data-scarce settings, it may be more effective to prompt language models than to finetune them for the task. although we focus only on masked language models in this paper, our method can be trivially extended to standard language models, and thus maybe useful for constructing inputs for models like @xcite . source code and datasets to reproduce the results in this paper is available at http://ucinlp.github.io/autoprompt . varying the number of trigger tokens generally has little effect. on the other hand, there is a substantial increase in accuracy when increasing the label set size from 1 to 3 (approximately +5% for bert, and +10% for roberta). after analyzing the label sets, we find that our method generally produces intuitive results-"marvelous" and "philanthrop" are associated with positive sentiment, whereas "worse" and "incompetence" are associated with negative sentiment for roberta. since our goal is to extract the object of relation triplets, rather than the relation itself, we tweak the standard re evaluation. we feed the re model sentences from test facts and we query the resulting graph for all edges that contain the given subject and relation. then we select the triple with the highest confidence and compare it's object to the gold object. we do this for every fact and take the average across all relations to get the overall precision. the re model is not trained to predict two of the original t-rex relations. for fair comparison, we exclude these two relations for our evaluation.