Skills-in-Context Prompting: Unlocking Compositionality in Large Language Models

Jiaao Chen, Xiaoman Pan, Dian Yu, Kaiqiang Song, Xiaoyang Wang, Dong Yu, Jianshu Chen · Submission to ICLR 2024 · Rejected

TL;DR

Large language models (LLMs) frequently stumble at compositional generalization—the ability to combine basic known skills to solve harder, longer problems. Skills-in-Context (SKiC) prompting solves this by explicitly defining modular sub-skills and demonstrating how to ground reasoning steps into them within a single prompt. Remarkably, this one-stage technique not only achieves near-perfect easy-to-hard generalization on algorithmic tasks, but also triggers models to retrieve and compose latent, pre-trained skills they were never explicitly taught in the prompt.

What Problem Does This Paper Address?

While modern LLMs excel at standard few-shot tasks, they consistently fail at "easy-to-hard" generalization. For instance, an LLM prompted with examples of adding 3-digit numbers will usually collapse when asked to add 7-digit numbers.

Previous approaches have notable shortcomings:

  • Chain-of-Thought (CoT) prompts step-by-step reasoning, but performance still degrades sharply on harder, out-of-distribution inputs.
  • Least-to-Most (LtM) and Decomposed Prompting (Decomp) require multi-stage execution pipelines: they split a query into sub-questions and call the LLM multiple times sequentially. This works well for linear problems, but breaks down on complex computation graphs (e.g., dynamic programming or multiplication) and suffers from cascading error propagation between stages.

The authors ask: Can we teach LLMs general compositional reasoning within a single, plug-and-play prompt?

Methods

The authors introduce Skills-in-Context (SKiC) prompting, inspired by the cognitive concept of elaborative rehearsal (linking new problem-solving tasks to an explicit scaffolding of prerequisite knowledge).

A SKiC prompt operates in a single stage and is structured into three blocks:

  1. Skill Scaffolding: A catalog of modular skills, each with an operational description and a few mini-examples (e.g., <extract_digits>, <add_two_single_digit_numbers>, <sub_10>).
  2. Compositional Exemplars: Few-shot demonstrations (often just two) showing how to solve a task by explicitly calling and chaining those named skills step-by-step (e.g., "Using Skill <extract_digits>, ... ").
  3. Target Problem: The complex or longer instance the model must solve.
+-----------------------------------------------------------------+
| 1. In-Context Skills                                            |
|    - Skill <words_to_list>: Convert string to list             |
|    - Skill <last_letter>: Extract final character               |
+-----------------------------------------------------------------+
| 2. Compositional Exemplar                                       |
|    "apple, banana" -> Step 1: Use <words_to_list> -> ['apple'..]|
|                       Step 2: Apply <last_letter> to each item  |
+-----------------------------------------------------------------+
| 3. Target Query                                                 |
|    "than, appropriate, sees, daisy, disturbed, espn..."         |
+-----------------------------------------------------------------+

Skills are acquired in one of two ways:

  • Manual Distillation: Human-curated for narrow, algorithmic tasks (e.g., string manipulation, arithmetic).
  • LLM-Prompted Distillation: For expansive domains like high school competition math, the LLM itself is prompted to outline foundational skills (e.g., "List basic skills in Algebra"), followed by human review.

Crucially, exemplars can also reference skills absent from the context block (e.g., <Pascal's Triangle>), which signals to the LLM that it is allowed to invoke internal pre-trained competencies.

Datasets

The authors evaluated SKiC across two distinct regimes on foundation models including LLaMA (65B, 70B, 70B-chat), text-davinci-003, ChatGPT, and GPT-4:

  1. Composition Over In-Context Skills (Easy-to-Hard Generalization):
  2. Last Letter Concatenation: Prompted on 1–2 words; tested on up to 12 words.
  3. Arithmetic: Addition (prompted on 2–3 digits; tested up to 7 digits) and Multiplication (prompted on 2–3 digits; tested on 4–5 digits).
  4. CommaQA-E: Multi-hop question answering over synthetic entities.
  5. Dynamic Programming (DP): Finding the maximum-sum non-adjacent subsequence (prompted on lengths 4–5; tested on lengths 6–8).
  6. Generalization Beyond In-Context Skills (Complex Mathematical Reasoning):
  7. GSM8K: Grade-school math word problems.
  8. MATH: Complex high-school math competition benchmark covering 7 subjects (Algebra, Geometry, Number Theory, etc.).

Key Insights and Ideas

  • Single-Stage Grounding Prevents Cascading Failures: Unlike multi-stage decomposition methods where an early sub-query error ruins the downstream answer, SKiC resolves everything in one generation window. Sub-tasks cross-reference each other, mitigating error propagation.
  • Activating Latent "Internal Skills": Demonstrating explicit skill composition triggers the LLM to reach into its pre-training weights. In the MATH benchmark, approximately 24% of the skills applied by GPT-4 were unlisted internal skills (e.g., Heron’s Formula, Angle Bisector Theorem).
  • Intra-Model Alignment Matters: When using ChatGPT to solve problems, prompting ChatGPT to define its own skills yielded better test accuracy (40.6%) and higher internal skill activation (14.9%) than feeding it higher-quality skills written by GPT-4 (38.9% accuracy, 12.5% activation). Self-generated skill taxonomies align better with a model's internal representations.

Key Results

SKiC dramatically outperformed standard prompting, Chain-of-Thought, and specialized decomposition baselines:

  • Algorithmic Extrapolation:
  • Last-letter concatenation (12 words): text-davinci-003 soared from 10.0% (standard 4-shot) and 31.0% (CoT) to 98.0% with SKiC. ChatGPT achieved 100.0%.
  • 7-digit addition: text-davinci-003 achieved 98.5% with SKiC (vs. 38.0% for CoT).
  • 5-digit multiplication: ChatGPT reached 48.5% (vs. 2.0% for CoT).
  • Dynamic Programming (length 8): GPT-4 hit 98.0% (vs. 72.0% for CoT); ChatGPT scored 92.0% (vs. 55.5% for CoT).
  • Reading Comprehension (CommaQA-E):
  • On the out-of-distribution compositional split, ChatGPT reached 80.8% Exact Match, outperforming Decomposed Prompting (73.5%) and CoT (46.4%).
  • Advanced Math (MATH Benchmark):
  • In a single pass, SKiC achieved 40.6% on ChatGPT (outperforming ComplexCoT's 34.1% and the multi-round PHP ensemble's 36.5%).
  • On GPT-4, SKiC achieved 56.4% overall accuracy, beating ComplexCoT (50.3%) and multi-round PHP (53.9%).

Limitations and Future Work

Through error analysis on 50 failure cases across four challenging tasks, the authors observed:

  1. Missing Foundational Skills: The leading cause of failure was the absence of a required sub-skill in both the prompt and model weights (e.g., 83% of multiplication errors occurred because the model lacked a robust skill to add multiple large numbers).
  2. Context Window & Copy Errors: On very long reasoning chains, models occasionally made typographical copying errors when carrying numbers across intermediate steps.
  3. Compositional Mistakes: In tasks requiring creative strategies (like GSM8K and MATH), misinterpreting the problem or picking the wrong combination of skills accounted for 36–45% of failures.

Future avenues include expanding automatic skill retrieval via external memory/RAG, improving skill-scaffolding quality, and pairing SKiC with longer-context LLMs.

Summary updated

BibTeX
@misc{chen2023skills,
  author = {Jiaao Chen and Xiaoman Pan and Dian Yu and Kaiqiang Song and Xiaoyang Wang and Dong Yu and Jianshu Chen},
  title = {{Skills-in-Context Prompting: Unlocking Compositionality in Large Language Models}},
  year = {2023},
  eprint = {2308.00304},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.00304},
}
Figure