liveBook · Manning

Fine-tuning

As explained in Data Storytelling with Altair and AI

Fine-tuning is the additional training of a pretrained machine-learning model on targeted data to adapt its parameters to a task or domain.

Fine-tuning adapts a pretrained large language model (LLM) to a domain or task by training it further on a smaller, targeted dataset. Each training sample supplies a prompt and an intended completion, allowing the model to learn a particular style of response. For data storytelling, this can make generated titles, annotations, and commentaries more consistent with an audience and scenario. section 7.4.1 section 7.6

Use fine-tuning when a general-purpose model needs domain-specific behavior or knowledge. A separate dataset can target the general public, professionals, executives, particular products or topics, or a specific output type. Greater dataset specificity is presented as a route to better results. When the goal is instead to summarize a long document using external information, retrieval augmented generation (RAG) is the alternative: it combines retrieval with generation rather than retraining the model. section 7.4 section 7.4.1

Figure 7.10 A criterion to establish whether to extend an LLM or not
figure

Use the decision criterion to decide whether an LLM must be extended with domain-specific information before generating a data-driven story. section 7.4

A practical fine-tuning workflow is:

  • Define the desired behavior and assemble relevant prompt–completion pairs. Manual pairs offer direct control over the behavior expected for a given input. section 7.4.1
  • Shape the examples for the intended audience and output. For example, prepare distinct data for public-facing, professional, or decision-maker commentary. section 7.4.1
  • Convert the data to JSONL messages containing system, user, and assistant roles, then upload the file and create a fine-tuning job through the OpenAI API. section 7.4.1
  • Wait for processing and job completion, retain the resulting model identifier, and use that identifier when requesting new generated text. section 7.4.1

Training commentary for a general audience

A training example frames the model as a data analyst communicating with the general public. Given household-chore percentages—cooking 35%, cleaning 30%, laundry 20%, and yard work 15%—the intended completion identifies cooking as the largest share and states the remaining values plainly. After fine-tuning, a request about rowing (62%) and cycling (58%) produces a concise commentary naming them as the most popular sports. section 7.4.1

Listing 7.1 The structure of a JSONL file
{
  "messages": [
     {
    "role": "system",
  "content": "You are a data analyst showing data to the general public."
     },
     {
         "role": "user",
         "content": "Distribution of household chores 
                                  (Cooking 35% Cleaning 30% Laundry 20%, Yard work 15%)"
     },
     {
          "role": "assistant",
           "content": "Cooking takes up the largest portion at 35%. 
                      Cleaning follows at 30% while laundry 
                      and yard work accounts for 20% and 15% respectively."

     }
  ]
}

Inspect the JSONL message structure used to turn a system instruction, data prompt, and desired commentary into one training sample. section 7.4.1

Dataset preparation is the main effort. Fine-tuning is most useful when repeated outputs should follow a familiar structure for the same audience; it is not necessary when a general ChatGPT response is sufficient. Treat it as one way to add textual context that helps turn chart information into audience-appropriate knowledge. section 7.4.1 section 7.4 section 7.6

How Data Storytelling with Altair and AI covers it

How deep it goes
Defines targeted retraining and walks through dataset construction, JSONL conversion, API job creation, and generation without explaining LLM internals.
Examples
Demonstrates audience-specific titles and commentary using household chores and popular-sports percentages, plus CSV-to-JSONL conversion.
What it assumes
Assumes a pretrained LLM and introduces prompt–completion datasets, JSONL formatting, and API-based fine-tuning from examples.
What you can do after
Apply it via the OpenAI API to train and call an audience-specific model for new data commentary.
How it connects
Contrasts fine-tuning with retrieval augmented generation, and connects it to prompt–completion pairs, textual context, and data storytelling.

Also explained in

Compare how 37 books explain fine-tuning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.