Resources/Model training/Data preparation

Pipeline step

Cleaning

Cleaning removes the replies a model should never learn from — errors, refusals, interface markup, duplicates and canned answers — and fixes the structure so every record is valid for training.

Chapter 54 min read4 references

What it is

Real chat logs are messy. Next to the answers you want the model to copy, they contain error messages, refusals from a safety layer, markup that only the chat interface understands, replies that just say a file is ready, and the same conversation saved twice. Cleaning is the first step of data preparation: it removes or repairs those records before anything is converted into a training file.

It matters because fine-tuning has no notion of a “bad example”. Every target reply that reaches the training file is treated as the right answer, and the model is pushed to make it more likely. One error message used as a target ten times teaches the model that error messages are a normal reply.

How it works

Each step looks for one specific pattern, and each has a reason grounded in how training works. Some steps remove a target reply (it stays readable as context, it just isn't graded); others remove a whole record or rewrite its structure.

StepWhat it catchesWhy it would hurt training
UI markupTags the chat interface uses to render buttons, collapsible panels and similarA model used outside that interface would print raw tags in its answers
Error replies“Error processing query…” and similar system failuresThe model would learn to fail on purpose
Guardrail blocksRefusals inserted by a platform safety layer, not written by the modelTeaches refusals for questions that were fine to answer
File announcementsShort replies whose real output was a generated file, e.g. “Your deck is ready”The file is not in the text, so the model learns to claim work it did not do
StructureA conversation that opens with the assistant; two messages in a row from the same roleTraining formats require alternating user and assistant turns, starting with the user
DuplicatesThe same conversation with the same answer, saved or imported twiceCounts one example twice: more weight, more memorisation, no new information
Repeated repliesOne identical reply used as a target many times, such as a greeting or a canned disclaimerA few stock phrases would dominate and the model would reach for them everywhere
Targets before cleaning1,850
Error replies−38
Guardrail blocks−12
File announcements−27
Duplicate conversations−64
Repeated replies, capped−41
Targets that train1,668
An illustrative cleaning pass over 1,850 target replies. Each step removes a small share, but together they take out about one target in ten — and these are exactly the replies that would have taught the model the wrong thing.

Duplicates deserve special attention. Research on large training sets found that repeated text is a major driver of memorisation: Lee et al. (2021) showed that deduplicating training data made models emit memorised text ten times less often, and Carlini et al. (2022) found that how often a sequence is duplicated is one of the strongest predictors of whether a model will repeat it word for word. A fine-tuning set is far smaller, so a single conversation repeated five times is a large share of what the model sees.

The capped repeated replies step is softer than deduplication. A short, identical reply like “Happy to help — anything else?” may be perfectly good, so it is kept up to a limit and only the excess copies stop being targets. The model still learns the phrase, without learning to say it to everything.

Worked example: 1,850 targets in, about 1,670 out
  1. A support team picks 1,000 conversations containing 1,850 assistant replies marked as targets.
  2. 38 targets are error replies from a service outage week and 12 are guardrail refusals. All 50 stop being targets.
  3. 27 targets are “Your report is ready” messages whose real output was a PDF. Removed: the text alone cannot teach the model to produce a PDF.
  4. 64 targets sit in conversations that were imported twice. One copy of each is kept.
  5. The sign-off “Is there anything else I can help with?” appears as a target 71 times. With a cap of, say, 30, 41 copies stop being targets.
  6. 1,668 targets remain, about 90%. Training costs slightly less, and the 10% removed were the replies most likely to make the model worse.

When it matters

  • Always for logs from a live product. Outages, safety layers and interface features all leave traces that look like replies.
  • More for small datasets. With 200 targets, ten bad ones are 5% of the signal; with 20,000 they are noise.
  • Imported chats. Exports from other tools often contain repeated or partially overlapping conversations.
  • When the model will run outside the chat interface. That is when UI markup must go; keep it only if the model will be used in the same interface that renders it.
Keep interface markupTypical Off#

Off by default. Turn it on only if the trained model will answer inside the same chat interface that understands those tags, and you want it to keep producing buttons and collapsible sections.

Common mistakes

  • Assuming a large dataset makes cleaning unnecessary: duplicates and canned replies grow with the dataset.
  • Training on “Your file is ready” replies and then wondering why the model claims to have created files it never produced.
  • Keeping interface markup for a model that will run in another product, where the tags show up as raw text.
  • Fixing symptoms in every prep instead of the source: if many replies are errors or refusals, the underlying chats or product flow need attention.
  • Deduplicating by message instead of by conversation, which can leave a reply without the question that explains it.

References and further reading

External sources open in a new tab.

  1. 01Deduplicating Training Data Makes Language Models BetterLee et al., 2021 · arXiv · arxiv.orgShows how much repeated text there is in real datasets and how removing it reduces memorisation.
  2. 02Quantifying Memorization Across Neural Language ModelsCarlini et al., 2022 · arXiv · arxiv.orgMemorisation grows with model size, with how often an example is duplicated and with prompt length.
  3. 03LIMA: Less Is More for AlignmentZhou et al., 2023 · arXiv · arxiv.org1,000 carefully curated examples were enough for strong results: quality over quantity.
  4. 04Supervised fine-tuningOpenAI API docs · developers.openai.comA provider's view of what a training example should contain.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.