NICE: To Optimize In-Context Examples or Not? (2024)

Abstract: Recent work shows that in-context learning and optimization of in-context examples (ICE) can significantly improve the accuracy of large language models (LLMs) on a wide range of tasks, leading to an apparent consensus that ICE optimization is crucial for better performance. However, most of these studies assume a fixed or no instruction provided in the prompt. We challenge this consensus by investigating the necessity of optimizing ICE when task-specific instructions are provided and find that there are many tasks for which it yields diminishing returns. In particular, using a diverse set of tasks and a systematically created instruction set with gradually added details, we find that as the prompt instruction becomes more detailed, the returns on ICE optimization diminish. To characterize this behavior, we introduce a taskspecific metric called Normalized Invariability to Choice of Examples (NICE) that quantifies the learnability of tasks from a given instruction, and provides a heuristic to help decide whether to optimize instructions or ICE for a new task. Given a task, the proposed metric can reliably predict the utility of optimizing ICE compared to using random ICE. Our code is available at https://github.com/microsoft/niceicl.

heading: 1 Introduction
text: With the scaling up of large language models (LLMs) in terms of model size and training data, recent work demonstrates their emergent in-context learning ability across a wide range of tasks (Brown et al., 2020; Radford et al., 2019; Kaplan et al., 2020). Specifically, the in-context learning (ICL) paradigm studies ability of an LLM to perform a new task given a few example demonstrations. The selection of good in-context examples (ICE) from a large pool of candidates is a non-trivial optimiza-
* These authors contributed equally.
tion problem over a large search space (Liu et al., 2022).
In-context learning ability in LLMs has motivated a growing body of literature on how to select the ICE to be added to an LLM’s input prompt (Liu et al., 2022; Lu et al., 2022; Zhang et al., 2022b; Qin et al., 2023). These works propose various ICE selection techniques and demonstrate significant improvements in LLM performance across a range of tasks, leading to an apparent consensus in the literature that ICE optimization is critical for better ICL performance of LLMs.
However, with the advent of instruction-tuning (Wei et al., 2021; Chung et al., 2024; Ouyang et al., 2022), LLMs are expected to follow natural language instructions, making it possible to solve a task in a zero-shot manner, i.e., learning with just the instruction and no ICE. As a result, a typical prompt to an LLM contains both the instruction and ICE. A natural question that follows is how instructions and ICE interact and whether they can be jointly optimized. Would ICE optimization still matter once a detailed task instruction is given? More practically, given a task, is optimizing the instruction more effective or optimizing ICE?
Using state-of-the-art LLMs, our main finding is that returns on ICE optimization diminish as more detailed instructions are added to the input prompt. We find that a detailed instruction with randomly chosen ICE surpasses or matches the accuracy of a prompt with ICE selected using criteria from past work (Liu et al., 2022; Levy et al., 2023; Rubin et al., 2021; Sorensen et al., 2022) across diverse tasks. These tasks include SST-2 and SST-5 for 2 and 5-way sentiment classification respectively (Socher et al., 2013), MNLI for natural language inference (Williams et al., 2017), TREC for 6-way question classification (Li and Roth, 2002), MedQA (Jin et al., 2021) and FinQA for domainspecific question-answering (Chen et al., 2021). Moreover, given a detailed instruction, even using
5494
ICE with incorrect labels yields the same accuracy as using correct labels on most tasks. On the other hand, there exists a different class of tasks, especially generative tasks that expect the output to follow specific schema, where ICE selection matters. For example, for tasks such as NL2BASH for bash command generation (Lin et al., 2018), MTOP (Li et al., 2021) for semantic parsing, and Break (Wolfson et al., 2020) for Question Decomposed Meaning Representation (QDMR) generation, a prompt with chosen examples outperforms a prompt containing a descriptive instruction with random ICE.
Therefore, contrary to prior work, we argue that ICE optimization per query may not always be the most effective strategy for improving performance, especially if the task instructions are much simpler to write (e.g., using our proposed template in Section 3.1). To characterize the tasks where ICE optimization may or may not matter, we introduce a metric called Normalized Invariability to Choice of Examples (NICE) that measures, for a given task and an instruction, the invariability of an LLM’s task performance to ICE. We partition the candidate pool of examples into a relatively small number of query-dependent bins (e.g., based on cosine similarity of examples to the given query), and compute a bin-wise score given by the task performance of an LLM when the given task instruction is augmented with random ICE picked only from a particular bin. Our NICE metric compares the maximum score against the average score over all bins. We show that this simple metric can effectively capture the dependence of tasks on ICE optimization. Schema-based generative tasks such as MTOP and BREAK have low NICE values (<0.4) whereas all other tasks have high NICE values (>0.85). Further, the NICE value increases when we include more detailed task instructions, and suggests diminishing returns of ICE optimization for better instructions.
As a practical implication, our work provides a method to decide the best option for improving an LLM’s task accuracy: ICE optimization or improving the instruction (see Fig. 1). To this end, we propose a template for creating a detailed instruction for any task and provide an efficient procedure to compute the NICE metric. Given the task and a template instruction, if the NICE value is high, then it is more effective to improve the instruction and random ICE suffice. Otherwise, if the NICE value is low, it is more effective to do ICE optimization.
To summarize, our main contributions are:

heading: HighLow

heading: Template Instruction
text: • Contrary to prior work, we show that ICE optimization does not always lead to performance improvement for LLMs. Across a range of tasks, we find that the performance of prompts improves with more detailed instructions, and this improvement remains constant even when the true labels in ICE are replaced with random labels.
• We introduce a practical, task-specific metric called NICE that helps predict if a given task and an instruction will benefit from ICE optimization.
• For tasks with high NICE value, we find that detailed instructions with random ICE obtain comparable or better performance than prompts with optimized ICE. On the other hand, for tasks with low NICE value, optimized ICE lead to better performance.

heading: 2 Related Work

heading: 2.1 ICE Selection Methods
text: Prior work on ICE selection can be divided into learning-free and learning-based methods.
Learning-free methods: Liu et al. (2022) propose a kNN-based method for selecting the top-k candidates based on their cosine-similarity with the query with the assumption that ICE with high similarity in the embedding space would help the most on downstream tasks. Sorensen et al. (2022) compare two in-context examples and select the one that maximizes the mutual information with the query. Gonen et al. (2023) attempt to select
ICE with low perplexity, while Levy et al. (2023) show that diversity in demonstrations improves the compositional generalization ability of LLMs.
Learning-based methods: Rubin et al. (2022) propose a two-stage retrieval method to select ICE. For a given input, they utilize a BM-25-based retriever to select candidate examples and then employ a retriever trained through contrastive learning to pick ICE. Li et al. (2023) enhance it by proposing a Unified Demonstration Retriever (UDR) across different tasks. Lu et al. (2023) propose a policygradient method for selecting ICE using a specific policy formulation for a given query. Ye et al. (2023) retrieve a set of demonstrations rather than extracting individual ones in order to capture interdemonstration relationships. They train a Determinantal Point Process (DPP)-based retriever to match scores of the LLM output, obtaining the most likely demonstration set through maximum a-posteriori during inference.

heading: 2.2 Jointly Optimizing Instructions and ICE
text: Most of the above work on ICE selection, however, considers a prompt without any instruction. In a separate line of work, methods for instruction optimization have been proposed (Zhou et al., 2023; Pryzant et al., 2023), but these do not consider ICE in the prompt. A recent RL-based method (Zhang et al., 2022a) optimizes over both discrete instruction and example sets in the prompt. However, the search space for unconstrained joint optimization becomes exponentially large for large instruction and example spaces.
While these works show the importance of optimizing instructions and examples for various tasks, they do not perform a comprehensive comparison of the two. In this paper, our objective is to compare the two task-learning paradigms—instruction following and in-context learning—and evaluate their relative importance across a diverse range of tasks. We find that the choice of optimal tasklearning paradigm depends on the task, and propose a method to determine which of these optimizations is expected to benefit LLM performance.

heading: 3 Problem Formulation
text: Optimizing ICE amounts to selecting the best k examples from a given pool of candidate examples that should be included in the prompt. However, optimizing the instruction is not a straightforward optimization because the space of possible instruc-
tions can be extremely large. Hence, we first provide a instruction template covering five types of instructions that we consider in this paper, and then define our research questions.

heading: 3.1 Prompt Structure and Instruction Set
text: For a fair comparison across instructions and generalizability to new tasks, we use a standard prompt template consisting of an instruction, kshot demonstrations (xi, yi) from a training set DT , and a query x from the test set with a cue for the model to predict y. We define a consistent structure to create a general set of instructions, iteratively adding useful, task-specific information to the instruction starting with no instruction and following a guideline similar to Zhang et al. (2023). A consistent template without human creativity ensures that our findings are not constrained to a narrow distribution of carefully-crafted prompts. The gradual addition of detailed information in the instruction serves as a proxy for "improved" instructions based on the results from Zhang et al. (2023).
For classification tasks, we consider the following kinds of instructions:
• No Instruction (NI): We provide no instruction, so LLM is expected to learn only from examples. • Task Definition (TD): A simple task definition without any other information. • Task Definition with Label Space (+LS): Including the label space in the task definition. (e.g. [“positive”, “negative”] for a binary sentiment classification task. • Task Definition with Label Meanings (+LM): We specify the meanings of the labels in the label space along with the task definition. • Delusive Instruction (DI): We also evaluate the model’s task learnability when the instruction is misleading, i.e., describing a task with shuffled labels. (e.g. “positive” for “negative”).
Note that we presented the instructions in increasing order of detail or effectiveness, except the Delusive Instruction which is expected to have the lowest effectiveness. For generation tasks, since there is no notion of label space, we introduce an additional variant of detailed instruction:
• Task Definition with Rules (+R): A simple task definition with syntactic rules for the task.
For generation tasks, we experiment with the ‘NoInstruction’ and ‘Task-Definition’ cases in the same
way as defined for classification tasks. Some examples are given in Appendix A.1.

heading: 3.2 Research Questions
text: We focus on the following research questions.
RQ1: Do all tasks benefit from in-context example optimization? To investigate whether ICE optimization is needed for a given task, we compare the LLM’s performance with different kinds of ICE. Specifically, we compare bins of ICE at different distances from a given query and check how the LLM’s performance varies. To understand how the effect of ICE optimization changes with the instruction quality, we repeat the experiment for the different instructions listed above. We evaluate various tasks based on the NICE metric defined in Eq. (2).
RQ2: How do ICE selection methods compare to random selection with a detailed instruction? Here we directly compare ICE optimization methods versus random ICE selection and study how the LLM’s performance gap varies with different instruction types.
RQ3: Given a detailed instruction, does providing the correct labels for ICE matter? Past works have studied the impact of noisy (Wei et al., 2023) and biased (Gupta et al., 2023) labels on LLM performance. We study how those conclusions may not hold in the presence of detailed instructions.
Min et al. (2022) identify four aspects of demonstrations that serve as a learning signal to the LLM: the input-label mapping, the distribution of the input text, the label space and the format. Concretely, they say that in-context examples play a role by informing the model of the label space or the format of the output. Pan et al. (2023) discuss the phenomena of task learning and task recognition as the two ways through which an LLM learns from demonstrations by comparing the performance of randomly labeled examples against abstract and gold-labeled ones.
Based on these works, we evaluate the role of input-label mapping for in-context learning, under the presence of a detailed task instruction. Specifically, we investigate whether in-context examples are being used for information about the input-label mapping or they are simply serving as information for task recognition: providing the input distribution, label space or output format. To this extent, we introduce perturbations in the in-context examples by randomizing their ground-truth labels.
In the case of classification tasks, we assign randomly chosen labels y ∼ YT to the inputs of the in-context examples, where YT denotes the label space of the output for a particular task T . In the case of generation tasks, we shuffle the ground truth values y of the ICE amongst themselves to introduce a perturbation.

heading: 4 NICE: Measuring Invariability to ICE
text: In addition to answering the research questions above, we provide a practical metric to assess the effectiveness of optimizing ICE. That is, to decide whether to optimize instruction or in-context examples, we develop a task-specific metric for a given instruction that measures the invariability of task performance to ICE selection.
We assume that each task is associated with a training set from which ICE are selected for a given query. Given a new query, we assume access to a scoring function f of the candidate examples and the query. To study invariance to ICE selection, for each query in the test set, we partition available training data of candidate examples using the function f into multiple bins. Subsequently, for each bin, given a test sample of queries, we compute the model’s performance using a pre-specified instruction I and random ICE from the bin for each query (and then averaging the resultant accuracy). This yields the score S for a bin,
S(j, I,D) = E x∼D E ej∼bxj [YLM (x|(I + ej))] , (1)
where YLM is the performance measure (higher is better) of the language model, D is the set of test queries, I is the given instruction and bxj ∈ B is the j-th bin for query x. Intuitively, given a task, high variance in the scores S across bins indicates a task where ICE selection may be important.

heading: 4.1 Metric Requirements
text: Before proposing a metric, we first outline some properties to be followed by the proposed metric so that it can capture returns of ICE optimization for a given task and a given instruction. • Property 1: The metric should be bounded
within (0,1], establishing a well-defined baseline to compare all tasks. • Property 2: It should be linearly invariant to the performance measures for each task, ensuring independence from variations in model capability and task difficulty.
• Property 3: If S(j, I,D) ≈ max j S(j, I,D) for all j, i.e., the performance of the model is invariant to the bin from which the examples are chosen, the metric should be close to 1. • Property 4: Let bmax = argmaxj S(j, I,D) be the best bin. If, for all j ̸= bmax, S(j, I,D) ≪ S(bmax, I,D), this represents a strictly retrieval task where the budget needs to be spent on ICE optimization. In this scenario, the metric should approach 0. Since API calls to LLMs are both costly and time consuming, another requirement is that the metric should be computable much more efficiently than typical ways to optimize over the search space of all candidate examples. In the next section, we introduce the NICE metric and in Appendix A.2, we prove that it follows all Properties 1-4.

heading: 4.2 Normalized Invariability to Choice of Examples (NICE)
text: Our metric, called the Normalized Invariability to Choice of Examples (NICE) of a task for a given instruction, is defined as the ratio of the expected score over all bins to the maximum amongst them. Mathematically, NICE is defined as follows:
NICE(D, I) = E 0<j≤|B| [S(j, I,D)]
max 0<j≤|B|
S(j, I,D) , (2)
where S(j, I) is the score for the j-th bin in B for a given instruction. Note that this score can be computed for any choice of task, any instruction, any performance measure YLM , and any grouping function f for partitioning the candidate examples. Liu et al. (2022) show that cosine similarity with
the query is a good proxy for selecting ICE. Thus, we set up our baseline to study the performance trend in various datasets by binning the examples (x) based on their similarity to the query (q). We assume the grouping function f as,
f := sim(x,q) = x⊤q
∥x∥∥q∥ . (3)
We partition the set of examples into bins based on the grouping function f for each example x, e.g., 0− 10%, 10− 20%. Combining Eqs. (1) and (2) with the grouping function from Eq. (3) gives us the NICE baseline we set up to distinguish tasks. Note that our simple cosine-similarity-based baseline can be easily extended to consider advanced clustering heuristics such as influence functions (Nguyen and Wong, 2023).
We hypothesize that high-NICE tasks are learnable from instructions and do not need carefully selected examples, whereas for low-NICE tasks, examples play a major role and we suggest spending more budget on optimizing ICE. We validate this hypothesis in the next section.

heading: 5 Results

heading: 5.1 Experimental Setup
text: To calculate the NICE metric, we use GPT-4-Turbo and due to cost considerations, we use GPT-3.5-Turbo for all other experiments. We show similar results using GPT-3.5-Turbo and the open-source models Llama-2-70B-Chat and Mixtral-8x7B-Instruct in Appendix A.4.
Using the ICE baseline methods from Subsection 3.2, we pick up the top k = 8 examples as the incontext examples with the instruction, similar to
other works that use k ∈ {4, 8, 16} (Min et al., 2022; Wei et al., 2023; Lu et al., 2022; Zhang et al., 2022c). Tasks: We experiment with the following tasks in line with other works in in-context learning: Stanford Sentiment Treebank (SST-2 and SST-5) (Socher et al., 2013), question multi-class classification in TREC (Li and Roth, 2002), textual entailment in MNLI (Williams et al., 2017), semantic parsing in MTOP, which is a multilingual task-oriented semantic parsing dataset with hierarchical intent-slot schema (Li et al., 2021), question decomposition in Break, where the input is a complex question (x) and the task is to map the question to its QDMR steps (s = ⟨s1, ..., sn⟩) (Wolfson et al., 2020), code generation in NL2BASH (Lin et al., 2018) and hybrid and multi-choice question-answering in FinQA (Chen et al., 2021) and MedQA (Jin et al., 2021) respectively. Details about our tasks and their NICE scores are given in Table 1. Train-test split: The training split of each dataset acts as a pool of candidate examples, and pick 50 queries randomly from the test split as our tet set. Computing NICE: For computing the NICE metric, for each test query, we partition the candidate examples into groups/bins based on the grouping function f defined in Eq. (3). We randomly sample 10 sets of k-shot demonstrations 1 from a specific bin for a given query and evaluate the model’s performance and report the averaged out results over 50 queries for each group.

heading: 5.2 RQ1: Does ICE optimization always help?
text: Fig. 2 shows the trend in performance with and without instructions using GPT-4-Turbo: • No Instruction: When we prompt the model with just in-context examples without any instruction, the NICE for relatively simpler tasks (SST2, SST5, and MNLI) is higher than more complex tasks (TREC, Break, NL2BASH, and MTOP). • Detailed Instruction: When a detailed, taskspecific instruction is added to the prompt along with ICE, we observe a flattening effect owing to improved invariability to bin-selection in binwise performance for TREC, SST5, and MTOP, thus increasing the NICE for these tasks. This evidence supports our hypothesis that the effect of picking specific ICE decreases in the presence of instructions. 1For GPT-4-Turbo and GPT-3.5-Turbo models, we take k=4 while we set k=16 for the others.
We observe in Fig. 2 that for tasks with a high NICE, it is not helpful to selectively retrieve in-context examples conditioned on the query. Learning-based methods such as Rubin et al. (2022) propose a contrastive-learning based objective for selecting ICE by scoring each subset of examples for a given query. With invariability in terms of the model’s performance across appropriately grouped subsets, such scoring-based methods would also not lead to performance improvements.

heading: 5.3 RQ2: Optimized ICE versus Random ICE
text: We consider three different baselines for methods to select in-context examples for a given query.
• Top-k-BERT: This dense retrieval method uses BERT (Devlin et al., 2019) embeddings to compute the cosine similarity of examples with the query and selects the top-k examples. • BM-25: BM-25 is a sparse bag-of-words retrieval algorithm that ranks examples using a tf-idf -based relevance score. • DPP: Determinantal Point Processes (DPP) (Borodin, 2009) compute a proba-
bility measure over the possible subsets of a discrete set. They model the repulsion between the items in a chosen subset by considering the volume of the parallelepiped formed by the feature vectors of the items in it as a measure of the probability of picking up that subset, thus optimizing for diversity in a specified criterion.
To ensure the reliability of our results, we report the mean accuracies with standard deviation bars. To obtain the error bar for the Instruction + Random Examples approach, we sample 3 random subsets of k in-context examples. We then compute the mean and standard deviation of accuracy for each query and aggregate these mean accuracies and standard deviations across different queries in the dev set of each dataset. We report the mean of these mean accuracies (for different dev-set queries) and the mean of these standard deviations (serving as the error bar). For the ICE selection methods (DPP, Top-K-BERT, BM25), we consider 3 different permutations of the in-context examples retrieved by these methods for each query. We report the final mean and standard deviation in accuracy similar to
the random example case above. Fig. 3 shows a comparison between the performance of different in-context example selection methods with no instructions against randomly sampled examples with a detailed task-specific instructions. We find that for high NICE tasks (SST2, SST5, TREC, MNLI, FinQA, and MedQA) which possess high-instruction learnability, the performance with even randomly sampled in-context examples complemented with a carefully crafted taskspecific instruction surpasses or matches the performance of the above mentioned in-context example selection methods with no instruction.
On the other hand, for tasks with a low NICE (MTOP, Break, and NL2BASH), we see that ICE optimization helps in improving the performance over randomly sampled examples accompanied with instructions. Interestingly, we observe that the the distance of the task’s NICE with complete instruction learnability (i.e., NICE =1) is proportional to the difference in performance of in-context example optimization and instructions. For instance, for NL2BASH and SST5, we see a slight dip in performance when using instruction, while the dip is significant for MTOP and Break.

heading: 5.4 RQ3: Do ground-truth labels matter?
text: In Fig. 4, we see that as we move to more detailed instructions, the difference in performance with
gold-labeled examples against randomly-labeled examples keeps on diminishing and ultimately becomes negligible for detailed task-specific instructions. This validates our hypothesis that for tasks with a high NICE, good instructions suffice and the dependence of the performance on examples is less and it reduces further with better instructions. (see 3.1 for the instruction templates). Thus, we see that a better instruction helps in reducing the model’s reliance on the in-context examples to understand input-label mapping. In the case of classification tasks, there is a drop in performance with the incorporation of a delusive instruction in the prompt; this drop is also an indicator of the model’s dependence on the instruction to understand a task.
Finally, on tasks with a low NICE (MTOP, Break and NL2BASH), we see a different trend in Fig. 4. While with no instructions we see a significant improvement in the performance (∼1.04x for MTOP and ∼1.25x for Break), the improvement from goldlabeled examples stays consistent with the addition of task definitions and the syntax rules of the task. Furthermore, the narrowing of the performance gap between gold and random labels for in-context examples can also be observed in these tasks, albeit at a slower rate compared to tasks with a high NICE. Consequently, the importance of optimizing in-context examples becomes more evident.

heading: 6 Discussion

heading: 6.1 Which tasks are sensitive to ICE choice?
text: Our results indicate that tasks that require the output to follow complex schema, such as MTOP, Break and NL2BASH, have a low NICE score. As a result, they are more sensitive to ICE optimization than other tasks. For example, in the MTOP dataset (shown in Fig. 11), the output format can vary depending on the query. Thus, LLMs may require carefully selected in-context examples tailored to specific queries to output the correct format.
To further explore the role of output schema in the sensitivity of a task to ICE, we present two ablation experiments where we vary the output schema complexity of tasks. For the tasks with a standard output format such as SST2 and SST5, we add a transformation that induces a novel schema/structure in the output. We find that the NICE score decreases significantly when the output has a nonstandard, complex structure. More details can be found in A.6.1. As another experiment, we use the GSM-8k (Cobbe et al., 2021) dataset. We consider two kinds of required output schema: 1) Final answer correctness: We only consider the last numerical value in the LLM’s response and compare against the ground-truth; 2) Reasoning format correctness: We use regular expressions to check if the model adheres to the reasoning syntax. Consistent with our hypothesis, we find that the second task (with complex output format) has a lower NICE score than the first task. Please refer to A.6.2 for the details and results of this experiment.

heading: 6.2 Key Takeaways
text: Through extensive experimentation, we found that for most tasks, except those with complex requirements on output format (which can be querydependent, see 6.1), optimizing in-context examples did not significantly impact performance once detailed instructions were provided. For simpler tasks, random ICE with detailed instructions performed as well as optimized ICE.
Tasks with complex output formats, such as Break, MTOP, NL2BASH (see Tab. 1, Fig. 2), SST2/SST5 (with induced schema) and GSM-8k (format-correctness) require ICE optimization (see Appendix A.6.1 and A.6.2). Our metric indicates the necessity of ICE optimization in these cases, as the NICE score is low. For these tasks, dynamically selecting ICE helps the LLM infer the specific output format expected for a query. Whereas for other
tasks like SST-2, SST-5, MNLI, MedQA, TREC, FinQA and GSM-8k (final answer-correctness) that do not have complex output formats, model performance is not sensitive to choice of ICE (or can be recovered with better instructions) and we see a high NICE score.

heading: 7 Conclusion
text: Our paper challenges the existing consensus that optimizing in-context examples (ICE) is universally beneficial. Through extensive experimentation on LLMs, we demonstrate that ICE optimization yields diminishing returns in the presence of task-specific instructions. We introduce a novel and efficient metric, NICE, to gauge the utility of optimizing ICE for a task. NICE measures the invariability of task performance with respect to the choice of ICE. This helps in efficient utilization of data and compute resources. A NICE score near 1 for a task implies minimal impact of ICE choice on model performance, allowing the use of static ICE that avoids query-dependent retrievals at inference time and improves computational efficiency. Thus for certain tasks, we show that a given LLM API budget may be more judiciously used to optimize the prompt instruction than to finetune available retriever models.
While we focus on using NICE to evaluate the effectiveness of ICE optimization for a task, the same can also be used to compare different instructions by optimizing a weighted sum of NICE scores (see more details in Appendix A.2.1). For simplicity, we use uniform weights in this work.

heading: 8 Limitations
text: We work with current state-of-the-art LLMs (GPT-4-Turbo, GPT-3.5-Turbo, Mixtral-8x7B-Instruct & Llama-2-70B-Chat) and the observations could differ with future models. Due to cost considerations, we do not compare more advanced learning-based methods for instruction and ICE optimization. While we do look at several tasks, we do not validate our hypotheses on completely new or open-ended generation tasks. Lastly, since training data for most models is not publicly available, data leakage from the training data corpus could possibly affects our findings.

heading: 9 Ethics Statement
text: We aim to advance the field of machine learning by improving our understanding of how universal large language models (LLMs) learn various tasks from instructions and prompts. We use proprietary models (GPT-4-Turbo, GPT-3.5-Turbo) accessed through OpenAI’s API endpoints and publicly available datasets from HuggingFace. Our work can help the scientific community evaluate new tasks and guide them toward building better prompts, which can have performance impacts while testing and deploying LLMs for downstream tasks. Like any other work advancing the field of machine learning, our work could also help understand and improve prompts for negative tasks, but we strongly discourage any negative usage extending from our work and LLMs.

heading: A Appendix

heading: A.1 Task-wise Instruction Sets

heading: A.1.1 Classification Tasks
text: In 3.1, we discuss the structured instruction sets we use. In this section, we give some concrete
examples. We also note that all of these instructions follow standard templates and none of them required human creativity. The total amount of time it took to create all of them for 9 datasets was under 1 hour. We show the instruction sets for SST2 and MTOP, and refer to our codebase for all other datasets.
Figs. 6, 7, 8, and 5 show the task definition (TD), TD with label space, TD with label meaning, and delusive instruction for SST-2.

heading: A.1.2 Generation Tasks
text: Fig. 9 and 10, we illustrate the task definition (TD) and TD with rules for MTOP:
The “No Instruction” case for both classification and generation tasks has an empty instruction appended by the examples. For instruction templates for all our classification and generation tasks, we refer the interested reader to our codebase.

heading: A.2 Proposition Proofs and Discussion on the NICE Metric
text: In this section we prove that the NICE metric defined in Section 4 indeed follows the propositions
in Section 4.1, and discuss some ways the NICE metric can be used for prompt optimization.
Proposition 1: Boundedness of NICE The NICE metric is bounded within (0,1], establishing a well-defined baseline to compare all tasks.
Proof: Since NICE is defined as the ratio of the expected score over all bins to the maximum amongst them, it can be expressed as:
NICE(D, I) = E 0<j≤|B| [S(j, I,D)]
max 0<j≤|B|
S(j, I,D)
The expectation of a bounded variable is itself bounded in (0,1], thus establishing the boundedness of NICE.
Proposition 2: Invariance to Linear Scaling NICE should be linearly invariant to the performance measure, ensuring independence from linear variations in model capability and task difficulty.
Proof: Consider the definition of NICE where performance (and thus the scores S) scale linearly with a factor k by linearity of expectation:
NICE(D, I) = E 0<j≤|B| k.S(j, I,D)
max 0<j≤|B|
k.S(j, I,D)
The linear invariance comes from the fact that scaling the performance measure YLM (x|(I + ei))

heading: 1. Identify the intent of the user from the utterance depending upon the domain.

heading: 5. Apply the same grammar rules in case of nested queries for the inner level.
text: by a constant factor will not affect the ratio, as both the numerator and denominator will be scaled equally. Thus, NICE remains invariant to linear scaling.
Proposition 3: Invariance to Bin Selection
If S(j, I,D) ≈ max j S(j, I,D) for all i, i.e., performance of the model is invariant to the bin from which the in-context examples are chosen, NICE → 1.
Proof: Since, there is an equal probability to sample examples from every bin,
E 0<j≤|B|
[S(j, I,D)] = ∑|B|
j=1 S(j, I,D) |B|
If the model’s performance is agnostic to the bin from which the ICE are picked, formally
∀j ∈ {1, ..., |B|}, S(j, I,D) ≈ max i S(j, I,D)
S(j, I,D) max
j S(j, I,D) ≈ 1
NICE = E 0<j≤|B| S(i, I,D)
max 0<j≤|B|
S(j, I,D) ≈ |B| |B| = 1
Proposition 4: Strict Retrieval Task Scenario Let bmax = argmaxj S(j, I,D) be the best bin. If, ∀ j ̸= bmax, S(j, I,D) ≪ S(bmax, I,D), representing a strictly retrieval task where the budget needs to be spent on in-context example optimization. In this scenario: NICE → 1/|B| and lim
|B|→∞ NICE = 0.
Proof: In this case, let the maximum score be denoted by,
m = S(bmax, I,D)
If for j ̸= bmax, S(j,I,D)m ≪ 1. Assuming that we have a finite number of bins, the metric in this case reduces to
NICE = E 0<j≤|B| S(i, I,D)
max 0<j≤|B|
S(j, I,D) ≈ m m.|B| = 1 |B|
Now, as the number of bins approaches infinity (for instance, in a scenario where examples are segregated based on their absolute distance from the query rather than percentile), the granularity of the partitioning becomes infinitely fine. Therefore,
lim |B|→∞ NICE = 0

heading: A.2.1 Discussion on the NICE Metric
text: We can define a partial order on the set of instructions as I ⪯ I ′ (in words, I is pareto-dominated by another instruction I ′) if S(j, I) ≤ S(j, I ′), ∀j. One can prove (under simple assumptions) that if there exists an I∗ that is not Pareto-dominated by any other I ′, then it must be a maximizer of∑
j wjS(j, I) for some non-negative weights wj’s (Harsanyi, 1955). The weights wj’s are typically uniform or chosen by domain experts (Harsanyi, 1955; Gale, 1960). For simplicity, we used uniform weights to define our metric.
The bin-wise scores can also be used for instruction/prompt optimization. One possible way is as follows: Start with an initial instruction that maximizes ∑ j S(j, I). Then, using weights
wj ∝ S(j, I), optimize ∑ j wjS(j, I) to find the
next instruction, and iterate. This is almost an alternating optimzation over instruction and examples (if not examples, the weights over different bins from which examples are chosen) that intuitively optimizes instructions for the examples (or bins) that matter more for the task at hand. An optimized instruction should pareto-dominate all other possible instructions. We leave this exploration and other uses of NICE for future work.

heading: A.3 Examples for the MTOP Dataset
text: We show some examples from the MTOP dataset in Fig. 11.

heading: A.4 NICE Results for Other Models
text: NICE-metric results for various datasets with and without instructions for GPT-3.5-Turbo are shown in Fig. 12 and for Mixtral-8x7B-v0.1 (an 8x7B mixture-of-experts model) and for Llama-2-70b-chat are shown in Figs. 13 and 14. We note similar observations as GPT-4-Turbo when using open-source language models.

heading: A.5 Pre-trained Models: Is Instruction-tuning the key?
text: While the results demonstrated in Figs. 2, 14, and 13 validate our hypotheses for instruction-tuned models, we see in Fig. 15 that they are valid for pre-trained models as well. Pre-training on nexttoken prediction enables models to learn a probability distribution pLM(x) over variable length sequences, thus allowing them to learn task-specific priors empowering them with zero-shot learnability, as was observed by (Choi et al., 2022). We see that even models not explicitly fine-tuned on
instruction-following exhibit the ability to learn from contexts.
We hypothesize that incorporating task-specific information containing label space information and other contextual cues provide substantial improvement for LLMs to predict the next tokens more accurately.
In Fig. 15, we show the results of the Llama-2-13B model on TREC (classification) and Break (generation) tasks. We see a partial paretodominance in case of semantic classification task like TREC (with high NICE) while it is not observed for the schema-based tasks like Break which has a low NICE.

heading: A.6 Additional Ablations and Results

heading: A.6.1 Task Transformations
text: For further exploration into the kinds of tasks where ICE optimization matters, we designed the following ablation experiment: for the tasks with a standard output format (such as SST), we performed a transformation to the output space to induce a novel and unseen schema/structure to the output. Specifically, we defined the following mapping for the labels:
• For SST2, we map:
– negative → negative – positive → POSITIVE
• For SST5, we map:
– very negative → very negative – negative → negative – neutral → NeUtRaL – positive → POSITIVE – very positive → VERY POSITIVE
Since the new output labels are non-standard, we hypothesize that it would help to include similar in-context examples in the prompt, which are likely to share the same label, thus ensuring that the model is aware of the new label format. The observations from this ablation further strengthen our hypothesis.
The NICE scores with and without instructions in each case are given in Tab. 2, and the original scores can be found in Tab. 1.
Quantitatively, we observe the following:
• A dip in the NICE score (corresponding to the No-Instructions case) as compared to standard datasets, thus showing the importance of learning the schema for model performance.
• This dip (showing the dependence of ICE choice) recovers in presence of detailed instructions (since these tasks are easy enough to be learned from detailed task-specific instructions).

heading: A.6.2 Correctness Metrics on GSM8k
text: We experiment with the GSM8k (Cobbe et al., 2021) task to study the role of ICE optimization for complex mathematical reasoning tasks. We make use of 4-shot examples in each case. An example output for this dataset looks like this: Natalia sold 48/2 = «48/2=24»24 clips
in May. Natalia sold 48+24 = «48+24=72»72 clips altogether in April and May. #### 72
We define two metrics to evaluate model outputs: Final Answer Correctness (FAC) We consider the last numerical value in the string response to compare against the ground-truth and do not penalize the model for the format. The NICE scores with respect to the FAC metric are high (0.91 with no instructions to 0.98 with detailed instructions), which means the task becomes almost invariant to choice of examples.
Reasoning Format Correctness (RFC): On the output string of the model, we use regular expressions to check if the model adheres to the reasoning syntax. In this case, we see that the NICE scores are 0.72 (for no instructions) and 0.74 (for detailed instructions), i.e., significantly lower than 0.91/0.98, indicating that ICE optimization matters a lot for learning the correct format. This is
consistent with our hypothesis about schema being the most important thing that is learned through examples.

heading: Future Work
text: We leave this exploration and other uses of NICE for future work