liveBook · Manning

Alpaca dataset

As explained in Build a Large Language Model (From Scratch)

A dataset of instruction-style input-output examples used to adapt a language model to follow natural-language instructions.

An instruction dataset contains explicit instruction–input–output pairs for adapting a pretrained GPT-style language model to follow human requests. It connects supervised examples to chatbot, assistant, and conversational behavior. section 7.0 section 7.2

Figure 7.1 The three main stages of coding an LLM. This chapter focuses on step 9 of stage 3: fine-tuning a pretrained LLM to follow human instructions.
figure

Use the fine-tuning pipeline figure to place instruction-dataset preparation between pretrained-model loading and instruction fine-tuning. section 7.0

Prepare the dataset as a model-ready data flow:

  • Download a human-readable JSON file containing 1,100 dictionary entries with instruction, input, and output fields; the input may be empty. section 7.2
  • Convert each entry into a prompt format, such as Alpaca’s labeled instruction, optional input, and response structure; Phi-3 provides an alternative style. section 7.2
  • Partition the entries into training, validation, and test sets using 85%, 5%, and 10% slices, yielding 935, 55, and 110 examples. section 7.2
  • Batch formatted examples with a custom collate function that pads sequences, creates target token IDs, masks padding tokens, truncates to 1,024 tokens, and transfers tensors to the selected device. section 7.10 section 7.4

Worked formatted entry

The instruction “Identify the correct spelling of the following word.” with input “Ocassion” becomes a labeled prompt whose response is “The correct spelling is 'Occasion.'” An entry asking for an antonym can omit the input field. section 7.2

PyTorch data loaders shuffle training batches and preserve validation and test batches for evaluation. The resulting input and target tensors share sequence shapes, while variable prompt lengths produce batches such as 8×61, 8×76, and 8×73. section 7.4

The prepared dataset fine-tunes a pretrained GPT-2 model through a familiar loss-based training loop. Training and validation losses are monitored across two epochs, and generated test responses can be scored with another language model. section 7.6 section 7.10

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Explains JSON structure, prompt formatting, dataset splits, collation, tensor shapes, loaders, training, and response evaluation.
Examples
Uses spelling correction, antonym identification, passive-voice conversion, Alpaca prompts, Phi-3 prompts, JSON entries, and tensor batches.
What it assumes
Assumes pretrained-model and training-loop familiarity while teaching instruction formatting, dataset partitioning, padding, masking, and batching.
What you can do after
Build it from scratch: download, format, split, batch, load, fine-tune, and evaluate an instruction-following GPT model.
How it connects
Connects supervised learning with GPT, transformers, tokenization, PyTorch DataLoader, prompt formatting, and model evaluation.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.