Concepts / Privacy and Safety in Training Data

Privacy and Safety in Training Data

Raw scraped data often contains formatting tokens such as HTML and Markdown, and removing them can improve accuracy while cutting input length.

  • Programming

What the Model Absorbs From Its Data

A model learns whatever patterns are present in the examples it receives. If those examples contain stray markup, content the model should never use, or records that are simply poor, the model absorbs those problems along with everything useful. This is the reason the people preparing data must decide, before training starts, what stays, what goes, and what might be worth keeping in a smaller form.

What do you think happens?

A scraped web page contains HTML tags such as bold markers and page structure. Should those tags be left in the training text so the model sees them?

  • Yes, the model should always see every character it was given

  • No, unless the goal is to teach the model to read those tags, they are noise

Reveal answer
Answer:

No, unless the goal is to teach the model to read those tags, they are noise.

Text pulled from web pages is written in markup languages, so it often arrives wrapped in tags for page structure, styling hints, or links. Those tags do not carry the content the project wants the model to learn, so the first cleaning task is usually to remove them.

Stripping Formatting Tokens From Raw Text

Many public datasets are assembled by collecting text from across the internet. Because web pages are written in markup languages, text pulled from them often carries HTML and Markdown markup inside the text itself. The source describes these formatting tokens as extraneous. Unless the goal is to teach a model to read those tags, they are noise, and removing them is the first cleaning step.

The source summary makes a practical claim about this step: removing formatting tokens can improve accuracy while also cutting the length of the input. Both effects come from the same action. Fewer meaningless characters means less text for the model to process, and the remaining text is closer to the content the project actually cares about.

Before
<p>Great <b>results</b> on the [test set](http://example.com)</p>

Raw record with HTML tags and a Markdown link wrapped around the words

After

Great results on the test set

Cleaned record that keeps only the readable words

Worked example

Cleaning one scraped record

A scraped record contains a paragraph tag, a bold tag, and a Markdown link. Show how the cleaning step handles it.

  1. 1
    Identify the formatting tokens

    The paragraph tag and the bold tag are HTML markup. The square brackets and parentheses around the link text form Markdown link syntax. None of these tokens are the content the model should learn from.

  2. 2
    Remove the tokens and keep the words

    Removing the tags and link syntax leaves the readable words Great results on the test set. The meaning of the sentence is preserved while the markup disappears.

  3. 3
    Check the shorter result

    The cleaned record is much shorter than the raw record, which matches the source's point that removing formatting tokens cuts input length.

Result

The record now contains only the text the model should learn from, and it is shorter than the original.

Enforcing Project Policies on Records and Fields

Cleaning also means enforcing rules. Data has to be checked against the policies that govern the project, and anything that does not comply must be removed. The source names several categories that fall under this heading: personally identifiable information (PII), sensitive data, copyrighted material, and content considered toxic. The techniques for handling those categories are covered in an earlier chapter on privacy and safety, so this article focuses on the filtering step itself.

Not every violation requires discarding a whole record. A dataset may contain columns that the project is not permitted to use, such as a zip code, a name, or a gender value. Those fields should be dropped before the model sees the data, even when the rest of the record is perfectly usable.

Finding Low-Quality Records

After compliance cleaning, the data may still contain records that are poor in quality even though they are allowed and properly formatted. The source describes a method for finding them that combines two activities. The first is looking closely at the data by hand. The second is turning what was noticed into rules that can be applied across the whole collection.

Manual inspection reveals patterns. When a person repeatedly sees the same kind of weak record, that pattern can become a heuristic, which is a rule that flags similar records automatically. The source also notes that some heuristics depend on context, such as the position of a record within an annotation session. A rule like this cannot be read off the record alone, which is one reason heuristics need to be checked against what a person actually observed.

AspectHeuristicsManual inspection
How it worksA rule written to flag a pattern across the collectionA person looks closely at the data by hand
Where it appliesAcross the whole collection once the rule existsOn the records a person actually reads
OriginOften built from patterns that manual inspection revealedThe starting point for discovering patterns
Context sensitivitySome rules depend on context, such as position in an annotation sessionA person can notice context that a simple rule might miss

Heuristics and manual inspection work together to find low-quality records.

Following a Record Through the Cleaning Pipeline

The steps described so far are not independent choices. They form a sequence in which each stage hands a smaller and cleaner collection to the next. Follow one raw record through that sequence. First its formatting tokens are stripped. Then it is checked against project policies, and any non-compliant record or field is removed. Next manual inspection and heuristics look for low-quality patterns. Finally, if the project has more data than it can use, an optional pruning stage selects a subset before training.

Raw scraped dataStrip formattingtokensCompliance checkPII, sensitive, copyright,toxicManual inspectionspot low-quality patternsHeuristic rulesapplied across thecollectionOptional pruningactive learning orimportance samplingTraining setDropped recordsnon-compliant or lowqualitynextnextnon-compliantcompliantpatterns become ruleslow qualityremaining dataselected subset
What happens to a raw record as it moves through cleaning, compliance checks, inspection and heuristics, and optional pruning, and where records are dropped along the way.

Notice where records leave the pipeline. Non-compliant records and low-quality records are dropped at different points, and the optional pruning stage only applies when the collection is larger than the project can use. Each stage works on what the previous stage left behind, so the training set is the end result of every filter, not any single one.

Trimming a Dataset That Is Too Large

Sometimes the problem is not bad data but too much of it. The source notes that if there is more data than you need or can afford to use, for example because of your compute budget, you can filter further. Two techniques are named. Active learning selects the examples that are most helpful for the model to learn from. Importance sampling selects the examples that are most important to the task. Both are ways of keeping a subset chosen on purpose, rather than a random or arbitrary portion.

Random portionArbitrary portionkeptActive learningmost helpful examplesImportance samplingmost important exampleskept
How active learning and importance sampling select a smaller subset differently from a random or arbitrary portion, and which kinds of records are kept.

The contrast in the diagram is the core idea. A random or arbitrary portion keeps whatever happens to be included, with no judgment about value. Active learning and importance sampling instead judge each example and keep the ones that help most. The result is a smaller dataset whose contents were decided deliberately.

Why the Pruning Metric Decides the Outcome

Both active learning and importance sampling depend on a single requirement, which the source states directly: their efficiency depends on whether you have a good way to evaluate the importance of each training example. Choosing examples is only as good as the measure used to judge them. A weak measure keeps the wrong examples, while a strong measure lets a much smaller set carry most of the value.

The source ties this to cost. Meta researchers, in their study of data pruning (Sorscher and colleagues, 2022), concluded that discovering good data-pruning metrics can significantly reduce the resource costs of modern deep learning. The practical message is that a good metric is an investment: it determines how much of a large dataset can be dropped without losing the examples that matter.

Worked example

Two metrics applied to the same collection

A project has a collection far larger than its compute budget and must keep a fraction of it. Compare what a poor metric and a good metric would do.

  1. 1
    Apply a poor metric

    A metric that does not track which examples matter may score a mix of useful and useless records similarly. The kept subset then contains weak examples and the filtering adds little value.

  2. 2
    Apply a good metric

    A metric that reliably separates important examples from unimportant ones keeps the records that carry the most value. The same fraction of data now holds more of what the model needs.

  3. 3
    Compare the outcomes

    Both runs keep the same amount of data, but only the good metric makes the smaller set useful, which is the point the source makes about pruning metrics and resource costs.

Result

The quality of the metric, not the size of the subset alone, determines how useful filtering will be.

Mistakes Beginners Make When Filtering

  • Common mistake

    Dropping an entire record to remove one restricted column

    What it looks like

    A record has a name column that the project may not use, and the whole row is deleted even though its text is usable.

    Why it fails

    The source says removing a field is often better than removing the whole record, because the rest of the record may still be valuable.

    Do this instead

    Drop only the non-compliant field and keep the rest of the record.

  • Common mistake

    Leaving formatting tokens in the text because the model can probably handle them

    What it looks like

    Raw HTML tags are kept in the training text, so the model spends capacity on page structure rather than content.

    Why it fails

    Formatting tokens are noise unless the goal is to teach the model to read them, and removing them can improve accuracy while cutting input length.

    Do this instead

    Strip extraneous HTML and Markdown markup as the first cleaning task.

  • Common mistake

    Writing a heuristic without checking the patterns behind it

    What it looks like

    A rule flags records based on a surface feature that actually appears in good records too.

    Why it fails

    Heuristics are meant to come from patterns that manual inspection reveals, and some depend on context that a simple rule may not capture.

    Do this instead

    Inspect the data by hand first, turn the noticed pattern into a rule, and check that the rule matches what was observed.

  • Common mistake

    Treating any subset of the data as equally good when the dataset is too large

  • Common mistake

    Choosing a pruning metric without evaluating how well it separates important examples

    Why it fails

    Active learning and importance sampling are only as good as the measure of each example's importance, so a weak metric keeps the wrong examples.

    Do this instead

    Assess the metric's ability to identify important examples before relying on it to drop data.

Applying the Cleaning Sequence

EASY

A scraped record contains an HTML bold tag, a column with a restricted personal name, and text that is compliant and readable. Describe, in order, what should happen to this record before it can join the training set, and say which parts of it are removed.

Hints
  • Start with the formatting tokens, which are noise unless the goal is to teach the model to read them.
  • Check the restricted column against project policies, and remember that removing a field may be better than removing the record.
  • Think about which parts of the record are kept after each step.
MEDIUM

A collection is much larger than the compute budget allows. Explain in two or three sentences why a good importance measure matters more than simply keeping a fixed number of records.

Hints
  • Look back at the source's statement that efficiency depends on a good way to evaluate each example's importance.
  • Consider what a weak measure would keep compared with a strong one.

Key Takeaways

  • A model absorbs every pattern in its training examples, so raw data must be cleaned of formatting tokens, non-compliant content, and poor-quality records before training.
  • Removing a non-compliant field is often better than removing the whole record, and extraneous HTML and Markdown markup should be stripped first.
  • Manual inspection reveals patterns that become heuristics, and some heuristics depend on context such as position in an annotation session.
  • When data exceeds the available budget, active learning and importance sampling select helpful and important examples rather than an arbitrary portion.
  • The usefulness of filtering depends on the quality of the metric that measures each example's importance, which can greatly reduce resource costs when it is good.

Related concepts

More concepts starting with P