Reza8848's picture
Track large files with Git LFS
837b615
{
"id": "2012.15723",
"annotator": "sarkar",
"input": [
"\\documentclass[11pt,a4paper]{article}\n",
"\\usepackage[hyperref]{acl2021}\n",
"\\usepackage{times}\n",
"\\usepackage{latexsym}\n",
"\\renewcommand{\\UrlFont}{\\ttfamily\\small}\n",
"\\usepackage{microtype}\n",
"\\usepackage{array}\n",
"\\usepackage{pifont}\n",
"\\usepackage{tabularx}\n",
"\\usepackage{adjustbox}\n",
"\\usepackage{multirow}\n",
"\\usepackage{enumitem}\n",
"\\usepackage{xspace}\n",
"\\usepackage{tcolorbox}\n",
"\\usepackage{booktabs,subcaption,amsfonts,dcolumn}\n",
"\\usepackage{hyperref}\n",
"\\usepackage{url}\n",
"\\usepackage{amsmath,amsthm,amsfonts,amssymb,bm,stmaryrd}\n",
"\\usepackage{xcolor}\t\t\n",
"\\usepackage[noorphans,vskip=0.75ex,leftmargin=2ex]{quoting}\n",
"\\aclfinalcopy \n",
"\\def\\aclpaperid{982} \n",
"\\definecolor{darkblue}{rgb}{0, 0, 0.5}\n",
"\\hypersetup{colorlinks=true, citecolor=darkblue, linkcolor=darkblue, urlcolor=darkblue}\n",
"\\usepackage[compact]{titlesec}\n",
"\\titlespacing{\\section}{0pt}{2ex}{1ex}\n",
"\\titlespacing{\\subsection}{0pt}{1ex}{1ex}\n",
"\\setlength{\\parskip}{0cm}\n",
"\\setlength{\\parindent}{1em}\n",
"\\providecommand{\\todo}[1]{\n",
"}\n",
"\\providecommand{\\danqi}[1]{\n",
" {\\protect\\color{purple}{[Danqi: #1]}}\n",
"}\n",
"\\providecommand{\\tianyu}[1]{\n",
" {\\protect\\color{blue}{[Tianyu: #1]}}\n",
"}\n",
"\\providecommand{\\adam}[1]{\n",
" {\\protect\\color{teal}{[Adam: #1]}}\n",
"}\n",
"\\newcommand{\\cmark}{\\ding{51}}\n",
"\\newcommand{\\xmark}{\\ding{55}}\n",
"\\newcommand\\sys[1]{\\textsc{#1}}\n",
"\\newcommand\\ti[1]{\\textit{#1}}\n",
"\\newcommand\\ts[1]{\\textsc{#1}}\n",
"\\newcommand\\tf[1]{\\textbf{#1}}\n",
"\\newcommand\\ttt[1]{\\texttt{#1}}\n",
"\\newcommand\\mf[1]{\\mathbf{#1}}\n",
"\\newcommand\\tmp[1]{\\color{gray}{#1}}\n",
"\\newcommand\\warn[1]{\\textbf{\\color{red}{#1}}}\n",
"\\providecommand{\\todon}{\n",
" {\\protect\\color{red}{00.0 (0.0)}}\n",
"}\n",
"\\newcommand{\\ours}{LM-BFF\\xspace}\n",
"\\newcommand{\\dtrain}{\\mathcal{D}_{\\text{train}}}\n",
"\\newcommand{\\ddev}{\\mathcal{D}_{\\text{dev}}}\n",
"\\newcommand{\\dtest}{\\mathcal{D}_{\\text{test}}}\n",
"\\newcommand{\\seedset}{\\mathcal{S}_{\\text{seed}}}\n",
"\\newcommand{\\maskx}{\\texttt{<X>}}\n",
"\\newcommand{\\masky}{\\texttt{<Y>}}\n",
"\\newcommand{\\maskz}{\\texttt{<Z>}}\n",
"\\newcommand{\\lsent}{\\texttt{<}S_1\\ttt{>}}\n",
"\\newcommand{\\lfirstsent}{\\texttt{<}S_1\\ttt{>}}\n",
"\\newcommand{\\lsecondsent}{\\texttt{<}S_2\\ttt{>}}\n",
"\\newcommand{\\sent}{\\ttt{<}$S_1$\\ttt{>}}\n",
"\\newcommand{\\firstsent}{\\ttt{<}$S_1$\\ttt{>}}\n",
"\\newcommand{\\secondsent}{\\ttt{<}$S_2$\\ttt{>}}\n",
"\\newcommand{\\xinput}{{x}_{\\mathrm{in}}}\n",
"\\newcommand{\\xprompt}{x_{\\mathrm{prompt}}}\n",
"\\newcommand{\\gen}{\\mathrm{g}}\n",
"\\newcommand{\\template}{\\mathcal{T}}\n",
"\\newcommand{\\lwordset}{\\mathcal{W}}\n",
"\\newcommand{\\lwordmap}{\\mathcal{M}}\n",
"\\newcommand{\\vocabulary}{\\mathcal{V}}\n",
"\\newcommand{\\labelset}{\\mathcal{Y}}\n",
"\\newcommand{\\mapping}{\\mathcal{M}}\n",
"\\newcommand{\\totalk}{K_{\\text{tot}}}\n",
"\\newcommand{\\lm}{\\mathcal{L}}\n",
"\\newcommand{\\cls}{\\texttt{[CLS]}}\n",
"\\newcommand{\\sep}{\\texttt{[SEP]}}\n",
"\\newcommand{\\mask}{\\texttt{[MASK]}}\n",
"\\DeclareMathOperator*{\\argmax}{arg\\,max}\n",
"\\DeclareMathOperator*{\\argmin}{arg\\,min}\n",
"\\renewcommand{\\paragraph}[1]{\\vspace{0.2cm}\\noindent\\textbf{#1}}\n",
"\\newcommand{\\tpf}[1]{\\noindent\\textbf{#1}}\n",
"\\newcommand{\\tableindent}{~~}\n",
"\\newcommand\\BibTeX{B\\textsc{ib}\\TeX}\n",
"\\title{Making Pre-trained Language Models Better Few-shot Learners}\n",
"\\author{Tianyu Gao$^{\\dagger*}$ \\quad Adam Fisch$^{\\ddagger*}$ \\quad Danqi Chen$^{\\dagger}$ \\\\\n",
"$^{\\dagger}$Princeton University\\quad $^{\\ddagger}$Massachusetts Institute of Technology\\\\\n",
"\\ttt{\\{tianyug,danqic\\}@cs.princeton.edu}\\\\\n",
"\\ttt{[email protected]}\n",
"}\n",
"\\date{}\n",
"\\begin{document}\n",
"\\maketitle\n",
"\\renewcommand{\\thefootnote}{\\fnsymbol{footnote}}\n",
"\\footnotetext[1]{The first two authors contributed equally.}\n",
"\\renewcommand{\\thefootnote}{\\arabic{footnote}}\n",
"\\begin{abstract}\n",
"The recent GPT-3 model~\\cite{brown2020language} achieves remarkable few-shot performance solely by leveraging a natural-language prompt and a few task demonstrations as input context.\n",
"Inspired by their findings, we study few-shot learning in a more practical scenario, where we use smaller language models for which fine-tuning is computationally efficient.\n",
"\\end{abstract}\n",
"\\section{Introduction}\n",
"\\begin{figure*}[t]\n",
" \\centering\n",
" \\includegraphics[width=0.95\\textwidth]{figures/in_context3.pdf}\n",
" \\caption{An illustration of (a) masked language model (MLM) pre-training, (b) standard fine-tuning, and (c) our proposed {\\ours} using prompt-based fine-tuning with demonstrations. The underlined text is the task-specific \\emph{template}, and colored words are \\emph{label words}.}\n",
" \\label{fig:overview}\n",
"\\end{figure*}\n",
"\\label{sec:intro}\n",
"The GPT-3 model \\cite{brown2020language} has made waves in the NLP community by demonstrating astounding few-shot capabilities on myriad language understanding tasks.\n",
"Given only a \\ti{natural language prompt} and a few \\emph{demonstrations} of the task, GPT-3 is able to make accurate predictions without updating any of the weights of its underlying language model.\n",
"However, while remarkable, GPT-3 consists of 175B parameters, which makes it challenging to use in most real-wold applications.\n",
"In this work, we study a more practical scenario in which we only assume access to a moderately-sized language model such as BERT~\\cite{devlin2019bert} or RoBERTa~\\cite{liu2019roberta}, and a small number of examples (i.e., a \\emph{few-shot} setting), which we can use to fine-tune the weights of\n",
"the language model.\n",
"This setting is appealing as\n",
"(1) such models can be trained on typical research hardware;\n",
"(2) few-shot settings are realistic, as it is generally both easy to acquire a few annotations (e.g., 32 examples) and efficient to train on them; and\n",
"(3) updating parameters typically leads to better performance.\n",
"Inspired by GPT-3's findings, we propose several novel strategies for expanding its few-shot learning abilities to our setting, considering both classification and---for the first time---regression.\n",
"First, we follow the route of \\ti{prompt-based} prediction, first developed by the GPT series~\\cite{radford2018improving,radford2019language,brown2020language} for zero-shot prediction and recently studied by PET~\\cite{schick2020exploiting, schick2020size} for fine-tuning.\n",
"Prompt-based prediction treats the downstream task as a (masked) language modeling problem, where the model directly generates a textual response (referred to as a \\emph{label word}) to a given prompt defined by a task-specific \\emph{template} (see Figure~\\ref{fig:overview}(c)).\n",
"Finding the right prompts, however, is an art---requiring both domain expertise and an understanding of the language model's inner workings.\n",
"Even if significant effort is invested, manual prompts are likely to be suboptimal.\n",
"We address this issue by introducing automatic prompt generation, including a pruned brute-force search to identify the best working label words, and a novel decoding objective to automatically generate templates using the generative T5 model~\\cite{raffel2020exploring}---all of which only require the few-shot training data. This allows us to cheaply obtain effective prompts that match or outperform our manually chosen ones.\n",
"Second, we adopt the idea of incorporating demonstrations \n",
"as\n",
"additional context.\n",
"and we obtain gains up to 30\\\n",
"For instance, we find that a RoBERTa-large model achieves around 90\\\n",
"\\section{Related Work}\n",
"\\label{sec:related_work}\n",
"\\tpf{Language model prompting.} The GPT series~\\citep{radford2018improving,radford2019language,brown2020language} fueled the development of prompt-based learning,\n",
"and we follow many of its core concepts.\n",
"We are also greatly inspired by the recent PET work~\\citep{schick2020exploiting,schick2020size}, although they mainly focus on a semi-supervised setting where a large set of unlabeled examples are provided.\n",
"Furthermore, we deviate from their evaluation by providing a more rigorous framework, as we will discuss in \\S\\ref{sec:setup}.\n",
"Finally, there is a large body of work on prompting for mining knowledge from pre-trained models \\cite[][\\emph{inter alia}]{trinh2018simple,petroni2019language,davison2019commonsense,talmor2020olmpics}. Different from these works, we focus on leveraging prompting for fine-tuning on downstream tasks.\n",
"\\paragraph{Automatic prompt search.}\n",
"\\citet{schick2020exploiting} and \\citet{schick2020automatically} explore ways of identifying label words automatically,\n",
"however, none of these results lead to better performance compared to hand-picked ones.\n",
"Several other attempts have been made in addition---yet these approaches either operate in limited domains,\n",
"such as finding patterns to express specific relations~\\cite{jiang2020can},\n",
"or require a large number of examples for gradient-guided search~\\cite{shin2020autoprompt,zhong2021factual}. Our approach aims to develop general-purpose search methods that rely only on a few annotations.\n",
"\\paragraph{Fine-tuning of language models.} A number of recent studies have focused on better methods for fine-tuning language models~\\cite{howard2018universal,dodge2020fine,lee2020mixout, zhang2020revisiting}. These works mainly focus on optimization and regularization techniques to stabilize fine-tuning. Here we use standard optimization techniques, and instead mainly focus our efforts on better prompt-based fine-tuning in a more extreme few-shot setting. We anticipate that results of these studies are largely complementary to ours.\n",
"\\paragraph{Few-shot learning.} Broadly speaking, our setting is also connected to other few-shot learning paradigms in NLP, including\n",
"(1) {semi-supervised learning}~\\cite{miyato2017adversarial,xie2020unsupervised,chen2020mixtext}, where a set of unlabeled examples are given;\n",
"(2) {meta-learning}~\\cite{yu2018diverse,han2018fewrel,bansal2020learning,bansal2020self, bao2020fewshot}, where a set of auxiliary tasks are given; and\n",
"(3) {intermediate training}~\\cite{phang2018sentence,yin2020universal}, where a related, intermediate task is given. We deviate from these settings by making minimal assumptions about available resources: we only assume a few annotated examples and a pre-trained language model. Our focus is on understanding how far we can push without any other advantages.\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{llcrrrcl}\n",
"\\toprule\n",
"\\tf{Category} & \\tf{Dataset} & $|\\mathcal{Y}|$ & $L$ & \\#Train & \\#Test & \\tf{Type} & \\tf{Labels (classification tasks)} \\\\\n",
"\\bottomrule\n",
" & SST-2 & 2 & 19 & 6,920 & 872 & sentiment & positive, negative \\\\\n",
"& SST-5 & 5 & 18 & 8,544 & 2,210 & sentiment & v. pos., positive, neutral, negative, v. neg. \\\\\n",
"& MR & 2 & 20 & 8,662& 2,000 & sentiment & positive, negative \\\\\n",
"single- & CR & 2 & 19 & 1,775 & 2,000 & sentiment & positive, negative \\\\\n",
"sentence & MPQA & 2 & 3 & 8,606 & 2,000 & opinion polarity & positive, negative \\\\\n",
"& Subj & 2 & 23 & 8,000 & 2,000 & subjectivity & subjective, objective \\\\\n",
"& TREC & 6 & 10 & 5,452 & 500 & question cls. & abbr., entity, description, human, loc., num.\\\\\n",
"& CoLA & 2 & 8 & 8,551 & 1,042 & acceptability & grammatical, not\\_grammatical\\\\\n",
"\\midrule\n",
" & MNLI & 3 & 22/11 & 392,702 & 9,815 & NLI & entailment, neutral, contradiction\\\\\n",
"& SNLI & 3 & 14/8 & 549,367 & 9,842 & NLI & entailment, neutral, contradiction \\\\\n",
"sentence- & QNLI & 2 & 11/30 & 104,743 & 5,463 & NLI & entailment, not\\_entailment \\\\\n",
"pair & RTE & 2 & 49/10 & 2,490 & 277 & NLI & entailment, not\\_entailment \\\\\n",
" & MRPC & 2 & 22/21 & 3,668 & 408 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& QQP & 2 & 12/12 & 363,846 & 40,431 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& STS-B & $\\mathcal{R}$ & 11/11 & 5,749 & 1,500 & sent. similarity & - \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{The datasets evaluated in this work. $|\\mathcal{Y}|$: \\# of classes for classification tasks (with one exception: STS-B is a real-valued regression task over the interval $[0, 5]$). $L$: average \\# of words in input sentence(s). Note that we only sample $\\dtrain$ and $\\ddev$ of $K \\times |\\labelset|$ examples from the original training set in our few-shot experiments (\\S\\ref{sec:setup}).}\n",
"\\label{tab:datasets}\n",
"\\end{table*}\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{lll}\n",
"\\toprule\n",
"\\tf{Task} & \\tf{Template} & \\tf{Label words}\\\\\n",
"\\midrule\n",
"SST-2 & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"SST-5 & {\\sent} It was {\\mask} . & v.positive: great, positive: good, neutral: okay, negative: bad, v.negative: terrible\\\\\n",
"MR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"CR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"Subj & {\\sent} This is {\\mask} . & subjective: subjective, objective: objective \\\\\n",
"TREC & {\\mask} : {\\sent} & abbreviation: Expression, entity: Entity, description: Description \\\\\n",
"&& human: Human, location: Location, numeric: Number \\\\\n",
"COLA & {\\sent} This is {\\mask} . & grammatical: correct, not\\_grammatical: incorrect \\\\\n",
"\\midrule\n",
"MNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No \\\\\n",
"SNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No\\\\\n",
"QNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"RTE & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"MRPC & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"QQP & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"STS-B & {\\firstsent} {\\mask} , {\\secondsent} & $y_u$: Yes, $y_l$: No \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"STS-B is a regression task (\\S\\ref{sec:regression}).\n",
"}\n",
"\\label{tab:manual_prompts}\n",
"\\vspace{-5pt}\n",
"\\end{table*}\n",
"\\section{Problem Setup}\n",
"\\label{sec:setup}\n",
"\\paragraph{Task formulation.}\n",
"In this work, we assume access to a pre-trained language model $\\lm$ that we wish to fine-tune on a task $\\mathcal{D}$ with a label space $\\labelset$. For the task, we only assume $K$ training examples \\emph{per class}\\footnote{For regression, we partition the data into two ``classes'' according to being above or below the median value.} for the task's training set $\\dtrain$, such that the total number of examples is $\\totalk = K \\times |\\labelset|$, and $\\dtrain = \\{(\\xinput^i, y^i)\\}_{i=1}^{\\totalk}$.\n",
"Our goal is then to develop task-agnostic learning strategies that generalize well to an unseen test set $(\\xinput^{\\text{test}}, y^{\\text{test}})\\sim \\dtest$. \n",
"For model selection and hyper-parameter tuning, we assume a development set $\\ddev$, of the same size as the few-shot training set, i.e., $|\\ddev| = |\\dtrain|$. This distinction is important: using a larger development set confers a significant advantage\n",
"(see our experiments in Appendix~\\ref{app:dev_size}),\n",
"and subverts our initial goal of learning from limited data.\\footnote{In contrast, \\newcite{schick2020exploiting,schick2020size} do not use a development set, and adopt a set of hyper-parameters based on practical considerations.\n",
"This is akin to ``shooting in the dark'' on a setting that we show can have unintuitive outcomes.}\n",
"\\paragraph{Evaluation datasets.}\n",
"including\n",
"8 tasks from the GLUE benchmark~\\cite{wang2019glue},\n",
"SNLI~\\cite{bowman2015large_snli}, and 6 other popular sentence classification tasks (SST-5, MR, CR, MPQA, Subj, TREC). All of the dataset details are provided in Appendix~\\ref{app:datasets}. For \\emph{single-sentence} tasks, the goal is to make a prediction based on an input sentence $\\xinput = x_1$, such as whether a movie review is positive or not. For \\emph{sentence-pair} tasks, the goal is to take a pair of input sentences $\\xinput = (x_1, x_2)$ and predict the relationship between them. We also interchangeably refer to the inputs as {\\firstsent} or (\\firstsent, \\secondsent).\n",
"Note that we mainly use SST-2 and SNLI for pilot experiments and model development, making it close to a true few-shot setting, at least for all the other datasets we evaluate on.\n",
"\\begin{comment}\n",
"\\vspace{-3pt}\n",
"\\begin{enumerate}[leftmargin=*]\n",
" \\item \\emph{Single-sentence tasks.} The goal is to make a prediction based on an input sentence $\\xinput = x_1$ (sometimes referred as \\firstsent), such as whether a movie review is positive or not.\n",
" Our tasks range from sentiment analysis to question classification and grammaticality assessment.\n",
" \\vspace{-3pt}\n",
" \\item \\emph{Sentence-pair tasks.} The goal is to make a prediction based on a pair of input sentences $\\xinput = (x_1, x_2)$ (sometimes referred as \\firstsent, \\secondsent), such as predicting the relationship between them.\n",
" Our tasks include natural language inference and paraphrase detection.\n",
"\\end{enumerate}\n",
"\\vspace{-3pt}\n",
"\\end{comment}\n",
"\\paragraph{Evaluation protocol.}\n",
"Systematically evaluating few-shot performance can be tricky.\n",
"It is well-known that\n",
"fine-tuning on small datasets can suffer from instability~\\cite{dodge2020fine,zhang2020revisiting}, and results may change dramatically given a new split of data.\n",
"This issue has also been discussed in\n",
"\\newcite{schick2020size}---they suggest using a fixed set of training examples. We argue that sampling\n",
"multiple splits gives a\n",
"more robust measure of performance,\n",
"and a better estimate of the variance.\n",
"We also observe that hyper-parameters\n",
"can make a significant difference,\n",
"thus we sweep multiple hyper-parameters for each data sample, and take the best setting as measured on the $\\ddev$ of that sample (see Appendix~\\ref{app:hyper_selection}).\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{lll}\n",
"\\toprule\n",
"\\tf{Task} & \\tf{Template} & \\tf{Label words}\\\\\n",
"\\midrule\n",
"SST-2 & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"SST-5 & {\\sent} It was {\\mask} . & v.positive: great, positive: good, neutral: okay, negative: bad, v.negative: terrible\\\\\n",
"MR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"CR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"Subj & {\\sent} This is {\\mask} . & subjective: subjective, objective: objective \\\\\n",
"TREC & {\\mask} : {\\sent} & abbreviation: Expression, entity: Entity, description: Description \\\\\n",
"&& human: Human, location: Location, numeric: Number \\\\\n",
"COLA & {\\sent} This is {\\mask} . & grammatical: correct, not\\_grammatical: incorrect \\\\\n",
"\\midrule\n",
"MNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No \\\\\n",
"SNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No\\\\\n",
"QNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"RTE & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"MRPC & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"QQP & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"STS-B & {\\firstsent} {\\mask} , {\\secondsent} & $y_u$: Yes, $y_l$: No \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"STS-B is a regression task (\\S\\ref{sec:regression}).\n",
"}\n",
"\\label{tab:manual_prompts}\n",
"\\vspace{-5pt}\n",
"\\end{table*}\n",
"\\section{Prompt-based Fine-tuning}\n",
"\\label{sec:prompt_finetuning}\n",
"Given a masked language model\n",
"$\\lm$,\n",
"we first convert input $\\xinput$ to a token sequence $\\tilde{x}$, and the language model $\\lm$ then\n",
"maps $\\tilde{x}$ to a sequence of hidden vectors $\\{\\mf{h}_k \\in \\mathbb{R}^d\\}$.\n",
"During standard fine-tuning, we usually take $\\tilde{x}_{\\text{single}} = \\cls x_1 \\sep$ or $\\tilde{x}_{\\text{pair}} = \\cls x_1 \\sep x_2 \\sep$.\n",
"For downstream classification tasks with a label space $\\labelset$, we train a task-specific head, $\\mathrm{softmax}(\\mf{W}_o \\mf{h}_{\\cls})$, by maximizing the log-probability of the correct label, where $\\mf{h}_{\\cls}$ is the hidden vector of \\cls, and $\\mf{W}_o \\in \\mathbb{R}^{\\mathcal{|\\labelset|} \\times d}$ is a set of randomly initialized parameters introduced at the start of fine-tuning.\n",
"Similarly, for a regression task, we can introduce $\\mf{w}_o \\in \\mathbb{R}^d$ and optimize the mean squared error between $\\mf{w}_o \\cdot \\mf{h}_{\\cls}$ and the gold label.\n",
"In either case, the number of new parameters can be substantial---for example, a simple binary classification task will introduce 2,048 new parameters for a RoBERTa-large model---making it challenging to learn from a small amount of annotated data (e.g., 32 examples).\n",
"An alternative approach to solving this problem is \\ti{prompt-based fine-tuning}, in which $\\lm$ is directly tasked with ``auto-completing'' natural language prompts. \n",
"For instance, we can formulate a binary sentiment classification task using a prompt with\n",
"input $x_1$\n",
"(e.g., ``\\ti{No reason to watch it .}'') as:\n",
"\\begin{equation*}\n",
" \\resizebox{.85\\hsize}{!}{\n",
" $\\xprompt = \\text{\\cls~$x_1$~{It was}~\\mask~. \\sep}$\n",
" }\n",
"\\end{equation*}\n",
"and let $\\lm$ decide whether it is more appropriate to fill in ``\\emph{great}'' (positive) or ``\\emph{terrible}'' (negative) for \\mask.\n",
"We now formalize this approach for classification and regression (\\S\\ref{sec:classification} and \\S\\ref{sec:regression}), and discuss the importance of prompt selection (\\S\\ref{sec:manual_prompts}).\n",
"\\subsection{Classification}\n",
"\\label{sec:classification}\n",
"Let $\\mapping \\colon \\labelset \\rightarrow \\vocabulary$ be a mapping from the task label space to individual words\\footnote{More generally, we can consider a one-to-many mapping $\\mapping\\colon \\labelset \\rightarrow 2^{|\\labelset|}$ in which we map labels to sets of words. However, we did not find significant gains in our experiments.}\n",
"in the vocabulary $\\vocabulary$ of $\\lm$.\n",
"Then for each $\\xinput$, let the manipulation ${x}_{\\mathrm{prompt}} = \\template(\\xinput)$\n",
"be a \\emph{masked language modeling} (MLM) input which contains one \\mask~token.\n",
"In this way, we can treat our task as an\n",
"MLM, and model the probability of predicting class $y \\in \\labelset$ as:\n",
"\\vspace{-10pt}\n",
"\\begin{equation}\n",
"\\label{eq:lm-classification}\n",
"\\resizebox{.85\\hsize}{!}{\n",
"$\\begin{aligned}\n",
"p(y \\mid \\xinput) &= p\\left(\\mask = \\mapping(y) \\mid \\xprompt\\right) \\\\\n",
"&=\\frac{\\exp\\left(\\mf{w}_{\\mapping(y)} \\cdot \\mf{h}_{\\mask}\\right)}{\\sum_{y' \\in \\labelset} {\\exp\\left(\\mf{w}_{\\mapping(y')} \\cdot \\mf{h}_{\\mask}\\right)}},\n",
"\\end{aligned}$\n",
"}\n",
"\\end{equation}\n",
"where $\\mf{h}_{\\mask}$ is the hidden vector of {\\mask} \n",
"and $\\mf{w}_v$ denotes the pre-softmax vector corresponding to $v \\in \\vocabulary$.\n",
"When supervised examples $\\{(\\xinput, y)\\}$ are available, $\\mathcal{L}$ can be fine-tuned to minimize the cross-entropy loss.\n",
"It is important to note that this approach re-uses the pre-trained weights $\\mf{w}_v$ and does not introduce any new parameters. It also reduces the gap between pre-training and fine-tuning, making it more effective in few-shot scenarios.\n",
"\\subsection{Regression}\n",
"\\label{sec:regression}\n",
"We assume the same basic setup as in classification, but treat the label space $\\labelset$ as a bounded interval $[v_l, v_u]$.\n",
"Inspired by ~\\citet{mettes2019hyperspherical},\n",
"we model the problem as an interpolation between two opposing poles, $\\{y_l, y_u\\}$, with values $v_l$ and $v_u$ respectively.\n",
"For instance, we can formulate our previous sentiment analysis task as a regression problem in the range $[0, 1]$, where we slide between ``\\emph{terrible}'' ($v_l = 0$) and ``\\emph{great}'' ($v_u = 1$). In this way, we can express $y$ as a \\emph{mixture model}:\n",
"\\begin{equation}\n",
" y = v_l \\cdot p(y_l \\mid \\xinput) + v_u \\cdot p(y_u \\mid \\xinput),\n",
"\\end{equation}\n",
"where $p(y_u \\mid \\xinput)$ is the probability of $y_u$, and $p(y_l \\mid \\xinput) = 1 - p(y_u \\mid \\xinput)$.\n",
"Then we define $\\mapping \\colon \\{y_l, y_u\\} \\rightarrow \\vocabulary$,\n",
"and model $p(y_u \\mid \\xinput)$ the same as Eq. (\\ref{eq:lm-classification}).\n",
"\\begin{comment}\n",
"\\begin{equation}\n",
"\\label{eq:lm-regression}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
"p(y_u \\mid \\xinput) = \\frac{\\exp\\left(\\mf{w}_{w_u} \\cdot \\mf{h}_{\\mask}\\right)}{\\sum_{w' \\in \\{w_u, w_l\\}}\\exp\\left(\\mf{w}_{w'} \\cdot \\mf{h}_{\\mask}\\right)}.\n",
"$}\n",
"\\end{equation}\n",
"\\end{comment}\n",
"We fine-tune $\\mathcal{L}$ to minimize the KL-divergence between the inferred $p(y_u \\mid \\xinput)$\n",
"and the observed mixture weight, $(y\n",
"- v_l) / (v_u - v_l)$.\n",
"\\begin{table}[!t]\n",
" \\centering\n",
" \\resizebox{0.95\\columnwidth}{!}{\n",
" \\begin{tabular}{l cc c}\n",
" \\toprule\n",
" \\midrule\n",
" \\multicolumn{2}{l}{SST-2 (positive/negative)} & mean (std)\\\\\n",
" \\midrule\n",
" {\\sent} It was {\\mask} . & great/terrible & \\tf{92.7 (0.9)} \\\\\n",
" {\\sent} It was {\\mask} . & good/bad & 92.5 (1.0) \\\\\n",
" {\\sent} It was {\\mask} . & cat/dog & 91.5 (1.4) \\\\\n",
" {\\sent} It was {\\mask} . & dog/cat & 86.2 (5.4) \\\\\n",
" {\\sent} It was {\\mask} . & terrible/great & 83.2 (6.9) \\\\\n",
" {Fine-tuning} & - & 81.4 (3.8) \\\\\n",
" \\midrule\n",
" \\multicolumn{2}{l}{SNLI (entailment/neutral/contradiction)} & mean (std)\\\\\n",
" \\midrule\n",
" {\\firstsent} ? {\\mask} , {\\secondsent} & Yes/Maybe/No & \\tf{77.2 (3.7)} \\\\\n",
" {\\firstsent} . {\\mask} , {\\secondsent} & Yes/Maybe/No & 76.2 (3.3) \\\\\n",
" {\\firstsent} ? {\\mask} {\\secondsent} & Yes/Maybe/No & 74.9 (3.0) \\\\\n",
" {\\firstsent} {\\secondsent} {\\mask} & Yes/Maybe/No & 65.8 (2.4) \\\\\n",
" {\\secondsent} ? {\\mask} , {\\firstsent} & Yes/Maybe/No & 62.9 (4.1) \\\\\n",
" {\\firstsent} ? {\\mask} , {\\secondsent} & Maybe/No/Yes & 60.6 (4.8) \\\\\n",
" {Fine-tuning} & - & 48.4 (4.8) \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" }\n",
" \\label{tab:prompt_search}\n",
"\\end{table}\n",
"\\subsection{Manual prompts: the good and the bad}\n",
"\\label{sec:manual_prompts}\n",
"The key challenge is to construct the template $\\template$ and label words $\\mapping(\\labelset)$---we refer to these two together as a \\ti{prompt} $\\mathcal{P}$.\n",
"Previous works~\\cite{schick2020exploiting,schick2020size} hand-craft both the templates and label words, which usually requires domain expertise and trial-and-error.\n",
"Table~\\ref{tab:manual_prompts}\n",
"These templates and label words were designed by intuition, and by considering formats used in previous literature. \n",
"the better the final accuracy is\n",
"(\\ti{great}/\\ti{terrible} $>$ \\ti{good}/\\ti{bad} $>$ \\ti{cat}/\\ti{dog}).\n",
"Furthermore, with the same set of label words,\n",
"can make a difference.\n",
"For example, for SNLI, if we put \\mask~at the end, or swap sentence order, we observe a $>$10\\\n",
"Searching for prompts, however, is hard, as the search space can be very large---especially for the template. Even worse, we only have a few examples to use to guide our search, which can easily overfit. We will address these issues next.\n",
"\\section{Automatic Prompt Generation}\n",
"\\label{sec:auto_prompt}\n",
"Here, we assume a classification task, but the process for regression is analogous.\n",
"\\subsection{Automatic selection of label words}\n",
"\\label{sec:label_search}\n",
"Naively searching all possible assignments, however, is (1) generally intractable, as the search space is exponential in the number of classes; and (2) prone to overfitting, as we will tend to uncover spurious correlations given only a few annotations. As a simple solution,\n",
"for each class $c \\in \\labelset$, we construct a pruned set $\\mathcal{V}^c \\subset \\mathcal{V}$ of the top $k$ vocabulary words based on their conditional likelihood using the initial $\\lm$. That is, let $\\dtrain^c \\subset \\dtrain$ be the subset of all examples of class $c$. We take $\\mathcal{V}^c$ as\n",
"\\begin{equation}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
" \\underset{v \\in \\mathcal{V}}{\\mathrm{Top}\\text{-}k} \\left\\{\\sum_{\\xinput \\in \\dtrain^c} \\hspace{-5pt}\\log P_{\\lm}\\Big(\\mask = v \\mid \\template(\\xinput)\\Big)\\right\\},\n",
"$}\n",
"\\end{equation}\n",
"where ${P}_{\\lm}$ denotes the output probability distribution of $\\lm$.\n",
"To further narrow down the search space, we find the top $n$ assignments over the pruned space that maximize zero-shot accuracy on $\\dtrain$ (both $n$ and $k$ are hyper-parameters, see\n",
"Appendix~\\ref{app:prompts}).\n",
"This approach is similar to the automatic verbalizer search methods in \\newcite{schick2020exploiting,schick2020automatically}, except that we use a much simpler search process (brute-force) and also apply re-ranking---which we find to be quite helpful.\n",
"\\subsection{Automatic generation of templates}\n",
"\\label{sec:template_search}\n",
"Next, we study how to generate a diverse set of templates $\\{\\template\\}$ automatically from a fixed set of label words $\\mapping(\\labelset)$.\n",
"To address this challenging problem, we propose to use T5~\\cite{raffel2020exploring}, a large pre-trained text-to-text Transformer.\n",
"T5 is pre-trained to fill in missing spans (replaced by T5 mask tokens, e.g., \\maskx~or \\masky) in its input.\n",
"For example, given the input ``\\ti{Thank you {\\maskx} me to your party {\\masky} week}'', T5 is trained to generate ``\\ti{{\\maskx} for inviting {\\masky} last {\\maskz}}'',\n",
"meaning that ``\\ti{for inviting}'' is the replacement for {\\maskx} and ``\\ti{last}'' is the replacement for {\\masky}.\n",
"This is well suited for prompt generation: we can simply take input sentences from $\\dtrain$ and let the T5 model construct the template $\\template$, without having to specify a pre-defined number of tokens for it.\n",
"Given an input example $(\\xinput, y) \\in \\dtrain$, \n",
"we consider the following simple conversions, denoted as $\\template_{\\gen}(\\xinput, y)$, for formulating the T5 model inputs:\\footnote{We consider putting the label word both before and after the input sentence for single-sentence tasks. However, we find that it is always better to put the label words in the middle (between the two sentences) for sentence-pair tasks.}\n",
"\\begin{equation*}\n",
"\\resizebox{.85\\hsize}{!}{\n",
"$\\begin{aligned}\n",
"\\lsent &\\longrightarrow~\\maskx~\\lwordmap(y)~\\masky~\\lsent, \\\\\n",
"\\lsent &\\longrightarrow~\\lsent~\\maskx~\\lwordmap(y)~\\masky,\\\\\n",
"\\lfirstsent,\\lsecondsent &\\longrightarrow \\lfirstsent~\\maskx~\\lwordmap(y)~\\masky~\\lsecondsent.\n",
"\\end{aligned}$\n",
"}\n",
"\\end{equation*}\n",
"As shown in Figure~\\ref{fig:template_search}, we rely on the T5 model to fill in the placeholders. \n",
"When decoding, our goal here is to find an output that can work well for \\emph{all} examples in $\\dtrain$,\n",
"i.e.,\n",
"where $P_{\\text{T5}}$ denotes the output probability distribution of T5.\n",
"It can be decomposed according to:\n",
"\\vspace{-0.5em}\n",
"\\begin{equation}\n",
"\\resizebox{.87\\hsize}{!}{$\\displaystyle\n",
" \\sum_{j = 1}^{|\\template|}\\hspace{-10pt}\\sum_{~~~~~(\\xinput, y) \\in \\dtrain} {\\hspace{-14pt}\\log{P_{\\text{T5}}\\big(t_j \\mid t_1,...,t_{j-1}, \\template_{\\gen}\\big(\\xinput,y\\big)\\big)}},\n",
"$}\n",
"\\end{equation}\n",
"where $(t_1, \\ldots, t_{|\\template|})$ are the template tokens.\n",
"\\begin{figure}[t]\n",
" \\centering\n",
" \\includegraphics[width=0.48\\textwidth]{figures/template_search.pdf}\n",
" \\caption{Our approach for template generation.\n",
" }\n",
" \\label{fig:template_search}\n",
" \\vspace{-5pt}\n",
"\\end{figure}\n",
"\\section{Fine-tuning with Demonstrations}\n",
"\\label{sec:demonstrations}\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.0\\textwidth}{!}{\n",
"\\begin{tabular}{lcccccccc}\n",
"\\toprule\n",
"& \\tf{SST-2} & \\tf{SST-5} & \\tf{MR} & \\tf{CR} & \\tf{MPQA} & \\tf{Subj} & \\tf{TREC} & \\tf{CoLA} \\\\\n",
"& (acc) & (acc) & (acc) & (acc) & (acc) & (acc) & (acc) & (Matt.)\\\\\n",
"\\midrule\n",
"Majority$^\\dagger$ & \\ti{50.9} & \\ti{23.1} & \\ti{50.0} & \\ti{50.0} & \\ti{50.0} & \\ti{50.0} & \\ti{18.8} & \\ti{0.0} \\\\\n",
"Prompt-based zero-shot$^\\ddagger$ & 83.6 &\t35.0 &\t80.8 &\t79.5 &\t67.6 &\t51.4 &\t32.0 &\t2.0 \\\\\n",
"``GPT-3'' in-context learning &84.8 (1.3) &\t30.6 (0.9) &\t80.5 (1.7) &\t87.4 (0.8) &\t63.8 (2.1) &\t53.6 (1.0) &\t26.2 (2.4) &\t-1.5 (2.4) \\\\\n",
"Fine-tuning & 81.4 (3.8) &\t43.9 (2.0) &\t76.9 (5.9) &\t75.8 (3.2) &\t72.0 (3.8) &\t90.8 (1.8) &\t{88.8} (2.1) &\t\\tf{33.9} (14.3) \\\\\n",
"\\midrule\n",
"Prompt-based FT (man) & 92.7 (0.9) &\t47.4 (2.5) &\t87.0 (1.2) &\t90.3 (1.0) &\t84.7 (2.2) &\t91.2 (1.1) &\t84.8 (5.1) &\t9.3 (7.3) \\\\\n",
"\\tableindent + demonstrations & 92.6 (0.5) &\t\\tf{50.6} (1.4) &\t86.6 (2.2) &\t90.2 (1.2) &\t\\tf{87.0} (1.1) &\t\\tf{92.3} (0.8) &\t87.5 (3.2) &\t18.7 (8.8) \t\\\\\n",
"Prompt-based FT (auto) & 92.3 (1.0) &\t49.2 (1.6) &\t85.5 (2.8) &\t89.0 (1.4) &\t85.8 (1.9) &\t91.2 (1.1) &\t88.2 (2.0) &\t14.0 (14.1) \\\\\n",
"\\tableindent + demonstrations & \\tf{93.0} (0.6) &\t49.5 (1.7) &\t\\tf{87.7} (1.4) &\t\\tf{91.0} (0.9) &\t86.5 (2.6) &\t91.4 (1.8) &\t\\tf{89.4} (1.7) &\t21.8 (15.9)\\\\\n",
"\\midrule\n",
"Fine-tuning (full)$^\\dagger$ & \\ti{95.0} & \\ti{58.7} & \\ti{90.8} & \\ti{89.4} & \\ti{87.8} & \\ti{97.0} & \\ti{97.4} & \\ti{62.6} \\\\\n",
"\\midrule\n",
" & \\tf{MNLI} & \\tf{MNLI-mm} & \\tf{SNLI} & \\tf{QNLI} & \\tf{RTE} & \\tf{MRPC} & \\tf{QQP} & \\tf{STS-B} \\\\\n",
" & (acc) & (acc) & (acc) & (acc) & (acc) & (F1) & (F1) & (Pear.)\\\\\n",
"\\midrule\n",
"Majority$^\\dagger$ & \\ti{32.7} & \\ti{33.0} & \\ti{33.8} & \\ti{49.5} & \\ti{52.7} & \\ti{81.2} & \\ti{0.0} & \\ti{-} \\\\\n",
"Prompt-based zero-shot$^\\ddagger$ &\t50.8 &\t51.7 &\t49.5 &\t50.8 &\t51.3 & 61.9 &\t49.7 &\t-3.2 \\\\\n",
"``GPT-3'' in-context learning & 52.0 (0.7) &\t53.4 (0.6) &\t47.1 (0.6) &\t53.8 (0.4) &\t60.4 (1.4) &\t45.7 (6.0) &\t36.1 (5.2) &\t14.3 (2.8) \\\\\n",
"Fine-tuning &\t45.8 (6.4) &\t47.8 (6.8) &\t48.4 (4.8) &\t60.2 (6.5) &\t54.4 (3.9) & {76.6} (2.5) &\t60.7 (4.3) &\t53.5 (8.5) \\\\\n",
"\\midrule\n",
"Prompt-based FT (man) &\t68.3 (2.3) &\t70.5 (1.9) &\t77.2 (3.7) &\t64.5 (4.2) &\t69.1 (3.6) & 74.5 (5.3) &\t65.5 (5.3) &\t71.0 (7.0) \\\\\n",
"\\tableindent + demonstrations &\t\\tf{70.7} (1.3) &\t\\tf{72.0} (1.2) &\t\\tf{79.7} (1.5) &\t\\tf{69.2} (1.9) &\t68.7 (2.3) & 77.8 (2.0) &\t\\tf{69.8} (1.8) &\t73.5 (5.1) \t\\\\\n",
"Prompt-based FT (auto) &\t68.3 (2.5) &\t70.1 (2.6) &\t77.1 (2.1) &\t68.3 (7.4) &\t\\tf{73.9} (2.2) & 76.2 (2.3) &\t67.0 (3.0) &\t75.0 (3.3) \\\\\n",
"\\tableindent + demonstrations & 70.0 (3.6) &\t\\tf{72.0} (3.1) &\t77.5 (3.5) &\t68.5 (5.4) &\t{71.1} (5.3) &\t\\tf{78.1} (3.4) &\t67.7 (5.8) &\t\\tf{76.4} (6.2) \\\\\n",
"\\midrule\n",
"Fine-tuning (full)$^\\dagger$ & \\ti{89.8} &\t\\ti{89.5} & \\ti{92.6}\t &\t\\ti{93.3} &\t\\ti{80.9} &\t\\ti{91.4} &\t\\ti{81.7} & \\ti{91.9} \\\\\n",
"\\bottomrule\n",
"\\end{tabular}}\n",
"\\end{center}\n",
"\\caption{\n",
"Our main results using RoBERTa-large.\n",
"$\\dagger$: full training set is used (see dataset sizes in\n",
"Table~\\ref{tab:datasets});\n",
"$\\ddagger$: no training examples are used; otherwise we use\n",
"$K = 16$ (per class)\n",
"for few-shot experiments.\n",
"We report mean (and standard deviation) performance over 5 different splits (\\S \\ref{sec:setup}).\n",
"{Majority:} majority class;\n",
"{FT:} fine-tuning;\n",
"{man:} manual prompt\n",
"(Table~\\ref{tab:manual_prompts});\n",
"{auto:} automatically searched templates (\\S\\ref{sec:template_search});\n",
"{``GPT-3'' in-context learning:} using the in-context learning proposed in \\newcite{brown2020language} with RoBERTa-large (no parameter updates).\n",
"}\n",
"\\label{tab:main_results}\n",
"\\end{table*}\n",
"In this section, we study whether we can leverage demonstrations when \\ti{fine-tuning} medium-sized LMs, and find better ways to exploit them.\n",
"\\subsection{Training examples as demonstrations}\n",
"GPT-3's naive approach to in-context learning simply involves concatenating the input with up to 32 examples randomly drawn from the training set.\n",
"This approach is suboptimal as\n",
"(1) the number of available demonstrations is bounded by the model's maximum input length;\\footnote{GPT-3 uses a context size of 2,048 while most smaller language models (e.g., RoBERTa) have a context size of 512.}\n",
"and (2) mixing numerous random examples from different classes together creates extremely long contexts which can be hard to leverage, especially for a smaller model.\n",
"To address these issues,\n",
"we propose a simpler solution:\n",
"at each training step,\n",
"convert it into $\\template\\big(\\xinput^{(c)}\\big)$ with {\\mask} replaced by $\\mapping(y_{\\phantom{t}}^{(c)})$---we denote this as $\\tilde{\\template}\\big(\\xinput^{(c)}, y_{\\phantom{t}}^{(c)}\\big)$---and then concatenate them with $\\xinput$ (Figure~\\ref{fig:overview}(c)):\n",
"\\begin{equation*}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
" \\template\\big(\\xinput\\big) \\oplus \\tilde{\\template}\\big(\\xinput^{(1)}, y_{\\phantom{t}}^{(1)}\\big) \\oplus \\cdots \\oplus \\tilde{\\template}\\big(\\xinput^{(|\\labelset|)}, y_{\\phantom{t}}^{(|\\labelset|)}\\big).\n",
"$}\n",
"\\end{equation*}\n",
"Here $\\oplus$ denotes concatenation of input sequences.\n",
"We observe that controlling the construction of the demonstration examples $\\{(\\xinput^{(c)}, y_{\\phantom{t}}^{(c)})\\}$ is crucial for good final performance.\n",
"For example, if the set of contrastive demonstrations $\\xinput^{(c)}$ are all dramatically different---from each other, or from the query $\\xinput$---then it becomes challenging for the language model to decipher meaningful patterns. As a result, the model may simply ignore the context, or even get confused by the additional examples.\n",
"Specifically, we use a pre-trained SBERT~\\cite{reimers2019sentence} model to obtain embeddings for all input sentences (for sentence-pair tasks, we use the concatenation of the two sentences).\n",
"Here we just feed the raw sentences without the templates into SBERT.\n"
],
"output": {
"What experiments do you suggest doing?": [
"1. Task performance with a single prompt: Authors should compare the performance in different tasks using a single prompt from the proposed approach with that of other approaches.",
"2. Analyzing the efficacy of template and label word generation: The authors can compare the performance of template and label word optimization separately and together to measure the effectiveness of different parts of the approach.",
"3. Task performance with Ensemble prompts: Authors should conduct an experiment to compare performance with ensembles of generated prompts.",
"4. Impact of Sampling Policy: The authors should conduct an experiment to analyze the impact of different sampling techniques on the performance of demonstrations in context.",
"5. Analyzing Sample Efficiency: The authors should conduct a comparative analysis of LM-BFF in different sample availability settings."
],
"Why do you suggest these experiments?": [
"1. Single prompt task performance highlights the quality of the best prompt attained from an automatically searched prompt, which is crucial to assess the quality of the proposed approach.",
"2. Separately generating templates and label words and finally comparing the performance in combining them should give a better view of whether the template or the label word generation is more important in this space.",
"3. With automated prompt search, it is possible to generate several prompts as required. Therefore, using different prompts and individually trained models, then using an ensemble of those models can offer much better results. Therefore, it is important to see whether ensemble results with the proposed approach can outperform that of previous approaches.",
"4. This experiment would provide further insights into the effectiveness of selective sampling in incorporating demonstrations in context, thereby justifying the choice of sampling strategy.",
"5. This experiment can provide further insight into whether the proposed approach does better compared to previous approaches in different data-constrained settings, where the proposed approach is more important."
]
},
"paper_info": {
"title": "Making Pre-trained Language Models Better Few-shot Learners",
"authors": [
"Tianyu Gao",
"Adam Fisch",
"Danqi Chen"
],
"abstract": "The recent GPT-3 model (Brown et al., 2020) achieves remarkable few-shot\nperformance solely by leveraging a natural-language prompt and a few task\ndemonstrations as input context. Inspired by their findings, we study few-shot\nlearning in a more practical scenario, where we use smaller language models for\nwhich fine-tuning is computationally efficient. We present LM-BFF--better\nfew-shot fine-tuning of language models--a suite of simple and complementary\ntechniques for fine-tuning language models on a small number of annotated\nexamples. Our approach includes (1) prompt-based fine-tuning together with a\nnovel pipeline for automating prompt generation; and (2) a refined strategy for\ndynamically and selectively incorporating demonstrations into each context.\nFinally, we present a systematic evaluation for analyzing few-shot performance\non a range of NLP tasks, including classification and regression. Our\nexperiments demonstrate that our methods combine to dramatically outperform\nstandard fine-tuning procedures in this low resource setting, achieving up to\n30% absolute improvement, and 11% on average across all tasks. Our approach\nmakes minimal assumptions on task resources and domain expertise, and hence\nconstitutes a strong task-agnostic method for few-shot learning.",
"comments": "Accepted to ACL 2021. The code is publicly available at\n https://github.com/princeton-nlp/LM-BFF"
},
"raw_data": {
"context_before_exp": [
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\documentclass[11pt,a4paper]{article}\n",
"\\usepackage[hyperref]{acl2021}\n",
"\\usepackage{times}\n",
"\\usepackage{latexsym}\n",
"\\renewcommand{\\UrlFont}{\\ttfamily\\small}\n",
"\n",
"\n",
"\n",
"\n",
"\\usepackage{microtype}\n",
"\\usepackage{array}\n",
"\\usepackage{pifont}\n",
"\\usepackage{tabularx}\n",
"\\usepackage{adjustbox}\n",
"\\usepackage{multirow}\n",
"\\usepackage{enumitem}\n",
"\\usepackage{xspace}\n",
"\\usepackage{tcolorbox}\n",
"\\usepackage{booktabs,subcaption,amsfonts,dcolumn}\n",
"\\usepackage{hyperref}\n",
"\\usepackage{url}\n",
"\\usepackage{amsmath,amsthm,amsfonts,amssymb,bm,stmaryrd}\n",
"\\usepackage{xcolor}\t\t\n",
"\\usepackage[noorphans,vskip=0.75ex,leftmargin=2ex]{quoting}\n",
"\n",
"\\aclfinalcopy \n",
"\\def\\aclpaperid{982} \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\definecolor{darkblue}{rgb}{0, 0, 0.5}\n",
"\\hypersetup{colorlinks=true, citecolor=darkblue, linkcolor=darkblue, urlcolor=darkblue}\n",
"\n",
"\\usepackage[compact]{titlesec}\n",
"\\titlespacing{\\section}{0pt}{2ex}{1ex}\n",
"\\titlespacing{\\subsection}{0pt}{1ex}{1ex}\n",
"\n",
"\\setlength{\\parskip}{0cm}\n",
"\\setlength{\\parindent}{1em}\n",
"\n",
"\n",
"\\providecommand{\\todo}[1]{\n",
" {\\protect\\color{red}{[TODO: #1]}}\n",
"}\n",
"\n",
"\\providecommand{\\danqi}[1]{\n",
" {\\protect\\color{purple}{[Danqi: #1]}}\n",
"}\n",
"\n",
"\\providecommand{\\tianyu}[1]{\n",
" {\\protect\\color{blue}{[Tianyu: #1]}}\n",
"}\n",
"\n",
"\\providecommand{\\adam}[1]{\n",
" {\\protect\\color{teal}{[Adam: #1]}}\n",
"}\n",
"\n",
"\n",
"\\newcommand{\\cmark}{\\ding{51}}\n",
"\\newcommand{\\xmark}{\\ding{55}}\n",
"\\newcommand\\sys[1]{\\textsc{#1}}\n",
"\\newcommand\\ti[1]{\\textit{#1}}\n",
"\\newcommand\\ts[1]{\\textsc{#1}}\n",
"\\newcommand\\tf[1]{\\textbf{#1}}\n",
"\\newcommand\\ttt[1]{\\texttt{#1}}\n",
"\\newcommand\\mf[1]{\\mathbf{#1}}\n",
"\\newcommand\\tmp[1]{\\color{gray}{#1}}\n",
"\\newcommand\\warn[1]{\\textbf{\\color{red}{#1}}}\n",
"\n",
"\n",
"\\providecommand{\\todon}{\n",
" {\\protect\\color{red}{00.0 (0.0)}}\n",
"}\n",
"\n",
"\\newcommand{\\ours}{LM-BFF\\xspace}\n",
"\\newcommand{\\dtrain}{\\mathcal{D}_{\\text{train}}}\n",
"\\newcommand{\\ddev}{\\mathcal{D}_{\\text{dev}}}\n",
"\\newcommand{\\dtest}{\\mathcal{D}_{\\text{test}}}\n",
"\\newcommand{\\seedset}{\\mathcal{S}_{\\text{seed}}}\n",
"\\newcommand{\\maskx}{\\texttt{<X>}}\n",
"\\newcommand{\\masky}{\\texttt{<Y>}}\n",
"\\newcommand{\\maskz}{\\texttt{<Z>}}\n",
"\\newcommand{\\lsent}{\\texttt{<}S_1\\ttt{>}}\n",
"\\newcommand{\\lfirstsent}{\\texttt{<}S_1\\ttt{>}}\n",
"\\newcommand{\\lsecondsent}{\\texttt{<}S_2\\ttt{>}}\n",
"\\newcommand{\\sent}{\\ttt{<}$S_1$\\ttt{>}}\n",
"\\newcommand{\\firstsent}{\\ttt{<}$S_1$\\ttt{>}}\n",
"\\newcommand{\\secondsent}{\\ttt{<}$S_2$\\ttt{>}}\n",
"\\newcommand{\\xinput}{{x}_{\\mathrm{in}}}\n",
"\\newcommand{\\xprompt}{x_{\\mathrm{prompt}}}\n",
"\\newcommand{\\gen}{\\mathrm{g}}\n",
"\n",
"\n",
"\\newcommand{\\template}{\\mathcal{T}}\n",
"\\newcommand{\\lwordset}{\\mathcal{W}}\n",
"\\newcommand{\\lwordmap}{\\mathcal{M}}\n",
"\\newcommand{\\vocabulary}{\\mathcal{V}}\n",
"\\newcommand{\\labelset}{\\mathcal{Y}}\n",
"\\newcommand{\\mapping}{\\mathcal{M}}\n",
"\\newcommand{\\totalk}{K_{\\text{tot}}}\n",
"\\newcommand{\\lm}{\\mathcal{L}}\n",
"\\newcommand{\\cls}{\\texttt{[CLS]}}\n",
"\\newcommand{\\sep}{\\texttt{[SEP]}}\n",
"\\newcommand{\\mask}{\\texttt{[MASK]}}\n",
"\\DeclareMathOperator*{\\argmax}{arg\\,max}\n",
"\\DeclareMathOperator*{\\argmin}{arg\\,min}\n",
"\\renewcommand{\\paragraph}[1]{\\vspace{0.2cm}\\noindent\\textbf{#1}}\n",
"\\newcommand{\\tpf}[1]{\\noindent\\textbf{#1}}\n",
"\n",
"\\newcommand{\\tableindent}{~~}\n",
"\n",
"\\newcommand\\BibTeX{B\\textsc{ib}\\TeX}\n",
"\n",
"\\title{Making Pre-trained Language Models Better Few-shot Learners}\n",
"\n",
"\\author{Tianyu Gao$^{\\dagger*}$ \\quad Adam Fisch$^{\\ddagger*}$ \\quad Danqi Chen$^{\\dagger}$ \\\\\n",
"$^{\\dagger}$Princeton University\\quad $^{\\ddagger}$Massachusetts Institute of Technology\\\\\n",
"\\ttt{\\{tianyug,danqic\\}@cs.princeton.edu}\\\\\n",
"\\ttt{[email protected]}\n",
"}\n",
"\n",
"\\date{}\n",
"\n",
"\n",
"\\begin{document}\n",
"\\maketitle\n",
"\\renewcommand{\\thefootnote}{\\fnsymbol{footnote}}\n",
"\\footnotetext[1]{The first two authors contributed equally.}\n",
"\\renewcommand{\\thefootnote}{\\arabic{footnote}}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{abstract}\n",
"The recent GPT-3 model~\\cite{brown2020language} achieves remarkable few-shot performance solely by leveraging a natural-language prompt and a few task demonstrations as input context.\n",
"Inspired by their findings, we study few-shot learning in a more practical scenario, where we use smaller language models for which fine-tuning is computationally efficient.\n",
"We present {\\ours}---\\underline{b}etter \\underline{f}ew-shot \\underline{f}ine-tuning of \\underline{l}anguage \\underline{m}odels\\footnote{Alternatively, {l}anguage {m}odels' \\underline{b}est \\underline{f}riends \\underline{f}orever.}---a suite of simple and complementary techniques for fine-tuning language models on a small number of annotated examples. Our approach includes (1) prompt-based fine-tuning together with a novel pipeline for automating prompt generation; and (2) a refined strategy for dynamically and selectively incorporating demonstrations into each context.\n",
"Finally, we present a systematic evaluation for analyzing few-shot performance on a range of NLP tasks, including classification and regression. Our experiments demonstrate that our methods combine to dramatically outperform standard fine-tuning procedures in this low resource setting, achieving up to 30\\\n",
"\n",
"\\end{abstract}\n",
"\n",
"\n",
"\n",
"\\section{Introduction}\n",
"\n",
"\n",
"\\begin{figure*}[t]\n",
" \\centering\n",
" \\includegraphics[width=0.95\\textwidth]{figures/in_context3.pdf}\n",
" \\caption{An illustration of (a) masked language model (MLM) pre-training, (b) standard fine-tuning, and (c) our proposed {\\ours} using prompt-based fine-tuning with demonstrations. The underlined text is the task-specific \\emph{template}, and colored words are \\emph{label words}.}\n",
" \n",
" \\label{fig:overview}\n",
"\\end{figure*}\n",
"\n",
"\\label{sec:intro}\n",
"\n",
"The GPT-3 model \\cite{brown2020language} has made waves in the NLP community by demonstrating astounding few-shot capabilities on myriad language understanding tasks.\n",
"Given only a \\ti{natural language prompt} and a few \\emph{demonstrations} of the task, GPT-3 is able to make accurate predictions without updating any of the weights of its underlying language model.\n",
"However, while remarkable, GPT-3 consists of 175B parameters, which makes it challenging to use in most real-wold applications.\n",
"\n",
"In this work, we study a more practical scenario in which we only assume access to a moderately-sized language model such as BERT~\\cite{devlin2019bert} or RoBERTa~\\cite{liu2019roberta}, and a small number of examples (i.e., a \\emph{few-shot} setting), which we can use to fine-tune the weights of\n",
"the language model.\n",
"This setting is appealing as\n",
"(1) such models can be trained on typical research hardware;\n",
"(2) few-shot settings are realistic, as it is generally both easy to acquire a few annotations (e.g., 32 examples) and efficient to train on them; and\n",
"(3) updating parameters typically leads to better performance.\n",
"Inspired by GPT-3's findings, we propose several novel strategies for expanding its few-shot learning abilities to our setting, considering both classification and---for the first time---regression.\n",
"\n",
"\n",
"\n",
"First, we follow the route of \\ti{prompt-based} prediction, first developed by the GPT series~\\cite{radford2018improving,radford2019language,brown2020language} for zero-shot prediction and recently studied by PET~\\cite{schick2020exploiting, schick2020size} for fine-tuning.\n",
"Prompt-based prediction treats the downstream task as a (masked) language modeling problem, where the model directly generates a textual response (referred to as a \\emph{label word}) to a given prompt defined by a task-specific \\emph{template} (see Figure~\\ref{fig:overview}(c)).\n",
"\n",
"Finding the right prompts, however, is an art---requiring both domain expertise and an understanding of the language model's inner workings.\n",
"Even if significant effort is invested, manual prompts are likely to be suboptimal.\n",
"We address this issue by introducing automatic prompt generation, including a pruned brute-force search to identify the best working label words, and a novel decoding objective to automatically generate templates using the generative T5 model~\\cite{raffel2020exploring}---all of which only require the few-shot training data. This allows us to cheaply obtain effective prompts that match or outperform our manually chosen ones.\n",
"\n",
"\n",
"\n",
"\n",
"Second, we adopt the idea of incorporating demonstrations \n",
"as\n",
"additional context.\n",
"GPT-3's naive ``in-context learning'' paradigm picks up to 32 randomly sampled examples, and concatenates them with the input. This method is not guaranteed to prioritize the most informative demonstrations, and mixing random examples from different classes together creates long contexts which can be hard to learn from. Additionally, the number of usable demonstrations is bounded by the model's maximum input length.\n",
"We develop a more refined strategy, where, for each input, we randomly sample a \\emph{single} example at a time from \\emph{each} class to create multiple, minimal demonstration \\emph{sets}.\n",
"We also devise a novel sampling strategy that pairs inputs with similar examples, thereby providing the model with more discriminative comparisons.\n",
"\n",
"\n",
"We present a systematic evaluation for analyzing few-shot performance on 8 single-sentence and 7 sentence-pair NLP tasks. We observe that given a small number of training examples, (1) prompt-based fine-tuning largely outperforms standard fine-tuning; (2) our automatic prompt search method matches or outperforms manual prompts; and (3) incorporating demonstrations is effective for fine-tuning, and boosts few-shot performance.\n",
"Together, these simple-yet-effective methods contribute towards a dramatic improvement across the tasks we evaluate on,\n",
"and we obtain gains up to 30\\\n",
"For instance, we find that a RoBERTa-large model achieves around 90\\\n",
"\n",
"\n",
"\n",
"\\section{Related Work}\n",
"\\label{sec:related_work}\n",
"\n",
"\n",
"\\tpf{Language model prompting.} The GPT series~\\citep{radford2018improving,radford2019language,brown2020language} fueled the development of prompt-based learning,\n",
"and we follow many of its core concepts.\n",
"We are also greatly inspired by the recent PET work~\\citep{schick2020exploiting,schick2020size}, although they mainly focus on a semi-supervised setting where a large set of unlabeled examples are provided.\n",
"We only use a few annotated examples as supervision, and also explore automatically generated prompts and fine-tuning with demonstrations.\n",
"Furthermore, we deviate from their evaluation by providing a more rigorous framework, as we will discuss in \\S\\ref{sec:setup}.\n",
"Finally, there is a large body of work on prompting for mining knowledge from pre-trained models \\cite[][\\emph{inter alia}]{trinh2018simple,petroni2019language,davison2019commonsense,talmor2020olmpics}. Different from these works, we focus on leveraging prompting for fine-tuning on downstream tasks.\n",
"\n",
"\n",
"\n",
"\\paragraph{Automatic prompt search.}\n",
"\\citet{schick2020exploiting} and \\citet{schick2020automatically} explore ways of identifying label words automatically,\n",
"however, none of these results lead to better performance compared to hand-picked ones.\n",
"In contrast, our method searches over both templates and label words, and is able to match or outperform our manual prompts.\n",
"Several other attempts have been made in addition---yet these approaches either operate in limited domains,\n",
"such as finding patterns to express specific relations~\\cite{jiang2020can},\n",
"or require a large number of examples for gradient-guided search~\\cite{shin2020autoprompt,zhong2021factual}. Our approach aims to develop general-purpose search methods that rely only on a few annotations.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\paragraph{Fine-tuning of language models.} A number of recent studies have focused on better methods for fine-tuning language models~\\cite{howard2018universal,dodge2020fine,lee2020mixout, zhang2020revisiting}. These works mainly focus on optimization and regularization techniques to stabilize fine-tuning. Here we use standard optimization techniques, and instead mainly focus our efforts on better prompt-based fine-tuning in a more extreme few-shot setting. We anticipate that results of these studies are largely complementary to ours.\n",
"\n",
"\n",
"\n",
"\\paragraph{Few-shot learning.} Broadly speaking, our setting is also connected to other few-shot learning paradigms in NLP, including\n",
"(1) {semi-supervised learning}~\\cite{miyato2017adversarial,xie2020unsupervised,chen2020mixtext}, where a set of unlabeled examples are given;\n",
"(2) {meta-learning}~\\cite{yu2018diverse,han2018fewrel,bansal2020learning,bansal2020self, bao2020fewshot}, where a set of auxiliary tasks are given; and\n",
"(3) {intermediate training}~\\cite{phang2018sentence,yin2020universal}, where a related, intermediate task is given. We deviate from these settings by making minimal assumptions about available resources: we only assume a few annotated examples and a pre-trained language model. Our focus is on understanding how far we can push without any other advantages.\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{llcrrrcl}\n",
"\\toprule\n",
"\\tf{Category} & \\tf{Dataset} & $|\\mathcal{Y}|$ & $L$ & \\#Train & \\#Test & \\tf{Type} & \\tf{Labels (classification tasks)} \\\\\n",
"\\bottomrule\n",
" & SST-2 & 2 & 19 & 6,920 & 872 & sentiment & positive, negative \\\\\n",
"& SST-5 & 5 & 18 & 8,544 & 2,210 & sentiment & v. pos., positive, neutral, negative, v. neg. \\\\\n",
"& MR & 2 & 20 & 8,662& 2,000 & sentiment & positive, negative \\\\\n",
"single- & CR & 2 & 19 & 1,775 & 2,000 & sentiment & positive, negative \\\\\n",
"sentence & MPQA & 2 & 3 & 8,606 & 2,000 & opinion polarity & positive, negative \\\\\n",
"& Subj & 2 & 23 & 8,000 & 2,000 & subjectivity & subjective, objective \\\\\n",
"& TREC & 6 & 10 & 5,452 & 500 & question cls. & abbr., entity, description, human, loc., num.\\\\\n",
"& CoLA & 2 & 8 & 8,551 & 1,042 & acceptability & grammatical, not\\_grammatical\\\\\n",
"\\midrule\n",
" & MNLI & 3 & 22/11 & 392,702 & 9,815 & NLI & entailment, neutral, contradiction\\\\\n",
"& SNLI & 3 & 14/8 & 549,367 & 9,842 & NLI & entailment, neutral, contradiction \\\\\n",
"sentence- & QNLI & 2 & 11/30 & 104,743 & 5,463 & NLI & entailment, not\\_entailment \\\\\n",
"pair & RTE & 2 & 49/10 & 2,490 & 277 & NLI & entailment, not\\_entailment \\\\\n",
" & MRPC & 2 & 22/21 & 3,668 & 408 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& QQP & 2 & 12/12 & 363,846 & 40,431 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& STS-B & $\\mathcal{R}$ & 11/11 & 5,749 & 1,500 & sent. similarity & - \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{The datasets evaluated in this work. $|\\mathcal{Y}|$: \\# of classes for classification tasks (with one exception: STS-B is a real-valued regression task over the interval $[0, 5]$). $L$: average \\# of words in input sentence(s). Note that we only sample $\\dtrain$ and $\\ddev$ of $K \\times |\\labelset|$ examples from the original training set in our few-shot experiments (\\S\\ref{sec:setup}).}\n",
"\\label{tab:datasets}\n",
"\\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{lll}\n",
"\\toprule\n",
"\\tf{Task} & \\tf{Template} & \\tf{Label words}\\\\\n",
"\\midrule\n",
"SST-2 & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"SST-5 & {\\sent} It was {\\mask} . & v.positive: great, positive: good, neutral: okay, negative: bad, v.negative: terrible\\\\\n",
"MR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"CR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"Subj & {\\sent} This is {\\mask} . & subjective: subjective, objective: objective \\\\\n",
"TREC & {\\mask} : {\\sent} & abbreviation: Expression, entity: Entity, description: Description \\\\\n",
"&& human: Human, location: Location, numeric: Number \\\\\n",
"COLA & {\\sent} This is {\\mask} . & grammatical: correct, not\\_grammatical: incorrect \\\\\n",
"\\midrule\n",
"MNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No \\\\\n",
"SNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No\\\\\n",
"QNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"RTE & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"MRPC & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"QQP & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"STS-B & {\\firstsent} {\\mask} , {\\secondsent} & $y_u$: Yes, $y_l$: No \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{Manual templates and label words that we used in our experiments. \n",
"STS-B is a regression task (\\S\\ref{sec:regression}).\n",
"}\n",
"\\label{tab:manual_prompts}\n",
"\\vspace{-5pt}\n",
"\\end{table*}\n",
"\n",
"\n",
"\n",
"\\section{Problem Setup}\n",
"\\label{sec:setup}\n",
"\n",
"\\paragraph{Task formulation.}\n",
"\n",
"In this work, we assume access to a pre-trained language model $\\lm$ that we wish to fine-tune on a task $\\mathcal{D}$ with a label space $\\labelset$. For the task, we only assume $K$ training examples \\emph{per class}\\footnote{For regression, we partition the data into two ``classes'' according to being above or below the median value.} for the task's training set $\\dtrain$, such that the total number of examples is $\\totalk = K \\times |\\labelset|$, and $\\dtrain = \\{(\\xinput^i, y^i)\\}_{i=1}^{\\totalk}$.\n",
"Our goal is then to develop task-agnostic learning strategies that generalize well to an unseen test set $(\\xinput^{\\text{test}}, y^{\\text{test}})\\sim \\dtest$. \n",
"For model selection and hyper-parameter tuning, we assume a development set $\\ddev$, of the same size as the few-shot training set, i.e., $|\\ddev| = |\\dtrain|$. This distinction is important: using a larger development set confers a significant advantage\n",
"(see our experiments in Appendix~\\ref{app:dev_size}),\n",
"and subverts our initial goal of learning from limited data.\\footnote{In contrast, \\newcite{schick2020exploiting,schick2020size} do not use a development set, and adopt a set of hyper-parameters based on practical considerations.\n",
"This is akin to ``shooting in the dark'' on a setting that we show can have unintuitive outcomes.}\n",
"For all of the following experiments (unless specified otherwise), we take $\\lm=$ RoBERTa-large and $K=16$.\n",
"\n",
"\n",
"\\paragraph{Evaluation datasets.}\n",
"\n",
"We conduct a systematic study across $8$ single-sentence and $7$ sentence-pair English tasks, \n",
"\n",
"including\n",
"8 tasks from the GLUE benchmark~\\cite{wang2019glue},\n",
"\n",
"SNLI~\\cite{bowman2015large_snli}, and 6 other popular sentence classification tasks (SST-5, MR, CR, MPQA, Subj, TREC). All of the dataset details are provided in Appendix~\\ref{app:datasets}. For \\emph{single-sentence} tasks, the goal is to make a prediction based on an input sentence $\\xinput = x_1$, such as whether a movie review is positive or not. For \\emph{sentence-pair} tasks, the goal is to take a pair of input sentences $\\xinput = (x_1, x_2)$ and predict the relationship between them. We also interchangeably refer to the inputs as {\\firstsent} or (\\firstsent, \\secondsent).\n",
"\n",
"\n",
"Note that we mainly use SST-2 and SNLI for pilot experiments and model development, making it close to a true few-shot setting, at least for all the other datasets we evaluate on.\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{comment}\n",
"\\vspace{-3pt}\n",
"\\begin{enumerate}[leftmargin=*]\n",
" \\item \\emph{Single-sentence tasks.} The goal is to make a prediction based on an input sentence $\\xinput = x_1$ (sometimes referred as \\firstsent), such as whether a movie review is positive or not.\n",
" Our tasks range from sentiment analysis to question classification and grammaticality assessment.\n",
" \n",
" \\vspace{-3pt}\n",
" \\item \\emph{Sentence-pair tasks.} The goal is to make a prediction based on a pair of input sentences $\\xinput = (x_1, x_2)$ (sometimes referred as \\firstsent, \\secondsent), such as predicting the relationship between them.\n",
" Our tasks include natural language inference and paraphrase detection.\n",
" \n",
"\\end{enumerate}\n",
"\\vspace{-3pt}\n",
"\\end{comment}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\paragraph{Evaluation protocol.}\n",
"Systematically evaluating few-shot performance can be tricky.\n",
"It is well-known that\n",
"fine-tuning on small datasets can suffer from instability~\\cite{dodge2020fine,zhang2020revisiting}, and results may change dramatically given a new split of data.\n",
"\n",
"To account for this, we measure average performance across 5 different randomly sampled $\\dtrain$ and $\\ddev$ splits.\n",
"\n",
"This issue has also been discussed in\n",
"\\newcite{schick2020size}---they suggest using a fixed set of training examples. We argue that sampling\n",
"\n",
"multiple splits gives a\n",
"more robust measure of performance,\n",
"and a better estimate of the variance.\n",
"We also observe that hyper-parameters\n",
"\n",
"can make a significant difference,\n",
"\n",
"\n",
"thus we sweep multiple hyper-parameters for each data sample, and take the best setting as measured on the $\\ddev$ of that sample (see Appendix~\\ref{app:hyper_selection}).\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{lll}\n",
"\\toprule\n",
"\\tf{Task} & \\tf{Template} & \\tf{Label words}\\\\\n",
"\\midrule\n",
"SST-2 & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"SST-5 & {\\sent} It was {\\mask} . & v.positive: great, positive: good, neutral: okay, negative: bad, v.negative: terrible\\\\\n",
"MR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"CR & {\\sent} It was {\\mask} . & positive: great, negative: terrible\\\\\n",
"Subj & {\\sent} This is {\\mask} . & subjective: subjective, objective: objective \\\\\n",
"TREC & {\\mask} : {\\sent} & abbreviation: Expression, entity: Entity, description: Description \\\\\n",
"&& human: Human, location: Location, numeric: Number \\\\\n",
"COLA & {\\sent} This is {\\mask} . & grammatical: correct, not\\_grammatical: incorrect \\\\\n",
"\\midrule\n",
"MNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No \\\\\n",
"SNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, netural: Maybe, contradiction: No\\\\\n",
"QNLI & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"RTE & {\\firstsent} ? {\\mask} , {\\secondsent} & entailment: Yes, not\\_entailment: No \\\\\n",
"MRPC & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"QQP & {\\firstsent} {\\mask} , {\\secondsent} & equivalent: Yes, not\\_equivalent: No\\\\\n",
"STS-B & {\\firstsent} {\\mask} , {\\secondsent} & $y_u$: Yes, $y_l$: No \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{Manual templates and label words that we used in our experiments. \n",
"STS-B is a regression task (\\S\\ref{sec:regression}).\n",
"}\n",
"\\label{tab:manual_prompts}\n",
"\\vspace{-5pt}\n",
"\\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Prompt-based Fine-tuning}\n",
"\\label{sec:prompt_finetuning}\n",
"\n",
"Given a masked language model\n",
"$\\lm$,\n",
"we first convert input $\\xinput$ to a token sequence $\\tilde{x}$, and the language model $\\lm$ then\n",
"\n",
"maps $\\tilde{x}$ to a sequence of hidden vectors $\\{\\mf{h}_k \\in \\mathbb{R}^d\\}$.\n",
"During standard fine-tuning, we usually take $\\tilde{x}_{\\text{single}} = \\cls x_1 \\sep$ or $\\tilde{x}_{\\text{pair}} = \\cls x_1 \\sep x_2 \\sep$.\n",
"\n",
"For downstream classification tasks with a label space $\\labelset$, we train a task-specific head, $\\mathrm{softmax}(\\mf{W}_o \\mf{h}_{\\cls})$, by maximizing the log-probability of the correct label, where $\\mf{h}_{\\cls}$ is the hidden vector of \\cls, and $\\mf{W}_o \\in \\mathbb{R}^{\\mathcal{|\\labelset|} \\times d}$ is a set of randomly initialized parameters introduced at the start of fine-tuning.\n",
"\n",
"Similarly, for a regression task, we can introduce $\\mf{w}_o \\in \\mathbb{R}^d$ and optimize the mean squared error between $\\mf{w}_o \\cdot \\mf{h}_{\\cls}$ and the gold label.\n",
"In either case, the number of new parameters can be substantial---for example, a simple binary classification task will introduce 2,048 new parameters for a RoBERTa-large model---making it challenging to learn from a small amount of annotated data (e.g., 32 examples).\n",
"\n",
"\n",
"\n",
"An alternative approach to solving this problem is \\ti{prompt-based fine-tuning}, in which $\\lm$ is directly tasked with ``auto-completing'' natural language prompts. \n",
"For instance, we can formulate a binary sentiment classification task using a prompt with\n",
"\n",
"input $x_1$\n",
"(e.g., ``\\ti{No reason to watch it .}'') as:\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{equation*}\n",
" \\resizebox{.85\\hsize}{!}{\n",
" $\\xprompt = \\text{\\cls~$x_1$~{It was}~\\mask~. \\sep}$\n",
" }\n",
"\\end{equation*}\n",
"and let $\\lm$ decide whether it is more appropriate to fill in ``\\emph{great}'' (positive) or ``\\emph{terrible}'' (negative) for \\mask.\n",
"We now formalize this approach for classification and regression (\\S\\ref{sec:classification} and \\S\\ref{sec:regression}), and discuss the importance of prompt selection (\\S\\ref{sec:manual_prompts}).\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Classification}\n",
"\\label{sec:classification}\n",
"\n",
"Let $\\mapping \\colon \\labelset \\rightarrow \\vocabulary$ be a mapping from the task label space to individual words\\footnote{More generally, we can consider a one-to-many mapping $\\mapping\\colon \\labelset \\rightarrow 2^{|\\labelset|}$ in which we map labels to sets of words. However, we did not find significant gains in our experiments.}\n",
"\n",
"in the vocabulary $\\vocabulary$ of $\\lm$.\n",
"Then for each $\\xinput$, let the manipulation ${x}_{\\mathrm{prompt}} = \\template(\\xinput)$\n",
"\n",
"be a \\emph{masked language modeling} (MLM) input which contains one \\mask~token.\n",
"\n",
"In this way, we can treat our task as an\n",
"\n",
"MLM, and model the probability of predicting class $y \\in \\labelset$ as:\n",
"\\vspace{-10pt}\n",
"\\begin{equation}\n",
"\\label{eq:lm-classification}\n",
"\\resizebox{.85\\hsize}{!}{\n",
"$\\begin{aligned}\n",
"p(y \\mid \\xinput) &= p\\left(\\mask = \\mapping(y) \\mid \\xprompt\\right) \\\\\n",
"&=\\frac{\\exp\\left(\\mf{w}_{\\mapping(y)} \\cdot \\mf{h}_{\\mask}\\right)}{\\sum_{y' \\in \\labelset} {\\exp\\left(\\mf{w}_{\\mapping(y')} \\cdot \\mf{h}_{\\mask}\\right)}},\n",
"\\end{aligned}$\n",
"}\n",
"\n",
"\n",
"\n",
"\\end{equation}\n",
"where $\\mf{h}_{\\mask}$ is the hidden vector of {\\mask} \n",
"\n",
"and $\\mf{w}_v$ denotes the pre-softmax vector corresponding to $v \\in \\vocabulary$.\n",
"When supervised examples $\\{(\\xinput, y)\\}$ are available, $\\mathcal{L}$ can be fine-tuned to minimize the cross-entropy loss.\n",
"It is important to note that this approach re-uses the pre-trained weights $\\mf{w}_v$ and does not introduce any new parameters. It also reduces the gap between pre-training and fine-tuning, making it more effective in few-shot scenarios.\n",
"\n",
"\n",
"\n",
"\\subsection{Regression}\n",
"\\label{sec:regression}\n",
"We assume the same basic setup as in classification, but treat the label space $\\labelset$ as a bounded interval $[v_l, v_u]$.\n",
"\n",
"\n",
"Inspired by ~\\citet{mettes2019hyperspherical},\n",
"we model the problem as an interpolation between two opposing poles, $\\{y_l, y_u\\}$, with values $v_l$ and $v_u$ respectively.\n",
"For instance, we can formulate our previous sentiment analysis task as a regression problem in the range $[0, 1]$, where we slide between ``\\emph{terrible}'' ($v_l = 0$) and ``\\emph{great}'' ($v_u = 1$). In this way, we can express $y$ as a \\emph{mixture model}:\n",
"\\begin{equation}\n",
" y = v_l \\cdot p(y_l \\mid \\xinput) + v_u \\cdot p(y_u \\mid \\xinput),\n",
"\\end{equation}\n",
"where $p(y_u \\mid \\xinput)$ is the probability of $y_u$, and $p(y_l \\mid \\xinput) = 1 - p(y_u \\mid \\xinput)$.\n",
"\n",
"Then we define $\\mapping \\colon \\{y_l, y_u\\} \\rightarrow \\vocabulary$,\n",
"and model $p(y_u \\mid \\xinput)$ the same as Eq. (\\ref{eq:lm-classification}).\n",
"\\begin{comment}\n",
"\\begin{equation}\n",
"\\label{eq:lm-regression}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
"p(y_u \\mid \\xinput) = \\frac{\\exp\\left(\\mf{w}_{w_u} \\cdot \\mf{h}_{\\mask}\\right)}{\\sum_{w' \\in \\{w_u, w_l\\}}\\exp\\left(\\mf{w}_{w'} \\cdot \\mf{h}_{\\mask}\\right)}.\n",
"$}\n",
"\\end{equation}\n",
"\\end{comment}\n",
"\n",
"We fine-tune $\\mathcal{L}$ to minimize the KL-divergence between the inferred $p(y_u \\mid \\xinput)$\n",
"\n",
"and the observed mixture weight, $(y\n",
"- v_l) / (v_u - v_l)$.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[!t]\n",
" \\centering\n",
" \\resizebox{0.95\\columnwidth}{!}{\n",
" \\begin{tabular}{l cc c}\n",
" \\toprule\n",
" \\tf{Template} & \\tf{Label words} & \\tf{Accuracy} \\\\\n",
" \\midrule\n",
" \\multicolumn{2}{l}{SST-2 (positive/negative)} & mean (std)\\\\\n",
" \\midrule\n",
" {\\sent} It was {\\mask} . & great/terrible & \\tf{92.7 (0.9)} \\\\\n",
" {\\sent} It was {\\mask} . & good/bad & 92.5 (1.0) \\\\\n",
" {\\sent} It was {\\mask} . & cat/dog & 91.5 (1.4) \\\\\n",
" {\\sent} It was {\\mask} . & dog/cat & 86.2 (5.4) \\\\\n",
" {\\sent} It was {\\mask} . & terrible/great & 83.2 (6.9) \\\\\n",
" {Fine-tuning} & - & 81.4 (3.8) \\\\\n",
" \\midrule\n",
" \\multicolumn{2}{l}{SNLI (entailment/neutral/contradiction)} & mean (std)\\\\\n",
" \\midrule\n",
" {\\firstsent} ? {\\mask} , {\\secondsent} & Yes/Maybe/No & \\tf{77.2 (3.7)} \\\\\n",
" {\\firstsent} . {\\mask} , {\\secondsent} & Yes/Maybe/No & 76.2 (3.3) \\\\\n",
" {\\firstsent} ? {\\mask} {\\secondsent} & Yes/Maybe/No & 74.9 (3.0) \\\\\n",
" {\\firstsent} {\\secondsent} {\\mask} & Yes/Maybe/No & 65.8 (2.4) \\\\\n",
" {\\secondsent} ? {\\mask} , {\\firstsent} & Yes/Maybe/No & 62.9 (4.1) \\\\\n",
" {\\firstsent} ? {\\mask} , {\\secondsent} & Maybe/No/Yes & 60.6 (4.8) \\\\\n",
" {Fine-tuning} & - & 48.4 (4.8) \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\caption{The impact of templates and label words on prompt-based fine-tuning ($K=16$).\n",
" }\n",
" \\label{tab:prompt_search}\n",
"\\end{table}\n",
"\n",
"\\subsection{Manual prompts: the good and the bad}\n",
"\\label{sec:manual_prompts}\n",
"\n",
"\n",
"The key challenge is to construct the template $\\template$ and label words $\\mapping(\\labelset)$---we refer to these two together as a \\ti{prompt} $\\mathcal{P}$.\n",
"\n",
"Previous works~\\cite{schick2020exploiting,schick2020size} hand-craft both the templates and label words, which usually requires domain expertise and trial-and-error.\n",
"Table~\\ref{tab:manual_prompts}\n",
"summarizes manual templates and label words chosen for each dataset in our experiments.\n",
"These templates and label words were designed by intuition, and by considering formats used in previous literature. \n",
"\n",
"\n",
"\n",
"To better understand what constitutes a good template or label word, we conduct a pilot study on SST-2 and SNLI.\n",
"\n",
"Table~\\ref{tab:prompt_search} shows that different prompts can lead to substantial differences in final accuracy.\n",
"\n",
"Specifically, when a template is fixed, the better the label words match the ``semantic classes'',\n",
"the better the final accuracy is\n",
"(\\ti{great}/\\ti{terrible} $>$ \\ti{good}/\\ti{bad} $>$ \\ti{cat}/\\ti{dog}).\n",
"In extreme cases where we swap plausible label words (e.g., \\ti{terrible}/\\ti{great}), we achieve the worst overall performance.\\footnote{It is unclear, however, why RoBERTa thinks that ``cat'' is more positive than ``dog''. The authors tend to disagree.}\n",
"\n",
"Furthermore, with the same set of label words,\n",
"even a small change in the template\n",
"\n",
"can make a difference.\n",
"For example, for SNLI, if we put \\mask~at the end, or swap sentence order, we observe a $>$10\\\n",
"The above evidence clearly underlines the importance of selecting good templates and label words.\n",
"Searching for prompts, however, is hard, as the search space can be very large---especially for the template. Even worse, we only have a few examples to use to guide our search, which can easily overfit. We will address these issues next.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Automatic Prompt Generation}\n",
"\\label{sec:auto_prompt}\n",
"\n",
"We now explore principled ways of automating the search process for label words (\\S\\ref{sec:label_search}) and templates (\\S\\ref{sec:template_search}). Our goals are to reduce the human involvement required to design prompts, and to find more optimal settings than those that we manually choose.\n",
"Here, we assume a classification task, but the process for regression is analogous.\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Automatic selection of label words}\n",
"\\label{sec:label_search}\n",
"We first study how to construct a label word mapping $\\mapping$ that maximizes accuracy on $\\ddev$ after fine-tuning, given a fixed template $\\template$.\n",
"Naively searching all possible assignments, however, is (1) generally intractable, as the search space is exponential in the number of classes; and (2) prone to overfitting, as we will tend to uncover spurious correlations given only a few annotations. As a simple solution,\n",
"for each class $c \\in \\labelset$, we construct a pruned set $\\mathcal{V}^c \\subset \\mathcal{V}$ of the top $k$ vocabulary words based on their conditional likelihood using the initial $\\lm$. That is, let $\\dtrain^c \\subset \\dtrain$ be the subset of all examples of class $c$. We take $\\mathcal{V}^c$ as\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{equation}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
" \\underset{v \\in \\mathcal{V}}{\\mathrm{Top}\\text{-}k} \\left\\{\\sum_{\\xinput \\in \\dtrain^c} \\hspace{-5pt}\\log P_{\\lm}\\Big(\\mask = v \\mid \\template(\\xinput)\\Big)\\right\\},\n",
"$}\n",
"\\end{equation}\n",
"where ${P}_{\\lm}$ denotes the output probability distribution of $\\lm$.\n",
"To further narrow down the search space, we find the top $n$ assignments over the pruned space that maximize zero-shot accuracy on $\\dtrain$ (both $n$ and $k$ are hyper-parameters, see\n",
"Appendix~\\ref{app:prompts}).\n",
"Then we fine-tune all top $n$ assignments, and re-rank to find the best one using $\\ddev$.\n",
"This approach is similar to the automatic verbalizer search methods in \\newcite{schick2020exploiting,schick2020automatically}, except that we use a much simpler search process (brute-force) and also apply re-ranking---which we find to be quite helpful.\n",
"\n",
"\n",
"\\subsection{Automatic generation of templates}\n",
"\\label{sec:template_search}\n",
"\n",
"Next, we study how to generate a diverse set of templates $\\{\\template\\}$ automatically from a fixed set of label words $\\mapping(\\labelset)$.\n",
"To address this challenging problem, we propose to use T5~\\cite{raffel2020exploring}, a large pre-trained text-to-text Transformer.\n",
"T5 is pre-trained to fill in missing spans (replaced by T5 mask tokens, e.g., \\maskx~or \\masky) in its input.\n",
"For example, given the input ``\\ti{Thank you {\\maskx} me to your party {\\masky} week}'', T5 is trained to generate ``\\ti{{\\maskx} for inviting {\\masky} last {\\maskz}}'',\n",
"meaning that ``\\ti{for inviting}'' is the replacement for {\\maskx} and ``\\ti{last}'' is the replacement for {\\masky}.\n",
"This is well suited for prompt generation: we can simply take input sentences from $\\dtrain$ and let the T5 model construct the template $\\template$, without having to specify a pre-defined number of tokens for it.\n",
"\n",
"\n",
"\n",
"Given an input example $(\\xinput, y) \\in \\dtrain$, \n",
"we consider the following simple conversions, denoted as $\\template_{\\gen}(\\xinput, y)$, for formulating the T5 model inputs:\\footnote{We consider putting the label word both before and after the input sentence for single-sentence tasks. However, we find that it is always better to put the label words in the middle (between the two sentences) for sentence-pair tasks.}\n",
"\n",
"\\begin{equation*}\n",
"\\resizebox{.85\\hsize}{!}{\n",
"$\\begin{aligned}\n",
"\\lsent &\\longrightarrow~\\maskx~\\lwordmap(y)~\\masky~\\lsent, \\\\\n",
"\\lsent &\\longrightarrow~\\lsent~\\maskx~\\lwordmap(y)~\\masky,\\\\\n",
"\\lfirstsent,\\lsecondsent &\\longrightarrow \\lfirstsent~\\maskx~\\lwordmap(y)~\\masky~\\lsecondsent.\n",
"\\end{aligned}$\n",
"}\n",
"\n",
"\n",
"\n",
"\\end{equation*}\n",
"\n",
"\n",
"As shown in Figure~\\ref{fig:template_search}, we rely on the T5 model to fill in the placeholders. \n",
"\n",
"When decoding, our goal here is to find an output that can work well for \\emph{all} examples in $\\dtrain$,\n",
"i.e.,\n",
"\n",
"the output template $\\template$ that maximizes $\\sum_{(\\xinput, y) \\in \\dtrain}{\\log P_{\\text{T5}}(\\template \\mid \\template_{\\gen}(\\xinput, y))}$,\n",
"where $P_{\\text{T5}}$ denotes the output probability distribution of T5.\n",
"It can be decomposed according to:\n",
"\\vspace{-0.5em}\n",
"\\begin{equation}\n",
"\\resizebox{.87\\hsize}{!}{$\\displaystyle\n",
" \\sum_{j = 1}^{|\\template|}\\hspace{-10pt}\\sum_{~~~~~(\\xinput, y) \\in \\dtrain} {\\hspace{-14pt}\\log{P_{\\text{T5}}\\big(t_j \\mid t_1,...,t_{j-1}, \\template_{\\gen}\\big(\\xinput,y\\big)\\big)}},\n",
"$}\n",
"\\end{equation}\n",
"where $(t_1, \\ldots, t_{|\\template|})$ are the template tokens.\n",
"\n",
"\\begin{figure}[t]\n",
" \\centering\n",
" \\includegraphics[width=0.48\\textwidth]{figures/template_search.pdf}\n",
" \\caption{Our approach for template generation.\n",
" }\n",
" \\label{fig:template_search}\n",
" \\vspace{-5pt}\n",
" \n",
"\\end{figure}\n",
"\n",
"\n",
"\n",
"\n",
"We use beam search to decode multiple template candidates. Concretely, we use a wide beam width (e.g., 100) to cheaply obtain a large set of diverse templates. We then fine-tune each generated template on $\\dtrain$ and use $\\ddev$ to either pick the single template with the best performance (Table~\\ref{tab:main_results}), or the top $k$ templates to use as an ensemble (Table~\\ref{tab:ensemble}). Though it might appear to be expensive to fine-tune the model on each individual template, this is fast in practice due to the small size of $\\dtrain$, and is also fully automated: making it easy to use, compared to manually tuning prompts for each dataset.\n",
"\n",
"\n",
"\\section{Fine-tuning with Demonstrations}\n",
"\\label{sec:demonstrations}\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.0\\textwidth}{!}{\n",
"\\begin{tabular}{lcccccccc}\n",
"\\toprule\n",
"& \\tf{SST-2} & \\tf{SST-5} & \\tf{MR} & \\tf{CR} & \\tf{MPQA} & \\tf{Subj} & \\tf{TREC} & \\tf{CoLA} \\\\\n",
"& (acc) & (acc) & (acc) & (acc) & (acc) & (acc) & (acc) & (Matt.)\\\\\n",
"\\midrule\n",
"\n",
"Majority$^\\dagger$ & \\ti{50.9} & \\ti{23.1} & \\ti{50.0} & \\ti{50.0} & \\ti{50.0} & \\ti{50.0} & \\ti{18.8} & \\ti{0.0} \\\\\n",
"Prompt-based zero-shot$^\\ddagger$ & 83.6 &\t35.0 &\t80.8 &\t79.5 &\t67.6 &\t51.4 &\t32.0 &\t2.0 \\\\\n",
"\n",
"``GPT-3'' in-context learning &84.8 (1.3) &\t30.6 (0.9) &\t80.5 (1.7) &\t87.4 (0.8) &\t63.8 (2.1) &\t53.6 (1.0) &\t26.2 (2.4) &\t-1.5 (2.4) \\\\\n",
"Fine-tuning & 81.4 (3.8) &\t43.9 (2.0) &\t76.9 (5.9) &\t75.8 (3.2) &\t72.0 (3.8) &\t90.8 (1.8) &\t{88.8} (2.1) &\t\\tf{33.9} (14.3) \\\\\n",
"\n",
"\\midrule\n",
"Prompt-based FT (man) & 92.7 (0.9) &\t47.4 (2.5) &\t87.0 (1.2) &\t90.3 (1.0) &\t84.7 (2.2) &\t91.2 (1.1) &\t84.8 (5.1) &\t9.3 (7.3) \\\\\n",
"\\tableindent + demonstrations & 92.6 (0.5) &\t\\tf{50.6} (1.4) &\t86.6 (2.2) &\t90.2 (1.2) &\t\\tf{87.0} (1.1) &\t\\tf{92.3} (0.8) &\t87.5 (3.2) &\t18.7 (8.8) \t\\\\\n",
"Prompt-based FT (auto) & 92.3 (1.0) &\t49.2 (1.6) &\t85.5 (2.8) &\t89.0 (1.4) &\t85.8 (1.9) &\t91.2 (1.1) &\t88.2 (2.0) &\t14.0 (14.1) \\\\\n",
"\\tableindent + demonstrations & \\tf{93.0} (0.6) &\t49.5 (1.7) &\t\\tf{87.7} (1.4) &\t\\tf{91.0} (0.9) &\t86.5 (2.6) &\t91.4 (1.8) &\t\\tf{89.4} (1.7) &\t21.8 (15.9)\\\\\n",
"\\midrule\n",
"Fine-tuning (full)$^\\dagger$ & \\ti{95.0} & \\ti{58.7} & \\ti{90.8} & \\ti{89.4} & \\ti{87.8} & \\ti{97.0} & \\ti{97.4} & \\ti{62.6} \\\\\n",
"\n",
"\\midrule\n",
" & \\tf{MNLI} & \\tf{MNLI-mm} & \\tf{SNLI} & \\tf{QNLI} & \\tf{RTE} & \\tf{MRPC} & \\tf{QQP} & \\tf{STS-B} \\\\\n",
" & (acc) & (acc) & (acc) & (acc) & (acc) & (F1) & (F1) & (Pear.)\\\\\n",
"\\midrule\n",
"\n",
"Majority$^\\dagger$ & \\ti{32.7} & \\ti{33.0} & \\ti{33.8} & \\ti{49.5} & \\ti{52.7} & \\ti{81.2} & \\ti{0.0} & \\ti{-} \\\\\n",
"Prompt-based zero-shot$^\\ddagger$ &\t50.8 &\t51.7 &\t49.5 &\t50.8 &\t51.3 & 61.9 &\t49.7 &\t-3.2 \\\\\n",
"\n",
"``GPT-3'' in-context learning & 52.0 (0.7) &\t53.4 (0.6) &\t47.1 (0.6) &\t53.8 (0.4) &\t60.4 (1.4) &\t45.7 (6.0) &\t36.1 (5.2) &\t14.3 (2.8) \\\\\n",
"Fine-tuning &\t45.8 (6.4) &\t47.8 (6.8) &\t48.4 (4.8) &\t60.2 (6.5) &\t54.4 (3.9) & {76.6} (2.5) &\t60.7 (4.3) &\t53.5 (8.5) \\\\\n",
"\n",
"\\midrule\n",
"Prompt-based FT (man) &\t68.3 (2.3) &\t70.5 (1.9) &\t77.2 (3.7) &\t64.5 (4.2) &\t69.1 (3.6) & 74.5 (5.3) &\t65.5 (5.3) &\t71.0 (7.0) \\\\\n",
"\\tableindent + demonstrations &\t\\tf{70.7} (1.3) &\t\\tf{72.0} (1.2) &\t\\tf{79.7} (1.5) &\t\\tf{69.2} (1.9) &\t68.7 (2.3) & 77.8 (2.0) &\t\\tf{69.8} (1.8) &\t73.5 (5.1) \t\\\\\n",
"Prompt-based FT (auto) &\t68.3 (2.5) &\t70.1 (2.6) &\t77.1 (2.1) &\t68.3 (7.4) &\t\\tf{73.9} (2.2) & 76.2 (2.3) &\t67.0 (3.0) &\t75.0 (3.3) \\\\\n",
"\\tableindent + demonstrations & 70.0 (3.6) &\t\\tf{72.0} (3.1) &\t77.5 (3.5) &\t68.5 (5.4) &\t{71.1} (5.3) &\t\\tf{78.1} (3.4) &\t67.7 (5.8) &\t\\tf{76.4} (6.2) \\\\\n",
"\\midrule\n",
"Fine-tuning (full)$^\\dagger$ & \\ti{89.8} &\t\\ti{89.5} & \\ti{92.6}\t &\t\\ti{93.3} &\t\\ti{80.9} &\t\\ti{91.4} &\t\\ti{81.7} & \\ti{91.9} \\\\\n",
"\n",
"\\bottomrule\n",
"\\end{tabular}}\n",
"\\end{center}\n",
"\n",
"\\caption{\n",
"Our main results using RoBERTa-large.\n",
"$\\dagger$: full training set is used (see dataset sizes in\n",
"Table~\\ref{tab:datasets});\n",
"$\\ddagger$: no training examples are used; otherwise we use\n",
"\n",
"$K = 16$ (per class)\n",
"for few-shot experiments.\n",
"\n",
"We report mean (and standard deviation) performance over 5 different splits (\\S \\ref{sec:setup}).\n",
"{Majority:} majority class;\n",
"{FT:} fine-tuning;\n",
"{man:} manual prompt\n",
"(Table~\\ref{tab:manual_prompts});\n",
"{auto:} automatically searched templates (\\S\\ref{sec:template_search});\n",
"{``GPT-3'' in-context learning:} using the in-context learning proposed in \\newcite{brown2020language} with RoBERTa-large (no parameter updates).\n",
"}\n",
"\\label{tab:main_results}\n",
"\\end{table*}\n",
"\n",
"In this section, we study whether we can leverage demonstrations when \\ti{fine-tuning} medium-sized LMs, and find better ways to exploit them.\n",
"\n",
"\\subsection{Training examples as demonstrations}\n",
"GPT-3's naive approach to in-context learning simply involves concatenating the input with up to 32 examples randomly drawn from the training set.\n",
"This approach is suboptimal as\n",
"(1) the number of available demonstrations is bounded by the model's maximum input length;\\footnote{GPT-3 uses a context size of 2,048 while most smaller language models (e.g., RoBERTa) have a context size of 512.}\n",
"\n",
"and (2) mixing numerous random examples from different classes together creates extremely long contexts which can be hard to leverage, especially for a smaller model.\n",
"To address these issues,\n",
"we propose a simpler solution:\n",
"at each training step,\n",
"we randomly sample \\ti{one}\\footnote{We also explored sampling multiple examples per class, but did not observe any improvements.} example $\\big(\\xinput^{(c)}, y_{\\phantom{t}}^{(c)}\\big)\\in \\dtrain$ from each class,\n",
"convert it into $\\template\\big(\\xinput^{(c)}\\big)$ with {\\mask} replaced by $\\mapping(y_{\\phantom{t}}^{(c)})$---we denote this as $\\tilde{\\template}\\big(\\xinput^{(c)}, y_{\\phantom{t}}^{(c)}\\big)$---and then concatenate them with $\\xinput$ (Figure~\\ref{fig:overview}(c)):\n",
"\n",
"\\begin{equation*}\n",
"\\resizebox{.89\\hsize}{!}{$\\displaystyle\n",
" \\template\\big(\\xinput\\big) \\oplus \\tilde{\\template}\\big(\\xinput^{(1)}, y_{\\phantom{t}}^{(1)}\\big) \\oplus \\cdots \\oplus \\tilde{\\template}\\big(\\xinput^{(|\\labelset|)}, y_{\\phantom{t}}^{(|\\labelset|)}\\big).\n",
"$}\n",
"\n",
"\\end{equation*}\n",
"Here $\\oplus$ denotes concatenation of input sequences.\n",
"During both training and inference we sample multiple demonstration sets for each $\\xinput$. Note that both $\\xinput$ and demonstration examples are sampled from the same set $\\dtrain$ during training. At testing time, we still sample demonstration sets from $\\dtrain$ and ensemble predictions across all sets.\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Sampling similar demonstrations}\n",
"\\label{sec:demonstration_sampling}\n",
"We observe that controlling the construction of the demonstration examples $\\{(\\xinput^{(c)}, y_{\\phantom{t}}^{(c)})\\}$ is crucial for good final performance.\n",
"For example, if the set of contrastive demonstrations $\\xinput^{(c)}$ are all dramatically different---from each other, or from the query $\\xinput$---then it becomes challenging for the language model to decipher meaningful patterns. As a result, the model may simply ignore the context, or even get confused by the additional examples.\n",
"To address this issue, we devise a simple strategy in which we only sample examples that are semantically close to $\\xinput$.\n",
"Specifically, we use a pre-trained SBERT~\\cite{reimers2019sentence} model to obtain embeddings for all input sentences (for sentence-pair tasks, we use the concatenation of the two sentences).\n",
"Here we just feed the raw sentences without the templates into SBERT.\n",
"For each query $\\xinput$ and each label $c\\in \\labelset$, we sort all training instances with the label $x \\in \\dtrain^{c}$ by their similarity score to the query $\\cos(\\mf{e}(\\xinput), \\mf{e}(x))$, and only sample from the top $r = 50\\\n",
"\n",
"\n",
"\n",
"\n"
],
"context_after_exp": [
"\\section{Experiments}\n",
"\\label{sec:experiments}\n",
"We present our main results, and address several research questions pertaining to our \\ours approach.\n",
"Implementation details are in Appendix~\\ref{app:exp_details}.\n",
"\n",
"\\subsection{Main results}\n",
"\\label{sec:mainresult}\n",
"We use a RoBERTa-large model and set $K = 16$ in our experiments.\n",
"A comparison of using RoBERTa vs BERT can be found in\n",
"Appendix~\\ref{app:analysis_bert}.\n",
"For automatic prompt search, in our main table we report automatic template search only (which consistently performs the best, see Table~\\ref{tab:auto_search}). To put our results in perspective, we compare to a number of baselines, namely\n",
"(1) standard fine-tuning in our few-shot setting;\n",
"(2) standard fine-tuning using the full training set;\n",
"(3) simply taking the most frequent class (measured on the full training set);\n",
"(4) prompt-based zero-shot prediction where we take our manual prompts and use $\\lm$ ``out-of-the-box'' without using any training examples; and\n",
"(5) ``GPT-3'' in-context learning, where we use the same prompt-based zero-shot setting, but augment the context with randomly sampled 32 demonstrations\n",
"(and still use RoBERTa-large, not GPT-3).\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{0.93\\columnwidth}{!}{\n",
" \\begin{tabular}{lcc}\n",
" \\toprule\n",
" {Prompt-based Fine-tuning} & \\tf{MNLI} & \\tf{RTE} \\\\\n",
" \\midrule\n",
" Our single manual $\\mathcal{P}$ & 68.3 (2.3) & 69.1 (3.6) \\\\\n",
" $\\mathcal{P}_{\\text{PET}}$ & 71.9 (1.5) & 69.2 (4.0) \\\\\n",
" $\\mathcal{P}_{\\text{ours}}$, $|\\mathcal{P}_{\\text{ours}}| = |\\mathcal{P}_{\\text{PET}}|$ & 70.4 (3.1) &\t73.0 (3.2)\\\\\n",
" \n",
" \\tableindent + demonstrations & 74.0 (1.9) & 71.9 (4.6)\\\\\n",
" $\\mathcal{P}_{\\text{ours}}$, $|\\mathcal{P}_{\\text{ours}}| = 20$&72.7 (2.5) & \\tf{73.1} (3.3)\\\\\n",
" \\tableindent + demonstrations& \\tf{75.4} (1.6) & 72.3 (4.5)\\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{Ensemble models using manual prompts from PET~\\cite{schick2020exploiting,schick2020size} and our automatic templates. PET uses 4 prompts for MNLI and 5 for RTE. We also use an equal number of templates \n",
" in $|\\mathcal{P}_{\\text{ours}}| = |\\mathcal{P}_{\\text{PET}}|$ \n",
" for a fair comparison.}\n",
" \\vspace{-3pt}\n",
" \\label{tab:ensemble}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{0.90\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Manual & \\tf{92.7} & \\tf{77.2} & 84.8&74.5 \\\\\n",
" \\midrule\n",
" Auto T & 92.3 & 77.1 & {88.2} &76.2 \\\\\n",
" Auto L & 91.5 & 75.6 & 87.0 & \\tf{77.2} \\\\\n",
" Auto T + L & 92.1 & 77.0 & \\tf{89.2} &74.0 \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
"\n",
" \\caption{\n",
" Comparison between manual prompts and different automatic prompt generation methods: auto-generated templates (Auto T), auto-generated label words (Auto L), and their combination (Auto T + L).\n",
" \n",
" \n",
" \n",
" }\n",
"\n",
" \\vspace{-3pt}\n",
" \\label{tab:auto_search}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\paragraph{Single-prompt results.}\n",
"Table~\\ref{tab:main_results} shows our main results using a single prompt, either from our manually designed ones (Table~\\ref{tab:manual_prompts}) , or the best generated ones.\n",
"First, prompt-based zero-shot prediction achieves much better performance than the majority class, showing the pre-encoded knowledge in RoBERTa.\n",
"Also, ``GPT-3'' in-context learning\n",
"does not always improve over zero-shot prediction, likely because smaller language models are not expressive enough to use off-the-shelf like GPT-3. \n",
"\n",
"Second, prompt-based fine-tuning can greatly outperform standard fine-tuning, both when using a manual prompt or a generated one.\n",
"\n",
"CoLA is one interesting exception, as the input may be a non-grammatical sentence which is out of the distribution of $\\lm$. \n",
"Generally, our automatically searched templates can achieve comparable or even higher results than manual ones,\n",
"especially for tasks in which constructing strong manual templates is less intuitive (e.g., TREC, QNLI and MRPC).\n",
"\n",
"\n",
"\n",
"\\begin{table}[!t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{0.92\\columnwidth}{!}{\n",
" \\begin{tabular}{ll}\n",
" \\toprule\n",
" \\tf{SST-2} & (positive/negative) \\\\\n",
" \\midrule\n",
"\n",
" Auto T & $\\mapping(\\labelset)$ = \\{great, terrible\\}\\\\\n",
" & \\#1. {\\sent} A {\\mask} one .\\\\\n",
" & \\#2. {\\sent} A {\\mask} piece .\\\\\n",
" & \\#3. {\\sent} All in all {\\mask} .\\\\\n",
" \\midrule\n",
" Auto L & $\\template(\\xinput)$ = \\sent~It was \\mask . \\\\\n",
" & \\#1. irresistible/pathetic\\\\\n",
" & \\#2. wonderful/bad \\\\\n",
" & \\#3. delicious/bad \\\\\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \\midrule\n",
" \\tf{SNLI} & (entailment/neutral/contradiction) \\\\\n",
" \\midrule\n",
" Auto T & $\\mapping(\\labelset)$ = \\{Yes, Maybe, No\\} \\\\\n",
" & \\#1. {\\firstsent} . {\\mask} , no , {\\secondsent} \\\\\n",
" & \\#2. {\\firstsent} . {\\mask} , in this case {\\secondsent} \\\\\n",
" & \\#3. {\\firstsent} . {\\mask} this time {\\secondsent} \\\\\n",
" \\midrule\n",
" Auto L & $\\template(\\xinput)$ = \\firstsent~? \\mask~, \\secondsent \\\\\n",
" & \\#1. Alright/Watch/Except \\\\\n",
" & \\#2. Hi/Watch/Worse \\\\\n",
" & \\#3. Regardless/Fortunately/Unless \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\vspace{-3pt}\n",
" \\caption{Examples of our automatically generated templates (Auto T) and label words (Auto L).}\n",
" \\vspace{-8pt}\n",
" \\label{tab:generated_template}\n",
" \\end{table}\n",
"\n",
"Finally, using demonstrations in context leads to consistent gains in a majority of tasks.\n",
"\n",
"\n",
" \n",
"\n",
"In summary, our combined solution---fine-tuning with automatically searched templates and sampled demonstration sets---achieves a $30\\\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\paragraph{Ensemble results.} An advantage of automatic prompt search is that we can generate as many prompts as we want, train individual models, and create large ensembles. PET~\\cite{schick2020exploiting,schick2020size} also ensembles multiple models trained with manual prompts.\\footnote{They then use unlabeled data and distillation to get a single model, which is outside of our scope.} In Table~\\ref{tab:ensemble}, we make a direct comparison of our searched prompts and PET's manual prompts on MNLI and RTE (two datasets that we evaluate in common).\\footnote{In the PET NLI templates, the hypothesis is put before the premise, which we actually found to be suboptimal. In our experiments, we swap the two and get better results.}\n",
"As the results show, an ensemble with multiple templates always improves performance.\n",
"An ensemble of the same number of automatic templates achieves comparable or better performance than the ensemble of PET's manual prompts. Increasing the number of automatic templates brings further gains.\n",
"\n",
"\n",
"\\subsection{Analysis of generated prompts}\n",
"Table~\\ref{tab:auto_search} gives the results of using manual vs automatic prompts.\n",
"For automatic prompts, we compare\n",
"\n",
"\n",
"template search (Auto T),\n",
"label word search (Auto L),\n",
"and a joint variant (Auto T + L) in which \n",
"we start from manual label words, apply Auto T, and then Auto L.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"In most cases, Auto T achieves comparable or higher performance than manual ones, and is consistently the best variant. Auto L outperforms manual prompts on TREC and MRPC---but is considerably worse on SNLI. Auto T + L is often better than Auto L, but only sometimes better than Auto T.\n",
"\n",
"\n",
"\n",
"Table~\\ref{tab:generated_template} shows examples from Auto T and Auto L (A full list in Appendix~\\ref{app:generated_prompts}).\n",
"Auto T templates generally fit the context and label words well, but can contain biased peculiarities (e.g., ``\\emph{\\{Yes/No\\}, no}'' in SNLI).\n",
"For Auto L words, things are mixed: while most look intuitively reasonable, there are also some mysterious abnormalities (e.g., ``\\emph{Hi}'' for the ``entailment'' class in SNLI).\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Analysis of demonstration sampling}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" & \\tf{SST-2} & \\tf{SNLI} &\\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Prompt-based FT & \\tf{92.7} & 77.2 & 84.8 & 74.5 \\\\\n",
" \\midrule\n",
" Uniform sampling & 92.3 & 78.8 & 85.6 & 70.9 \\\\\n",
" \\tableindent + RoBERTa sel. & \\tf{92.7} & 79.5 & 83.4 & 76.6 \\\\\n",
" \\tableindent + SBERT sel. & 92.6 & \\tf{79.7} & \\tf{87.5} & \\tf{77.8} \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
"\n",
" \\caption{\n",
" Impact of demonstration sampling strategies.\n",
" Uniform sampling randomly samples demonstrations, while selective (sel.) sampling only takes top sentences measured by the sentence encoders (\\S \\ref{sec:demonstrations}).\n",
" }\n",
" \\vspace{-10pt}\n",
" \\label{tab:pair_ablation}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Table~\\ref{tab:pair_ablation} compares the performance of demonstrations using uniform sampling to selective sampling by SBERT.\n",
"\n",
"We acknowledge that SBERT is trained on SNLI and MNLI datasets, thus we also tried a simple sentence encoder using mean pooling of hidden representations from RoBERTa-large.\n",
"\n",
"\n",
"We find that in either case, using selective sampling outperforms uniform sampling, highlighting the importance of sampling similar examples for incorporating demonstrations in context.\n",
"\n",
"\n",
"\n",
"\\subsection{Sample efficiency}\n",
"\n",
"\n",
"\n",
"Figure~\\ref{fig:sample} illustrates\n",
"how standard fine-tuning and our \\ours compare as $K$ increases.\n",
"For a simple task such as SST-2 (also see MR, CR and MPQA in Table~\\ref{tab:main_results}), despite using only 32 total examples, \\ours has already nearly saturated its performance and is comparable to standard fine-tuning over the entire dataset. On the harder task of SNLI, \\ours continues to improve as $K$ increases while still maintaining a performance gap over standard fine-tuning, until the two converge around $K = 256$.\n",
"\n",
"\n",
"\\section{Analysis}\n",
"\\label{sec:analysis}\n",
"\n",
"\n",
"\\subsection{Generated vs. manual prompts}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\danqi{I am also thinking we need to discuss the imbalanced-class issue for SNLI tasks (zero-shot and after fine-tuning). }\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{0.90\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Manual & \\tf{92.7} & \\tf{77.2} & 84.8&74.5 \\\\\n",
" \\midrule\n",
" Auto T & 92.3 & 77.1 & {88.2} &76.2 \\\\\n",
" Auto L & 91.5 & 75.6 & 87.0 & \\tf{77.2} \\\\\n",
" Auto T + L & 92.1 & 77.0 & \\tf{89.2} &74.0 \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
"\n",
" \\caption{\n",
" Comparison between manual prompts and different automatic prompt generation methods: auto-generated templates (Auto T), auto-generated label words (Auto L), and their combination (Auto T + L).\n",
" \n",
" \n",
" \n",
" }\n",
"\n",
" \\vspace{-3pt}\n",
" \\label{tab:auto_search}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[!t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{0.92\\columnwidth}{!}{\n",
" \\begin{tabular}{ll}\n",
" \\toprule\n",
" \\tf{SST-2} & (positive/negative) \\\\\n",
" \\midrule\n",
"\n",
" Auto T & $\\mapping(\\labelset)$ = \\{great, terrible\\}\\\\\n",
" & \\#1. {\\sent} A {\\mask} one .\\\\\n",
" & \\#2. {\\sent} A {\\mask} piece .\\\\\n",
" & \\#3. {\\sent} All in all {\\mask} .\\\\\n",
" \\midrule\n",
" Auto L & $\\template(\\xinput)$ = \\sent~It was \\mask . \\\\\n",
" & \\#1. irresistible/pathetic\\\\\n",
" & \\#2. wonderful/bad \\\\\n",
" & \\#3. delicious/bad \\\\\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \\midrule\n",
" \\tf{SNLI} & (entailment/neutral/contradiction) \\\\\n",
" \\midrule\n",
" Auto T & $\\mapping(\\labelset)$ = \\{Yes, Maybe, No\\} \\\\\n",
" & \\#1. {\\firstsent} . {\\mask} , no , {\\secondsent} \\\\\n",
" & \\#2. {\\firstsent} . {\\mask} , in this case {\\secondsent} \\\\\n",
" & \\#3. {\\firstsent} . {\\mask} this time {\\secondsent} \\\\\n",
" \\midrule\n",
" Auto L & $\\template(\\xinput)$ = \\firstsent~? \\mask~, \\secondsent \\\\\n",
" & \\#1. Alright/Watch/Except \\\\\n",
" & \\#2. Hi/Watch/Worse \\\\\n",
" & \\#3. Regardless/Fortunately/Unless \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\vspace{-3pt}\n",
" \\caption{Examples of our automatically generated templates (Auto T) and label words (Auto L).}\n",
" \\vspace{-8pt}\n",
" \\label{tab:generated_template}\n",
" \\end{table}\n",
"\n",
"In this section, we study the quality of our automatically generated prompts. This includes two parts: automatically generated templates (auto T) using manual label words and generated label words (auto L) using manual templates. Table~\\ref{tab:auto_search} shows the results of using manual or automatic prompts on selected datasets. In most cases, auto T achieves comparable or even higher performance than manual prompts. Auto L can outperform manual prompts on some datasets, but there are also cases where auto L perform significantly worse than the original results.\n",
"\n",
"To further analyze the automatic search results, we demonstrate some of the generated examples in Table~\\ref{tab:generated_template}.\n",
"Generated templates fit the context and the manual label words for most cases.\n",
"For automatically generated label words, things are mixed: while most of them look intuitively reasonable, there are some abnormal label words (e.g., ``better'' for the negative class in SST-5). We believe this is due to the overfitting issue of automatic label word search.\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Analysis of in-context learning}\n",
"\\label{sec:in_context_analysis}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"In this section we compare different variants of in-context fine-tuning. Table~\\ref{tab:pair_ablation} reports the performance of in-context fine-tuning without filtering, filtered by RoBERTa and filtered by Sentence-BERT. Since RoBERTa does not provide sentence embedding directly, we use the mean pooling over representations at all positions.\n",
"\n",
"From Table~\\ref{tab:pair_ablation}, we can see that all variants outperform prompt-based fine-tuning on most tasks. Compared to the vanilla in-context fine-tuning, using either of the encoders leads to further boost.\n",
"Among them, Sentence-BERT filtering achieves the best performance, and we take it as the default in-context fine-tuning model. We acknowledge that Sentence-BERT is trained on SNLI~\\cite{bowman2015large_snli}, MNLI~\\cite{williams2018broad_mnli} and STS-B~\\cite{cer2017semeval_sts-b} datasets, and this may contribute to the good performance in filtering.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" & \\tf{SST-2} & \\tf{SNLI} &\\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Prompt-based FT & \\tf{92.7} & 77.2 & 84.8 & 74.5 \\\\\n",
" \\midrule\n",
" Uniform sampling & 92.3 & 78.8 & 85.6 & 70.9 \\\\\n",
" \\tableindent + RoBERTa sel. & \\tf{92.7} & 79.5 & 83.4 & 76.6 \\\\\n",
" \\tableindent + SBERT sel. & 92.6 & \\tf{79.7} & \\tf{87.5} & \\tf{77.8} \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
"\n",
" \\caption{\n",
" Impact of demonstration sampling strategies.\n",
" Uniform sampling randomly samples demonstrations, while selective (sel.) sampling only takes top sentences measured by the sentence encoders (\\S \\ref{sec:demonstrations}).\n",
" }\n",
" \\vspace{-10pt}\n",
" \\label{tab:pair_ablation}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Comparisons of pre-trained LMs}\n",
"\n",
"\\label{sec:analysis_bert}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" \\tf{BERT-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 79.5 &\t51.4 & 80.3& \\tf{74.4} \\\\\n",
" \\midrule\n",
" Prompt-based FT & 85.6 & 59.2 & 79.0 & 66.8 \\\\\n",
" \\tableindent + demo (1-seg) & \\tf{87.5} & 50.4 & 77.2 & 68.5 \\\\\n",
" \\tableindent + demo (2-seg) & 86.1 & \\tf{61.3} & 77.9 & 73.2 \\\\\n",
" \\tableindent + demo ($n$-seg) & 86.4 & 58.6 & \\tf{79.6} & 71.0 \\\\\n",
" \\midrule\n",
" \\tf{RoBERTa-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 81.4 & 48.4 & \\tf{88.8} & 76.6\\\\\n",
" \\midrule\n",
" Prompt-based FT & \\tf{92.7} & 77.2 & 84.8 & 74.5 \\\\\n",
" \\tableindent + demonstrations & 92.6 & \\tf{79.7} & 87.5 & \\tf{77.8} \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{A comparison of BERT-large vs RoBERTa-large. We use manual prompts in these experiments.}\n",
" \\label{tab:bert}\n",
" \\end{table}\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Table~\\ref{tab:bert} shows the results of using BERT-large (uncased) and RoBERTa-large in our settings. Our in-context fine-tuning also works for BERT on some datasets, but the results are mixed compared to RoBERTa. This might be due to that BERT uses different segment embeddings to distinguish different parts of inputs (e.g., premise and hypothesis in NLI). There are only 2 pre-trained segment embeddings, and for in-context learning, we need to train new segment embeddings from scratch, which increases the instability of few-shot fine-tuning. \n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Sample Efficiency}\n",
"\n",
"\n",
"\\begin{figure}\n",
" \\centering\n",
" \\includegraphics[width=0.235\\textwidth]{figures/sample_sst2.pdf}\n",
" \\includegraphics[width=0.235\\textwidth]{figures/sample_snli.pdf}\n",
" \\caption{Performance of fine-tuning and our LM-BFF with different $K$ (numbers of instances per class).\n",
" \\todo{The last point of SNLI is a placeholder.}}\n",
" \\label{fig:sample}\n",
"\\end{figure} \n",
"\n",
"It is interesting to see how the standard fine-tuning and our method (LM-BFF) perform with increasing K and where we stand compared to taking the full dataset fine-tuning. Figure~\\ref{fig:sample} gives a comparison on SST-2 and SNLI. \n",
"We can see that for simple tasks like SST-2 (also see MR, CR and MPQA in Table~\\ref{tab:main_results}), LM-BFF already achieves comparable results to full dataset fine-tuning only with 32 examples. \n",
"With increasing $K$, LM-BFF continues to show performance gain compared to standard fine-tuning, until after $K=256$ where the two approaches converge.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Discussion}\n",
"\\label{sec:limitations}\n",
"\n",
"Reformulating NLP tasks as MLM has exciting implications for few-shot learning, but also has limitations. \n",
"First, while LM-BFF greatly outperforms standard fine-tuning, Table~\\ref{tab:main_results} shows that, overall, the performance still substantially lags behind \n",
"fine-tuning with thousands of examples, especially for harder tasks. \n",
"Additionally, just like standard fine-tuning, our results also suffer from high variance. \n",
"As described in \\S\\ref{sec:related_work}, several recent studies have tried to counter instability in few-shot fine-tuning \n",
"\n",
"and we expect these methods to also help here. \n",
"\n",
"\n",
"\n",
"With respect to automatic prompt generation, despite its effectiveness, \n",
"we still find it practically challenging to expand the search space, \n",
"or generalize well based on only approximately 32 examples. \n",
"This is partly due to our lingering reliance on \\emph{some} manual design---either manual templates (for label word search) or manual label words (for template search), \n",
"\n",
"which allows us to get our search off the ground, but does also bias it towards areas of the search space that we might have already imagined.\n",
"\n",
"\n",
"\n",
"\n",
"Finally, it is important to clarify that LM-BFF favors certain tasks which \n",
"(1) can be naturally posed as a ``fill-in-the-blank'' problem; \n",
"(2) have relatively short input sequences; and \n",
"(3) do not contain many output classes. \n",
"Issues (2) and (3) might be ameliorated with longer-context language models~\\cite[e.g.,][]{Beltagy2020Longformer}.\n",
"\n",
"For tasks that are not straightforward to formulate in prompting, such as structured prediction, issue (1) is more fundamental. \n",
"We leave it as an open question for future work.\n",
"\n",
"\\begin{figure}[!t]\n",
" \\centering\n",
" \\includegraphics[width=0.237\\textwidth, trim=4 5 0 0, clip]{figures/sample_sst2.pdf}\n",
" \\includegraphics[width=0.237\\textwidth, trim=4 5 0 0, clip]{figures/sample_snli.pdf}\n",
" \\caption{Standard fine-tuning vs our LM-BFF as a function of $K$ (\\# instances per class). For lower $K$, our method consistently outperforms standard fine-tuning.}\n",
" \\label{fig:sample}\n",
"\\end{figure}\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Conclusion}\n",
"\\label{sec:conclusion}\n",
"\n",
"In this paper we presented LM-BFF, a set of simple but effective techniques for fine-tuning language models using only a few examples. Our approach proposes to\n",
"(1) use prompt-based fine-tuning with automatically searched prompts;\n",
"and (2) include selected task demonstrations (training examples) as part of the input context.\n",
"We show \n",
"that our method outperforms vanilla fine-tuning by up to $30\\\n",
"We concluded by discussing the limitations of our approach, and posed open questions for future study.\n",
"\n",
"\\section*{Acknowledgements}\n",
"We thank the members of Princeton, MIT, Tsinghua NLP groups and the anonymous reviewers for their valuable feedback. TG is supported by a Graduate Fellowship at Princeton University and AF is supported by an NSF Graduate Research Fellowship. This research is also partly supported by a Google Research Scholar Award.\n",
"\n",
"\n",
"\\begin{comment}\n",
"\n",
"\\section*{Ethical Considerations}\n",
"\n",
"This work aims to further progress on few-shot learning across a range of NLP tasks. In general, allowing for overall smaller models to be used effectively with few labeled examples expands the accessibility of NLP solutions to more users with limited resources.\n",
"Nevertheless, our work makes use of medium-sized pre-trained language models, which---though smaller by design than other contemporary, massive models such as GPT-3---still require care when being deployed in potentially sensitive situations.\n",
"More concretely, leveraging the built-in knowledge of pre-trained language models as much as possible is a key feature we exploit in this work for effective few-shot learning.\n",
"At the same time, it is well known that these models can inherit the biases present in the data they are trained on---and therefore for some problems (such as those that are race- or gender-sensitive) may require modification and oversight.\n",
"However, though our methods may have similar bias concerns as a result, they are agnostic to the specific choice of language models, and we anticipate that developments in ethically-compliant language models can straighforwardly carry through in our use cases.\n",
"\n",
"\\end{comment}\n",
"\n",
"\n",
"\n",
"\\clearpage\n",
"\\bibliography{ref}\n",
"\\bibliographystyle{acl_natbib}\n",
"\n",
"\n",
"\\clearpage\n",
"\\appendix\n",
"\\counterwithin{figure}{section}\n",
"\\counterwithin{table}{section}\n",
"\n",
"\n",
"\\clearpage\n",
"\\section{Impact of Development Sets}\n",
"\\label{app:dev_size}\n",
"\n",
"\n",
"Table~\\ref{tab:exp_large_dev} shows how the size of the development sets can affect the final performance of the model.\n",
"For ``No $\\ddev$'', we take the same hyper-parameters from~\\citet{schick2020exploiting,schick2020size}: batch size = 16, learning rate = 1e-5 and training steps = 250. We also experiment with a variant that we sample a development set of 10 times larger than the training set. We can see that using larger development sets leads to better performance, and this is why we stick to $|\\dtrain| = |\\ddev|$ in our few-shot setting.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[h]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" {Fine-tuning} & \\tf{SST-2} & \\tf{SNLI} &\\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" No $\\ddev$ & 79.5 & 49.2 & 83.9 & 77.8 \\\\\n",
" $|\\ddev| = |\\dtrain|$ & 81.4 & 48.4 & 88.8 & 76.6 \\\\\n",
" $|\\ddev| = 10|\\dtrain|$ & 83.5 & 52.0 & 89.4 & 79.6 \\\\\n",
" \\midrule\n",
" {Prompt-based FT} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" No $\\ddev$ & 92.1 & 75.3 & 84.8 & 70.2 \\\\\n",
" $|\\ddev| = |\\dtrain|$ & 92.7 & 77.2 & 84.8 & 74.5 \\\\\n",
" $|\\ddev| = 10|\\dtrain|$ & 93.0 & 79.7 & 89.3 & 80.9 \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\vspace{-5pt}\n",
" \\caption{Impact of different sizes of development sets. Standard deviations are omitted here to save space. For No $|\\ddev|$, we use the same set of hyper-parameters as \\newcite{schick2020exploiting,schick2020size}.}\n",
" \\vspace{-15pt}\n",
" \\label{tab:exp_large_dev}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Datasets}\n",
"\\label{app:datasets}\n",
"\n",
"\n",
"\n",
"For SNLI~\\cite{bowman2015large_snli} and datasets from GLUE~\\cite{wang2019glue}, including SST-2~\\cite{socher2013recursive_sst-2}, CoLA~\\cite{warstadt2019neural_cola}, MNLI~\\cite{williams2018broad_mnli}, QNLI~\\cite{rajpurkar2016squad}, RTE~\\cite{dagan2005pascal_rte1,bar2006second,giampiccolo2007third_rte3,bentivogli2009fifth_rte4}, MRPC~\\cite{dolan2005automatically_mrpc}, QQP\\footnote{\\url{https://www.quora.com/q/quoradata/}} and STS-B~\\cite{cer2017semeval_sts-b}, we follow~\\newcite{zhang2020revisiting} and use their original development sets for testing. For datasets which require a cross-validation evaluation---MR~\\cite{pang2005seeing_mr}, CR~\\cite{hu2004mining_cr}, MPQA~\\cite{wiebe2005annotating_mpqa}, Subj~\\cite{pang2004sentimental_subj}---we simply randomly sample 2,000 examples as the testing set and leave them out from training. For SST-5~\\cite{socher2013recursive_sst-2} and TREC~\\cite{voorhees2000building_trec}, we use their official test sets. We show dataset statistics in Table~\\ref{tab:datasets}.\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{llcrrrcl}\n",
"\\toprule\n",
"\\tf{Category} & \\tf{Dataset} & $|\\mathcal{Y}|$ & $L$ & \\#Train & \\#Test & \\tf{Type} & \\tf{Labels (classification tasks)} \\\\\n",
"\\bottomrule\n",
" & SST-2 & 2 & 19 & 6,920 & 872 & sentiment & positive, negative \\\\\n",
"& SST-5 & 5 & 18 & 8,544 & 2,210 & sentiment & v. pos., positive, neutral, negative, v. neg. \\\\\n",
"& MR & 2 & 20 & 8,662& 2,000 & sentiment & positive, negative \\\\\n",
"single- & CR & 2 & 19 & 1,775 & 2,000 & sentiment & positive, negative \\\\\n",
"sentence & MPQA & 2 & 3 & 8,606 & 2,000 & opinion polarity & positive, negative \\\\\n",
"& Subj & 2 & 23 & 8,000 & 2,000 & subjectivity & subjective, objective \\\\\n",
"& TREC & 6 & 10 & 5,452 & 500 & question cls. & abbr., entity, description, human, loc., num.\\\\\n",
"& CoLA & 2 & 8 & 8,551 & 1,042 & acceptability & grammatical, not\\_grammatical\\\\\n",
"\\midrule\n",
" & MNLI & 3 & 22/11 & 392,702 & 9,815 & NLI & entailment, neutral, contradiction\\\\\n",
"& SNLI & 3 & 14/8 & 549,367 & 9,842 & NLI & entailment, neutral, contradiction \\\\\n",
"sentence- & QNLI & 2 & 11/30 & 104,743 & 5,463 & NLI & entailment, not\\_entailment \\\\\n",
"pair & RTE & 2 & 49/10 & 2,490 & 277 & NLI & entailment, not\\_entailment \\\\\n",
" & MRPC & 2 & 22/21 & 3,668 & 408 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& QQP & 2 & 12/12 & 363,846 & 40,431 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& STS-B & $\\mathcal{R}$ & 11/11 & 5,749 & 1,500 & sent. similarity & - \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{The datasets evaluated in this work. $|\\mathcal{Y}|$: \\# of classes for classification tasks (with one exception: STS-B is a real-valued regression task over the interval $[0, 5]$). $L$: average \\# of words in input sentence(s). Note that we only sample $\\dtrain$ and $\\ddev$ of $K \\times |\\labelset|$ examples from the original training set in our few-shot experiments (\\S\\ref{sec:setup}).}\n",
"\\label{tab:datasets}\n",
"\\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Experimental Details}\n",
"\\label{app:exp_details}\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Hyper-parameter selection}\n",
"\\label{app:hyper_selection}\n",
"For grid search, we take learning rates from \\{1e-5, 2e-5, 5e-5\\} and batch sizes from \\{2, 4, 8\\}.\n",
"These numbers are picked by pilot experiments on the SST-2 and SNLI datasets.\n",
"We also use early stopping to avoid overfitting.\n",
"For each trial, we train the model for 1,000 steps, validate the performance every 100 steps, and take the best checkpoint.\n",
"\n",
"\n",
"\n",
"\\subsection{Prompt-based fine-tuning}\n",
"\\label{app:prompts}\n",
"Table~\\ref{tab:manual_prompts} shows all the manual templates and label words we use in experiment.\n",
"For automatically template generation, we take the T5-3B\\footnote{We take the T5 1.0 checkpoint, which is trained on both unsupervised and downstream task data. We compared it to T5 1.1 (without downstream task data) and did not find a significant difference in generated templates.} model, which is the largest publicly available one that can fit on a single GPU.\n",
"For automatically searching label words, we set $k$ to 100 for all tasks except SST-5 and TREC. For SST-5 we set a smaller $k = 30$, as it is a 5-way classification task. For TREC, we observe that filtering $\\mathcal{V}^c$ using conditional likelihood alone is still noisy, thus we set $k = 1000$, and then re-rank $\\mathcal{V}^c$ by the nearest neighbors of the original manual label words and take the top 30 per class. We set $n$ to 100 in all experiments. \n",
"Due to the large number of trials in automatic search, we take a fixed set of hyper-parameters in this part: batch size of 8 and learning rate of 1e-5.\n",
"\n",
"Since the idea of prompt-based fine-tuning is to make the input and output distribution close to the pre-training, the implementation details are crucial.\n",
"For templates, we put extra space before sentences if it is not at the beginning of the input.\n",
"Also, we lowercase the first letter of the sentence if it is concatenated with a prefix (e.g., \\secondsent~in Table~\\ref{tab:manual_prompts}).\n",
"Also if one sentence is appended any punctuation (e.g., \\firstsent~in Table~\\ref{tab:manual_prompts}), then the last character of the original sentence is discarded.\n",
"Finally, we prepend a space for label words in $\\mapping(\\labelset)$. For example, we use ``\\_great'' instead of ``great'' in the RoBERTa vocabulary, where ``\\_'' stands for space.\n",
"\n",
"\\subsection{Fine-tuning with demonstrations}\n",
"\\label{app:demonstrations}\n",
"When using demonstrations, we sample $16$ different sets of demonstrations for each input and average the predicted log probability for each class during inference.\n",
"We find that further increasing the number of samples does not bring substantial improvement.\n",
"Additional, we have tried different aggregation methods like taking the result with the maximum confidence and we did not find a meaningful improvement.\n",
"For selective demonstrations, we take \\ttt{roberta-large-nli-stsb- mean-tokens}\\footnote{\\url{https://github.com/UKPLab/sentence-transformers}}\n",
"from \\newcite{reimers2019sentence}\n",
"as our sentence embedding model.\n",
"\n",
"\n",
"\n",
"\\section{Comparisons of BERT vs RoBERTa}\n",
"\\label{app:analysis_bert}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" \\tf{BERT-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 79.5 &\t51.4 & 80.3& \\tf{74.4} \\\\\n",
" \\midrule\n",
" Prompt-based FT & 85.6 & 59.2 & 79.0 & 66.8 \\\\\n",
" \\tableindent + demo (1-seg) & \\tf{87.5} & 50.4 & 77.2 & 68.5 \\\\\n",
" \\tableindent + demo (2-seg) & 86.1 & \\tf{61.3} & 77.9 & 73.2 \\\\\n",
" \\tableindent + demo ($n$-seg) & 86.4 & 58.6 & \\tf{79.6} & 71.0 \\\\\n",
" \\midrule\n",
" \\tf{RoBERTa-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 81.4 & 48.4 & \\tf{88.8} & 76.6\\\\\n",
" \\midrule\n",
" Prompt-based FT & \\tf{92.7} & 77.2 & 84.8 & 74.5 \\\\\n",
" \\tableindent + demonstrations & 92.6 & \\tf{79.7} & 87.5 & \\tf{77.8} \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{A comparison of BERT-large vs RoBERTa-large. We use manual prompts in these experiments.}\n",
" \\label{tab:bert}\n",
" \\end{table}\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Table~\\ref{tab:bert} compares the results of BERT-large (uncased) and RoBERTa-large in our settings.\n",
"Pre-trained BERT provides two segment embeddings (A/B) for different parts of input. The common practice, when fine-tuning BERT, is that using only segment A for single-sentence tasks, and using segment A/B for the two sentences in sentence-pair tasks. \n",
"In our case of incorporating demonstrations, however, we have more than two sentences. Thus we explore the following different strategies for segments:\n",
"(1) using the A segment for all sentences (1-seg);\n",
"(2) using the A segment for the original input and the B segment for the demonstrations (2-seg); \n",
"\n",
"(3) using different segment embeddings for each sentence ($n$-seg), e.g., for SNLI, we use different segments for each premise and hypothesis in both the original input and the demonstrations, which leads to a total number of 8 segment embeddings. This introduces new segment embeddings (randomly initialized and learned during fine-tuning) as the pre-trained BERT only has two. \n",
"\n",
"Table~\\ref{tab:bert} shows that\n",
"prompt-based fine-tuning with demonstrations also works for BERT, and 2-seg works the best when incorporating demonstrations.\n",
"Still, we take RoBERTa-large as our main model, for RoBERTa performs much better than BERT and RoBERTa saves the trouble to tune the usage of segment embeddings.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Generated Prompts}\n",
"\\label{app:generated_prompts}\n",
"\n",
"We demonstrate the top 3 automatically generated templates and label words for all tasks in Table~\\ref{tab:full_generated_prompt}. In general, most automatic templates are reasonable and grammatically correct.\n",
"For the label words, the generated results look intuitive for most single sentence tasks. For other tasks, the automatic ones can be counterintuitive in some cases.\n",
"It is still unclear why the language model picks these words and sometimes they actually work well.\n",
"We leave this for future study.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.91\\columnwidth}{!}{\n",
" \\begin{tabular}{lll}\n",
" \\toprule\n",
" \\tf{Task} & \\tf{Auto template} & \\tf{Auto label words}\\\\\n",
" \\midrule\n",
" \n",
"\n",
" \n",
" \\tf{SST-2} & (positive/negative) \\\\\n",
" & {\\sent} A {\\mask} one . & irresistible/pathetic \\\\\n",
" & {\\sent} A {\\mask} piece . & wonderful/bad \\\\\n",
" & {\\sent} All in all {\\mask} . & delicious/bad \\\\\n",
" \\midrule\n",
" \\tf{SST-5} & (very positive/positive/neutral/negative/very negative) \\\\\n",
" & {\\sent} The movie is {\\mask} . & wonderful/remarkable/hilarious/better/awful \\\\\n",
" & {\\sent} The music is {\\mask} . & wonderful/perfect/hilarious/better/awful \\\\\n",
" & {\\sent} But it is {\\mask} . & unforgettable/extraordinary/good/better/terrible \\\\\n",
" \\midrule\n",
" \\tf{MR} & (positive/negative) \\\\\n",
" & It was {\\mask} ! {\\sent} & epic/terrible \\\\\n",
" & {\\sent} It's {\\mask} . & epic/awful \\\\\n",
" & {\\sent} A {\\mask} piece of work . & exquisite/horrible \\\\\n",
" \\midrule\n",
" \\tf{CR} & (positive/negative) \\\\\n",
" & {\\sent} It's {\\mask} ! & fantastic/horrible \\\\\n",
" & {\\sent} The quality is {\\mask} . & neat/pointless \\\\\n",
" & {\\sent} That is {\\mask} . & magnificent/unacceptable \\\\\n",
" \\midrule\n",
" \\tf{MPQA} & (positive/negative) \\\\\n",
" & {\\sent} is {\\mask} . & important/close \\\\\n",
" & {\\sent}, {\\mask} ! & needed/bad \\\\\n",
" & {\\sent}. {\\mask} . & unexpected/shocking \\\\\n",
" \\midrule\n",
" \\tf{Subj} & (subjective/objective) \\\\\n",
" & {\\sent} It's all {\\mask} . & everywhere/tragic \\\\\n",
" & {\\sent} It's {\\mask} . & everywhere/horrifying \\\\\n",
" & {\\sent} Is it {\\mask} ? & something/surreal \\\\\n",
" \\midrule\n",
" \\tf{TREC} & (abbreviation/entity/description/human/location/numeric) \\\\\n",
" & Q: {\\mask} : {\\sent} & Application/Advisor/Discussion/Culture/Assignment/Minute \\\\\n",
" & {\\sent} Why {\\mask}? & Production/AE/Context/Artist/Assignment/Minute \\\\\n",
" & {\\sent} Answer: {\\mask} . & Personality/Advisor/Conclusion/Hum/Assignment/Minute \\\\\n",
" \\midrule\n",
" \\tf{CoLA} & (grammatical/not\\_grammatical) \\\\\n",
" & {\\sent} You are {\\mask} . & one/proof \\\\\n",
" & It is {\\mask} . {\\sent} & wrong/sad \\\\\n",
" & I am {\\mask} . {\\sent} & misleading/disappointing \\\\\n",
" \\midrule\n",
" \n",
" \\tf{MNLI} & (entailment/neutral/contradiction) \\\\\n",
" & {\\firstsent} . {\\mask} , you are right , {\\secondsent} & Fine/Plus/Otherwise \\\\\n",
" & {\\firstsent} . {\\mask} you're right {\\secondsent} & There/Plus/Otherwise \\\\\n",
" & {\\firstsent} . {\\mask} ! {\\secondsent} & Meaning/Plus/Otherwise \\\\\n",
" \\midrule\n",
" \\tf{SNLI} & (entailment/neutral/contradiction) \\\\\n",
" & {\\firstsent} . {\\mask} , no , {\\secondsent} & Alright/Watch/Except \\\\\n",
" & {\\firstsent} . {\\mask} , in this case {\\secondsent} & Hi/Watch/Worse \\\\\n",
" & {\\firstsent} . {\\mask} this time {\\secondsent} & Regardless/Fortunately/Unless \\\\\n",
" \\midrule\n",
" \\tf{QNLI} & (entailment/not\\_entailment) \\\\\n",
" & {\\firstsent} ? {\\mask} . Yes , {\\secondsent} & Okay/Nonetheless \\\\\n",
" & {\\firstsent} ? {\\mask} . It is known that {\\secondsent} & Notably/Yet \\\\\n",
" & {\\firstsent} ? {\\mask} , however , {\\secondsent} & Specifically/Notably \\\\\n",
" \\midrule\n",
" \\tf{RTE} & (entailment/not\\_entailment) \\\\\n",
" & {\\firstsent} . {\\mask} , I believe {\\secondsent} & Clearly/Yet \\\\\n",
" & {\\firstsent} . {\\mask} , I think that {\\secondsent} & Accordingly/meanwhile \\\\\n",
" & {\\firstsent} . {\\mask} , I think {\\secondsent} & So/Meanwhile \\\\\n",
" \\midrule\n",
" \\tf{MRPC} & (equivalent/not\\_equivalent) \\\\\n",
" & {\\firstsent} . {\\mask} ! {\\secondsent} & Rather/Alas \\\\\n",
" & {\\firstsent} . {\\mask} . This is the first time {\\secondsent} & At/Thus \\\\\n",
" & {\\firstsent} . {\\mask} . That's right . {\\secondsent} & Instead/Moreover \\\\\n",
" \\midrule\n",
" \\tf{QQP} & (equivalent/not\\_equivalent)\\\\\n",
" & {\\firstsent} ? {\\mask} , but {\\secondsent} & Me/Since \\\\\n",
" & {\\firstsent} ? {\\mask} , please , {\\secondsent} & Um/Best \\\\\n",
" & {\\firstsent} ? {\\mask} , I want to know {\\secondsent} & Ironically/Beyond \\\\\n",
" \\midrule\n",
" \\tf{STS-B} & ($y_u$/$y_l$)\\\\\n",
" & {\\firstsent} . {\\mask} sir {\\secondsent} & Note/Next \\\\\n",
" & {\\firstsent} . {\\mask} , it is not . {\\secondsent} & Yesterday/meanwhile \\\\\n",
" & {\\firstsent} . {\\mask} . It is {\\secondsent} & Yeah/meanwhile \\\\\n",
" \\bottomrule\n",
" \n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{Top 3 automatically generated templates and label words for all tasks based on one split of $K=16$ training examples. Note that automatic template results are based on manual label words and automatic label word results are based on manual templates provided in Table~\\ref{tab:manual_prompts}.}\n",
" \\label{tab:full_generated_prompt}\n",
" \\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\clearpage\n",
"\\section{Impact of Development Sets}\n",
"\\label{app:dev_size}\n",
"\n",
"\n",
"Table~\\ref{tab:exp_large_dev} shows how the size of the development sets can affect the final performance of the model.\n",
"For ``No $\\ddev$'', we take the same hyper-parameters from~\\citet{schick2020exploiting,schick2020size}: batch size = 16, learning rate = 1e-5 and training steps = 250. We also experiment with a variant that we sample a development set of 10 times larger than the training set. We can see that using larger development sets leads to better performance, and this is why we stick to $|\\dtrain| = |\\ddev|$ in our few-shot setting.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table}[h]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" {Fine-tuning} & \\tf{SST-2} & \\tf{SNLI} &\\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" No $\\ddev$ & 79.5 & 49.2 & 83.9 & 77.8 \\\\\n",
" $|\\ddev| = |\\dtrain|$ & 81.4 & 48.4 & 88.8 & 76.6 \\\\\n",
" $|\\ddev| = 10|\\dtrain|$ & 83.5 & 52.0 & 89.4 & 79.6 \\\\\n",
" \\midrule\n",
" {Prompt-based FT} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" No $\\ddev$ & 92.1 & 75.3 & 84.8 & 70.2 \\\\\n",
" $|\\ddev| = |\\dtrain|$ & 92.7 & 77.2 & 84.8 & 74.5 \\\\\n",
" $|\\ddev| = 10|\\dtrain|$ & 93.0 & 79.7 & 89.3 & 80.9 \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\vspace{-5pt}\n",
" \\caption{Impact of different sizes of development sets. Standard deviations are omitted here to save space. For No $|\\ddev|$, we use the same set of hyper-parameters as \\newcite{schick2020exploiting,schick2020size}.}\n",
" \\vspace{-15pt}\n",
" \\label{tab:exp_large_dev}\n",
"\\end{table}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Datasets}\n",
"\\label{app:datasets}\n",
"\n",
"\n",
"\n",
"For SNLI~\\cite{bowman2015large_snli} and datasets from GLUE~\\cite{wang2019glue}, including SST-2~\\cite{socher2013recursive_sst-2}, CoLA~\\cite{warstadt2019neural_cola}, MNLI~\\cite{williams2018broad_mnli}, QNLI~\\cite{rajpurkar2016squad}, RTE~\\cite{dagan2005pascal_rte1,bar2006second,giampiccolo2007third_rte3,bentivogli2009fifth_rte4}, MRPC~\\cite{dolan2005automatically_mrpc}, QQP\\footnote{\\url{https://www.quora.com/q/quoradata/}} and STS-B~\\cite{cer2017semeval_sts-b}, we follow~\\newcite{zhang2020revisiting} and use their original development sets for testing. For datasets which require a cross-validation evaluation---MR~\\cite{pang2005seeing_mr}, CR~\\cite{hu2004mining_cr}, MPQA~\\cite{wiebe2005annotating_mpqa}, Subj~\\cite{pang2004sentimental_subj}---we simply randomly sample 2,000 examples as the testing set and leave them out from training. For SST-5~\\cite{socher2013recursive_sst-2} and TREC~\\cite{voorhees2000building_trec}, we use their official test sets. We show dataset statistics in Table~\\ref{tab:datasets}.\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
"\\begin{center}\n",
"\\centering\n",
"\\resizebox{1.98\\columnwidth}{!}{\n",
"\\begin{tabular}{llcrrrcl}\n",
"\\toprule\n",
"\\tf{Category} & \\tf{Dataset} & $|\\mathcal{Y}|$ & $L$ & \\#Train & \\#Test & \\tf{Type} & \\tf{Labels (classification tasks)} \\\\\n",
"\\bottomrule\n",
" & SST-2 & 2 & 19 & 6,920 & 872 & sentiment & positive, negative \\\\\n",
"& SST-5 & 5 & 18 & 8,544 & 2,210 & sentiment & v. pos., positive, neutral, negative, v. neg. \\\\\n",
"& MR & 2 & 20 & 8,662& 2,000 & sentiment & positive, negative \\\\\n",
"single- & CR & 2 & 19 & 1,775 & 2,000 & sentiment & positive, negative \\\\\n",
"sentence & MPQA & 2 & 3 & 8,606 & 2,000 & opinion polarity & positive, negative \\\\\n",
"& Subj & 2 & 23 & 8,000 & 2,000 & subjectivity & subjective, objective \\\\\n",
"& TREC & 6 & 10 & 5,452 & 500 & question cls. & abbr., entity, description, human, loc., num.\\\\\n",
"& CoLA & 2 & 8 & 8,551 & 1,042 & acceptability & grammatical, not\\_grammatical\\\\\n",
"\\midrule\n",
" & MNLI & 3 & 22/11 & 392,702 & 9,815 & NLI & entailment, neutral, contradiction\\\\\n",
"& SNLI & 3 & 14/8 & 549,367 & 9,842 & NLI & entailment, neutral, contradiction \\\\\n",
"sentence- & QNLI & 2 & 11/30 & 104,743 & 5,463 & NLI & entailment, not\\_entailment \\\\\n",
"pair & RTE & 2 & 49/10 & 2,490 & 277 & NLI & entailment, not\\_entailment \\\\\n",
" & MRPC & 2 & 22/21 & 3,668 & 408 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& QQP & 2 & 12/12 & 363,846 & 40,431 & paraphrase & equivalent, not\\_equivalent \\\\\n",
"& STS-B & $\\mathcal{R}$ & 11/11 & 5,749 & 1,500 & sent. similarity & - \\\\\n",
"\\bottomrule\n",
"\\end{tabular}\n",
"}\n",
"\\end{center}\n",
"\\caption{The datasets evaluated in this work. $|\\mathcal{Y}|$: \\# of classes for classification tasks (with one exception: STS-B is a real-valued regression task over the interval $[0, 5]$). $L$: average \\# of words in input sentence(s). Note that we only sample $\\dtrain$ and $\\ddev$ of $K \\times |\\labelset|$ examples from the original training set in our few-shot experiments (\\S\\ref{sec:setup}).}\n",
"\\label{tab:datasets}\n",
"\\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Experimental Details}\n",
"\\label{app:exp_details}\n",
"\n",
"\n",
"\n",
"\n",
"\\subsection{Hyper-parameter selection}\n",
"\\label{app:hyper_selection}\n",
"For grid search, we take learning rates from \\{1e-5, 2e-5, 5e-5\\} and batch sizes from \\{2, 4, 8\\}.\n",
"These numbers are picked by pilot experiments on the SST-2 and SNLI datasets.\n",
"We also use early stopping to avoid overfitting.\n",
"For each trial, we train the model for 1,000 steps, validate the performance every 100 steps, and take the best checkpoint.\n",
"\n",
"\n",
"\n",
"\\subsection{Prompt-based fine-tuning}\n",
"\\label{app:prompts}\n",
"Table~\\ref{tab:manual_prompts} shows all the manual templates and label words we use in experiment.\n",
"For automatically template generation, we take the T5-3B\\footnote{We take the T5 1.0 checkpoint, which is trained on both unsupervised and downstream task data. We compared it to T5 1.1 (without downstream task data) and did not find a significant difference in generated templates.} model, which is the largest publicly available one that can fit on a single GPU.\n",
"For automatically searching label words, we set $k$ to 100 for all tasks except SST-5 and TREC. For SST-5 we set a smaller $k = 30$, as it is a 5-way classification task. For TREC, we observe that filtering $\\mathcal{V}^c$ using conditional likelihood alone is still noisy, thus we set $k = 1000$, and then re-rank $\\mathcal{V}^c$ by the nearest neighbors of the original manual label words and take the top 30 per class. We set $n$ to 100 in all experiments. \n",
"Due to the large number of trials in automatic search, we take a fixed set of hyper-parameters in this part: batch size of 8 and learning rate of 1e-5.\n",
"\n",
"Since the idea of prompt-based fine-tuning is to make the input and output distribution close to the pre-training, the implementation details are crucial.\n",
"For templates, we put extra space before sentences if it is not at the beginning of the input.\n",
"Also, we lowercase the first letter of the sentence if it is concatenated with a prefix (e.g., \\secondsent~in Table~\\ref{tab:manual_prompts}).\n",
"Also if one sentence is appended any punctuation (e.g., \\firstsent~in Table~\\ref{tab:manual_prompts}), then the last character of the original sentence is discarded.\n",
"Finally, we prepend a space for label words in $\\mapping(\\labelset)$. For example, we use ``\\_great'' instead of ``great'' in the RoBERTa vocabulary, where ``\\_'' stands for space.\n",
"\n",
"\\subsection{Fine-tuning with demonstrations}\n",
"\\label{app:demonstrations}\n",
"When using demonstrations, we sample $16$ different sets of demonstrations for each input and average the predicted log probability for each class during inference.\n",
"We find that further increasing the number of samples does not bring substantial improvement.\n",
"Additional, we have tried different aggregation methods like taking the result with the maximum confidence and we did not find a meaningful improvement.\n",
"For selective demonstrations, we take \\ttt{roberta-large-nli-stsb- mean-tokens}\\footnote{\\url{https://github.com/UKPLab/sentence-transformers}}\n",
"from \\newcite{reimers2019sentence}\n",
"as our sentence embedding model.\n",
"\n",
"\n",
"\n",
"\\section{Comparisons of BERT vs RoBERTa}\n",
"\\label{app:analysis_bert}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
" \\begin{table}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.0\\columnwidth}{!}{\n",
" \\begin{tabular}{lcccc}\n",
" \\toprule\n",
" \\tf{BERT-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 79.5 &\t51.4 & 80.3& \\tf{74.4} \\\\\n",
" \\midrule\n",
" Prompt-based FT & 85.6 & 59.2 & 79.0 & 66.8 \\\\\n",
" \\tableindent + demo (1-seg) & \\tf{87.5} & 50.4 & 77.2 & 68.5 \\\\\n",
" \\tableindent + demo (2-seg) & 86.1 & \\tf{61.3} & 77.9 & 73.2 \\\\\n",
" \\tableindent + demo ($n$-seg) & 86.4 & 58.6 & \\tf{79.6} & 71.0 \\\\\n",
" \\midrule\n",
" \\tf{RoBERTa-large} & \\tf{SST-2} & \\tf{SNLI} & \\tf{TREC} & \\tf{MRPC} \\\\\n",
" \\midrule\n",
" Fine-tuning & 81.4 & 48.4 & \\tf{88.8} & 76.6\\\\\n",
" \\midrule\n",
" Prompt-based FT & \\tf{92.7} & 77.2 & 84.8 & 74.5 \\\\\n",
" \\tableindent + demonstrations & 92.6 & \\tf{79.7} & 87.5 & \\tf{77.8} \\\\\n",
" \\bottomrule\n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{A comparison of BERT-large vs RoBERTa-large. We use manual prompts in these experiments.}\n",
" \\label{tab:bert}\n",
" \\end{table}\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"Table~\\ref{tab:bert} compares the results of BERT-large (uncased) and RoBERTa-large in our settings.\n",
"Pre-trained BERT provides two segment embeddings (A/B) for different parts of input. The common practice, when fine-tuning BERT, is that using only segment A for single-sentence tasks, and using segment A/B for the two sentences in sentence-pair tasks. \n",
"In our case of incorporating demonstrations, however, we have more than two sentences. Thus we explore the following different strategies for segments:\n",
"(1) using the A segment for all sentences (1-seg);\n",
"(2) using the A segment for the original input and the B segment for the demonstrations (2-seg); \n",
"\n",
"(3) using different segment embeddings for each sentence ($n$-seg), e.g., for SNLI, we use different segments for each premise and hypothesis in both the original input and the demonstrations, which leads to a total number of 8 segment embeddings. This introduces new segment embeddings (randomly initialized and learned during fine-tuning) as the pre-trained BERT only has two. \n",
"\n",
"Table~\\ref{tab:bert} shows that\n",
"prompt-based fine-tuning with demonstrations also works for BERT, and 2-seg works the best when incorporating demonstrations.\n",
"Still, we take RoBERTa-large as our main model, for RoBERTa performs much better than BERT and RoBERTa saves the trouble to tune the usage of segment embeddings.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\section{Generated Prompts}\n",
"\\label{app:generated_prompts}\n",
"\n",
"We demonstrate the top 3 automatically generated templates and label words for all tasks in Table~\\ref{tab:full_generated_prompt}. In general, most automatic templates are reasonable and grammatically correct.\n",
"For the label words, the generated results look intuitive for most single sentence tasks. For other tasks, the automatic ones can be counterintuitive in some cases.\n",
"It is still unclear why the language model picks these words and sometimes they actually work well.\n",
"We leave this for future study.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\begin{table*}[t]\n",
" \\begin{center}\n",
" \\centering\n",
" \\resizebox{1.91\\columnwidth}{!}{\n",
" \\begin{tabular}{lll}\n",
" \\toprule\n",
" \\tf{Task} & \\tf{Auto template} & \\tf{Auto label words}\\\\\n",
" \\midrule\n",
" \n",
"\n",
" \n",
" \\tf{SST-2} & (positive/negative) \\\\\n",
" & {\\sent} A {\\mask} one . & irresistible/pathetic \\\\\n",
" & {\\sent} A {\\mask} piece . & wonderful/bad \\\\\n",
" & {\\sent} All in all {\\mask} . & delicious/bad \\\\\n",
" \\midrule\n",
" \\tf{SST-5} & (very positive/positive/neutral/negative/very negative) \\\\\n",
" & {\\sent} The movie is {\\mask} . & wonderful/remarkable/hilarious/better/awful \\\\\n",
" & {\\sent} The music is {\\mask} . & wonderful/perfect/hilarious/better/awful \\\\\n",
" & {\\sent} But it is {\\mask} . & unforgettable/extraordinary/good/better/terrible \\\\\n",
" \\midrule\n",
" \\tf{MR} & (positive/negative) \\\\\n",
" & It was {\\mask} ! {\\sent} & epic/terrible \\\\\n",
" & {\\sent} It's {\\mask} . & epic/awful \\\\\n",
" & {\\sent} A {\\mask} piece of work . & exquisite/horrible \\\\\n",
" \\midrule\n",
" \\tf{CR} & (positive/negative) \\\\\n",
" & {\\sent} It's {\\mask} ! & fantastic/horrible \\\\\n",
" & {\\sent} The quality is {\\mask} . & neat/pointless \\\\\n",
" & {\\sent} That is {\\mask} . & magnificent/unacceptable \\\\\n",
" \\midrule\n",
" \\tf{MPQA} & (positive/negative) \\\\\n",
" & {\\sent} is {\\mask} . & important/close \\\\\n",
" & {\\sent}, {\\mask} ! & needed/bad \\\\\n",
" & {\\sent}. {\\mask} . & unexpected/shocking \\\\\n",
" \\midrule\n",
" \\tf{Subj} & (subjective/objective) \\\\\n",
" & {\\sent} It's all {\\mask} . & everywhere/tragic \\\\\n",
" & {\\sent} It's {\\mask} . & everywhere/horrifying \\\\\n",
" & {\\sent} Is it {\\mask} ? & something/surreal \\\\\n",
" \\midrule\n",
" \\tf{TREC} & (abbreviation/entity/description/human/location/numeric) \\\\\n",
" & Q: {\\mask} : {\\sent} & Application/Advisor/Discussion/Culture/Assignment/Minute \\\\\n",
" & {\\sent} Why {\\mask}? & Production/AE/Context/Artist/Assignment/Minute \\\\\n",
" & {\\sent} Answer: {\\mask} . & Personality/Advisor/Conclusion/Hum/Assignment/Minute \\\\\n",
" \\midrule\n",
" \\tf{CoLA} & (grammatical/not\\_grammatical) \\\\\n",
" & {\\sent} You are {\\mask} . & one/proof \\\\\n",
" & It is {\\mask} . {\\sent} & wrong/sad \\\\\n",
" & I am {\\mask} . {\\sent} & misleading/disappointing \\\\\n",
" \\midrule\n",
" \n",
" \\tf{MNLI} & (entailment/neutral/contradiction) \\\\\n",
" & {\\firstsent} . {\\mask} , you are right , {\\secondsent} & Fine/Plus/Otherwise \\\\\n",
" & {\\firstsent} . {\\mask} you're right {\\secondsent} & There/Plus/Otherwise \\\\\n",
" & {\\firstsent} . {\\mask} ! {\\secondsent} & Meaning/Plus/Otherwise \\\\\n",
" \\midrule\n",
" \\tf{SNLI} & (entailment/neutral/contradiction) \\\\\n",
" & {\\firstsent} . {\\mask} , no , {\\secondsent} & Alright/Watch/Except \\\\\n",
" & {\\firstsent} . {\\mask} , in this case {\\secondsent} & Hi/Watch/Worse \\\\\n",
" & {\\firstsent} . {\\mask} this time {\\secondsent} & Regardless/Fortunately/Unless \\\\\n",
" \\midrule\n",
" \\tf{QNLI} & (entailment/not\\_entailment) \\\\\n",
" & {\\firstsent} ? {\\mask} . Yes , {\\secondsent} & Okay/Nonetheless \\\\\n",
" & {\\firstsent} ? {\\mask} . It is known that {\\secondsent} & Notably/Yet \\\\\n",
" & {\\firstsent} ? {\\mask} , however , {\\secondsent} & Specifically/Notably \\\\\n",
" \\midrule\n",
" \\tf{RTE} & (entailment/not\\_entailment) \\\\\n",
" & {\\firstsent} . {\\mask} , I believe {\\secondsent} & Clearly/Yet \\\\\n",
" & {\\firstsent} . {\\mask} , I think that {\\secondsent} & Accordingly/meanwhile \\\\\n",
" & {\\firstsent} . {\\mask} , I think {\\secondsent} & So/Meanwhile \\\\\n",
" \\midrule\n",
" \\tf{MRPC} & (equivalent/not\\_equivalent) \\\\\n",
" & {\\firstsent} . {\\mask} ! {\\secondsent} & Rather/Alas \\\\\n",
" & {\\firstsent} . {\\mask} . This is the first time {\\secondsent} & At/Thus \\\\\n",
" & {\\firstsent} . {\\mask} . That's right . {\\secondsent} & Instead/Moreover \\\\\n",
" \\midrule\n",
" \\tf{QQP} & (equivalent/not\\_equivalent)\\\\\n",
" & {\\firstsent} ? {\\mask} , but {\\secondsent} & Me/Since \\\\\n",
" & {\\firstsent} ? {\\mask} , please , {\\secondsent} & Um/Best \\\\\n",
" & {\\firstsent} ? {\\mask} , I want to know {\\secondsent} & Ironically/Beyond \\\\\n",
" \\midrule\n",
" \\tf{STS-B} & ($y_u$/$y_l$)\\\\\n",
" & {\\firstsent} . {\\mask} sir {\\secondsent} & Note/Next \\\\\n",
" & {\\firstsent} . {\\mask} , it is not . {\\secondsent} & Yesterday/meanwhile \\\\\n",
" & {\\firstsent} . {\\mask} . It is {\\secondsent} & Yeah/meanwhile \\\\\n",
" \\bottomrule\n",
" \n",
" \\end{tabular}\n",
" }\n",
" \\end{center}\n",
" \\caption{Top 3 automatically generated templates and label words for all tasks based on one split of $K=16$ training examples. Note that automatic template results are based on manual label words and automatic label word results are based on manual templates provided in Table~\\ref{tab:manual_prompts}.}\n",
" \\label{tab:full_generated_prompt}\n",
" \\end{table*}\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\\end{document}\n"
],
"del_percentage": 0.06272
}
}