Concepts / Effective Data Preparation for AI Models

Effective Data Preparation for AI Models

Inspecting a raw dataset comes before training and aims to judge its quality and to reveal how its contents are distributed.

  • Programming

Why Look Before Training

Imagine you have collected a large pile of examples for teaching a model. Some came from public sources, some were written in-house, and some were labeled by people you have never met. Before any of it reaches a training run, you need an honest answer to a simple question: what is actually in this data? A model learns whatever patterns the examples contain, including the bad ones, so an unexamined dataset can quietly steer the model in directions you never intended.

What do you think happens?

What do you think happens to the bad patterns in an unexamined dataset during training?

Reveal answer
Answer:

The model learns them, because a model learns whatever patterns the examples contain, including the bad ones.

Training does not check whether a pattern is desirable. It absorbs the patterns that are present, which is why inspection has to happen first.

This article covers the first stage of data preparation: inspecting a dataset to judge its quality and to learn how its contents are spread out. Inspection does not change the data. It produces understanding, and that understanding decides what you keep, what you fix, and what you remove later.

Where Inspection Sits in the Pipeline

Inspection is a stage that sits between raw collection and training or tuning. Follow one dataset through the process and notice what each stage hands to the next. The raw collection enters first. Its origins are then checked, its distributions are measured, those distributions are sliced to look for skew, annotations are checked for disagreement, and only then do you decide what to change.

Raw collectionexamples from severalsourcesProvenance checkorigin, processing, prioruseMeasure distributionstokens, lengths, specialtokens, coverageSlice distributionsby source, time, annotatorCheck disagreementconflicting annotatorlabelsDecide keep, fix,removedocumented decisionsTraining or tuningthe inspected datasetoriginsprocessed dataoverall shapesubgroup findingsconflict reviewsrevised dataset
What flows from each stage into the next, and where inspection sits between raw collection and training

The earliest questions are about provenance, not statistics. Where did each part of the dataset originate? How was it processed along the way, for example by cleaning, filtering, or reformatting? Was it ever used for some other purpose before it arrived at your project? Each answer changes what the numbers mean. Two datasets with identical word counts can behave very differently if one was scraped and the other was written by specialists under a careful protocol.

Measuring What Is in the Data

Once you know the origins, you can measure the dataset. A distribution tells you how often each value of some property appears, or how a numeric property is spread across the examples. The source suggests several starting properties. Token frequency shows which tokens are common, which in turn reveals the vocabulary the data really relies on. Input length and response length show how big the examples are. You can also ask whether the data contains any special tokens, and whether the topics and languages present are spread across the examples in a way that matches your task.

Each of these properties belongs to a family of checks. Token frequency and special tokens describe the vocabulary and format of the text. Input and response lengths describe the size of the examples. Topic and language coverage describes relevance, that is, whether the content matches what the application will actually see. Keeping these families separate helps you decide which check answers which question.

Worked example

Reading a length distribution

A small dataset has five examples, and each has a response length in words: 12, 15, 9, 180, and 14. Find the average response length, then describe what the average tells you about the data.

  1. 1
    Compute the mean

    Add the lengths: 12 + 15 + 9 + 180 + 14 = 230. Divide by 5 examples to get a mean of 46 words.

  2. 2
    Look at the values

    Four of the five responses are between 9 and 15 words. One response is 180 words, far above the rest.

  3. 3
    Compare the mean with the typical value

    The middle value of the sorted lengths (9, 12, 14, 15, 180) is 14 words. The mean of 46 is pulled upward by the single long response, so it describes none of the typical examples well.

  4. 4
    Ask what the outlier is

    The 180-word response could be a valuable example, an error, or a sign of something systematic. Deciding which one requires reading that example.

Result

The overall average of 46 words looks like a typical response length, but four of five responses are short. The single long example hides the real shape of the data, which is why the distribution should be inspected rather than summarized by one number.

The last question is a relevance question, and it is easy to skip. A dataset can be large and varied yet still be mostly about topics your application will never encounter. Measuring the topic and language distribution lets you compare what the data covers against what the task needs.

Choosing a Statistic That Answers a Question

The statistics you choose are not limited to the obvious ones. The source describes a study by a group of Microsoft researchers from 2023 that examined the same set of instructions answered by two different models, GPT-3 and GPT-4. They measured the distribution of verb, direct object, and noun combinations in the responses, and they also measured response length. The pattern that emerged was that GPT-4 showed a broader and more varied range of verb-noun pairings and tended to produce longer responses.

The same technique that exposes differences between two generators can be turned on a dataset, because it reveals what kinds of language a set of examples actually contains. The source notes that this kind of analysis helps evaluate models as well as data. The lesson is that a useful statistic is one that matches a question you care about. Choose the measurement first, then let the question decide it.

Question you are askingStatistic to measureWhat it reveals
Is the phrasing varied enough?Distribution of verb, object, and noun combinationsThe range of language patterns in the examples
Are the responses too verbose?Distribution of response lengthsHow big the responses are and where they cluster
Does the data match the application?Topic and language coverageWhether the content is relevant to the task
Which vocabulary does the data rely on?Token frequencyThe tokens that dominate the examples

Matching a statistic to a question (generated illustration of the lesson's principle)

Slicing a Distribution to Find Hidden Skew

A single overall distribution can look healthy while hiding real problems. The practice is to plot the same distributions again after splitting the data by source, by time, or by annotator. A slice that behaves differently from the rest deserves investigation. The diagram below compares the pooled view with a per-source view of the same response lengths from the earlier example. The pooled view reports a single average, while the per-source view shows where the long responses actually come from.

All examplesmean 46 wordsSource A9 to 15 wordsSource B180 wordssplit by sourcesplit by source
How the same response lengths look overall and when split by source; the slice that differs from the rest is the one to investigate

The source gives a clear reading rule. If one data source consistently produces very short responses, that is a finding about the source, not about the examples in general. Slicing can also answer more pointed questions. Do certain kinds of questions tend to receive longer or shorter responses? Do some kinds receive higher or lower scores? If the scores are supposed to follow a normal distribution, a fair test is to check whether the scores from each annotator follow that shape, rather than only checking the pooled scores.

Outliers need the same care. An extreme value can be a real and valuable example, an error, or a sign of something systematic. The source asks three questions in sequence: are there outliers, what might cause them, and what should be done with them. Answering the middle question usually requires looking at the examples themselves, which is a point the next section returns to.

Following Inter-Annotator Disagreement

Many datasets give the same example to more than one annotator. When that happens, you can compute inter-annotator disagreement, which measures how often the annotators' labels conflict. The source recommends this check directly: if each example has more than one annotation, compute the disagreement, then examine the examples where annotations conflict and resolve those conflicts. The flowchart below traces one item through that process, including the path taken when labels do not disagree.

Example withseveral labelssame example, multipleannotatorsCompute disagreementhow often labels conflictLabels conflict?Accept agreed labelIdentify the causeambiguous instruction,misunderstanding, hardexampleResolve with adocumented reasonkeep a label or revise theexampleExamine conflictingexamplesread the examplesthemselvesannotationsdisagreement scorenoyesreviewdecide
The path an example takes from several annotator labels through the disagreement check; when labels agree, the example is accepted, and when they conflict, the conflict is examined and resolved

Disagreement is information, not just noise to be deleted. Sometimes it signals an ambiguous instruction, sometimes an annotator who misunderstood the task, and sometimes a genuinely hard example where reasonable people differ. Resolving a conflict means deciding, for a documented reason, which label stands or how the example should be revised. Deleting the conflicting example without this review throws away the evidence that the task itself may need clearer wording.

Why Reading Examples Still Matters

Automated tools can compute distributions and flag disagreement quickly, but the source is clear that they do not replace manual inspection. Each method catches things the other can miss. A distribution can show that one source produces short responses, but only reading the examples shows whether the short responses are unhelpful, or whether they are exactly what the task asks for. Automated slicing finds where to look; reading tells you what you are looking at.

The author reports that spending about fifteen minutes reading a dataset directly has often revealed something that saved hours of later troubleshooting. A quote from an OpenAI co-founder, Greg Brockman, makes the same point, describing manual inspection of data as having probably the highest value relative to its prestige of any activity in machine learning.

Mistakes When Inspecting Data

  • Common mistake

    Trusting a single overall average

    What it looks like

    A mean response length of 46 words looks typical even though four of five responses are between 9 and 15 words.

    Why it fails

    One pooled number can hide a skewed subgroup or an outlier.

    Do this instead

    Plot the distribution again after slicing by source, time, or annotator.

  • Common mistake

    Deleting outliers without asking why they exist

    Why it fails

    An extreme value may be a valuable example, an error, or a sign of a systematic problem, and removing it skips the question entirely.

    Do this instead

    Ask what might cause the outlier, usually by reading the example, before deciding what to do with it.

  • Common mistake

    Treating disagreement as noise to delete

    Why it fails

    Conflicting labels can point to an ambiguous instruction, an annotator who misunderstood the task, or a hard example.

    Do this instead

    Examine each conflicting example and resolve it deliberately, recording the reason.

  • Common mistake

    Choosing a statistic before deciding the question

    Why it fails

    A statistic that does not match your concern produces numbers that do not answer it.

    Do this instead

    Decide whether the concern is variety, verbosity, or relevance, then pick the matching measurement.

  • Common mistake

    Assuming an annotator's tendency makes their labels wrong

    Why it fails

    Short responses or higher scores from one annotator do not automatically make the annotations incorrect.

    Do this instead

    Treat the tendency as a decision you make deliberately about how those annotations are used.

Practice: Find the Skewed Slice

MEDIUM

Two annotators labeled the same kind of task. Annotator A's response lengths in words are 10, 12, 11, and 9. Annotator B's response lengths are 60, 75, 58, and 70. Which annotator's behavior should you investigate first, and what check would you run before deciding how to treat their annotations?

Hints
  • Compare the two slices separately rather than only looking at the pooled set of eight lengths.
  • The source says annotators sometimes write much shorter or longer responses, and that this is a tendency to be decided deliberately, not an automatic error.
  • Consider reading a few examples from each annotator before deciding how the difference should be handled.

Key Takeaways

  • Inspect a raw dataset before training or tuning, starting with provenance and then measuring its distributions, because a model learns whatever patterns the examples contain.
  • Choose statistics to match your question: token frequency, input and response lengths, special tokens, and topic or language coverage each answer a different question.
  • Slice distributions by source, time, or annotator to reveal outliers, skewed subgroups, and annotator bias that a pooled view can hide.
  • Compute inter-annotator disagreement when examples have several labels, then examine and resolve each conflict for a documented reason.
  • Combine automated exploration with manual reading of examples, since reading is what tells you what a flagged slice actually means.

Related concepts

More concepts starting with E