Text to FigureText → Imageinfographic

How to Build Toolformer: Tool-Use Training Pipeline

Illustration of how to build Toolformer. (Image source: Schick et al. 2023 ).

Paper context

Paper title: Prompt Engineering | Lil'Log Abstract: The figure illustrates the three-step pipeline for augmenting an LM dataset with API calls in the Toolformer model: sampling, executing, and filtering. Source body: Table of Contents Basic Prompting Zero-Shot Few-shot Tips for Example Selection Tips for Example Ordering Instruction Prompting Self-Consistency Sampling Chain-of-Thought (CoT) Types of CoT prompts Tips and Extensions Automatic Prompt Design Augmented Language Models Retrieval Programming Language External APIs Citation Useful Resources References Prompt Engineering , also known as In-Context Prompting , refers to methods for how to communicate with LLM to steer its behavior for desired outcomes without updating the model weights. It is an empirical science and the effect of prompt engineering methods can vary a lot among models, thus requiring heavy experimentation and heuristics. This post only focuses on prompt engineering for autoregressive language models, so nothing with Cloze tests, image generation or multimodality models. At its core, the goal of prompt engineering is about alignment and model steerability. Check my previous post on controllable text generation. [My personal spicy take] In my opinion, some prompt engineering papers are not worthy 8 pages long, since those tricks can be explained in one or a few sentences and the rest is all about benchmarking. An easy-to-use and shared benchmark infrastructure should be more beneficial to the community. Iterative prompting or external tool use would not be trivial to set up. Also non-trivial to align the whole research community to adopt it. Basic Prompting # Zero-shot and few-shot learning are two most basic approaches for prompting the model, pioneered by many LLM papers and commonly used for benchmarking LLM performance. Zero-Shot # Zero-shot learning is to simply feed the task text to the model and ask for results. (All the sentiment analysis examples are from SST-2) Text: i'll bet the video game is a lot more fun than the film. Sentiment: Few-shot # Few-shot learning presents a set of high-quality demonstrations, each consisting of both input and desired output, on the target task. As the model first sees good examples, it can better understand human intention and criteria for what kinds of answers are wanted. Therefore, few-shot learning often leads to better performance than zero-shot. However, it comes at the cost of more token consumption and may hit the context length limit when input and output text are long. Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place. Sentiment: positive Text: despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults. Sentiment: negative Text: for the first time in years, de niro digs deep emotionally, perhaps because he's been stirred by the powerful work of his co-stars. Sentiment: positive Text: i'll bet the video game is a lot more fun than the film. Sentiment: Many studies looked into how to construct in-context examples to maximize the performance and observed that choice of prompt format, training examples, and the order of the examples can lead to dramatically different performance , from near random guess to near SoTA. Zhao et al. (2021) investigated the case of few-shot classification and proposed that several biases with LLM (they use GPT-3 in the experiments) contribute to such high variance: (1) Majority label bias exists if distribution of labels among the examples is unbalanced; (2) Recency bias refers to the tendency where the model may repeat the label at the end; (3) Common token bias indicates that LLM tends to produce common tokens more often than rare tokens. To conquer such bias, they proposed a method to calibrate the label probabilities output by the model to be uniform when the input string is N/A . Tips for Example Selection # Choose examples that are semantically similar to the test example using $k$-NN clustering in the embedding space ( Liu et al., 2021 ) To select a diverse and representative set of examples, Su et al. (2022) proposed to use a graph-based approach: (1) First, construct a directed graph $G=(V, E)$ based on the embedding (e.g. by SBERT or other embedding models ) cosine similarity between samples, where each node points to its $k$ nearest neighbors; (2) Start with a set of selected samples $\mathcal{L}=\emptyset$ and a set of remaining samples $\mathcal{U}$. Each sample $u \in \mathcal{U}$ is scored by $$ \text{score}(u) = \sum_{v \in \{v \mid (u, v) \in E, v\in \mathcal{U}\}} s(v)\quad\text{where }s(v)=\rho^{- \vert \{\ell \in \mathcal{L} \vert (v, \ell)\in E \}\vert},\quad\rho > 1 $$ such that $s(v)$ is low if many of $v$’s neighbors are selected and thus the scoring encourages to pick diverse samples. Rubin et al. (2022) proposed to train embeddings via contrastive learning specific to one training dataset for in-context learning sample selection. Given each training pair $(x, y)$, the quality of one example $e_i$ (formatted input-output pair) can be measured by a conditioned probability assigned by LM: $\text{score}(e_i) = P_\text{LM}(y \mid e_i, x)$. We can identify other examples with top-$k$ and bottom-$k$ scores as positive and negative sets of candidates for every training pair and use that for contrastive learning. Some researchers tried Q-Learning to do sample selection. ( Zhang et al. 2022 ) Motivated by uncertainty-based active learning , Diao et al. (2023) suggested to identify examples with high disagreement or entropy among multiple sampling trials. Then annotate these examples to be used in few-shot prompts. Tips for Example Ordering # A general suggestion is to keep the selection of examples diverse, relevant to the test sample and in random order to avoid majority label bias and recency bias. Increasing model sizes or including more training examples does not reduce variance among different permutations of in-context examples.

The prompt

Above I've shared:
(1) the full blog body,
(2) the caption for the infographic I want.

TASK: Render an INFOGRAPHIC for a tech-explainer blog (Lil'Log / Distill /
HuggingFace blog style). **NOT** an academic-paper figure.

Style requirements:

  - Magazine-quality, colourful, illustrated. Use icons, metaphors,
    visual analogies — not just labelled boxes.
  - Coherent palette of 3-5 colours; consistent typography.
  - Vertical or wide layout (not square academic format).
  - Information-dense in a NARRATIVE flow (top-to-bottom or left-to-right
    reading order); NOT a single static diagram.
  - Audience: a curious general ML reader who wants to understand the
    concept, not a researcher needing to verify the method.

If your output looks like a clean academic figure (black-on-white,
labelled boxes, no decoration), you've missed the task. Render an
educational infographic. Just give me the final image.

Try this prompt now

Open it inside the generator with the prompt pre-filled.

Try this prompt

Related prompts