Concepts / Data Verification

Data Verification

Extraneous HTML tags and Markdown tokens are common in scraped data, and removing them is usually right unless the model is meant to learn markup.

  • Programming

Why Scraped Text Needs Inspection

Imagine you have collected a large amount of text from the web to train a language model. On the surface, the text looks like language. But many of the pages were written in markup languages, and some of the content should never reach a model at all. Data preparation is the stage where you decide what stays, what goes, and what needs repair before training begins. This article focuses on the removal half of that work: taking out the things that do not belong in the dataset.

The source material names three broad kinds of unwanted data. The first is extraneous formatting tokens, such as HTML tags and Markdown symbols. The second is information that conflicts with policy, including personally identifiable information, sensitive data, copyrighted material, and toxic content. The third is low-quality data, which may look acceptable at a glance but makes the model worse. The guiding goal is stated directly: data needs to be cleaned to make your model performant and safe.

What do you think happens?

A scraped web page contains the tags <p> and <b>. You are building a general-purpose text training set. Should those tags be kept?

  • Keep them, because they are part of the original page

  • Remove them, unless the model is meant to learn HTML tags

Reveal answer
Answer:

Remove them, unless the model is meant to learn HTML tags.

The source says to remove extraneous HTML tags and Markdown tokens unless you want to train your model on those tags. For most general text training, they are noise.

Markup That Only Controls Layout

Many public datasets are scraped from the internet, and web pages are built from HTML. An HTML tag such as a paragraph or bold marker is an instruction for a browser about how to display text. It is not part of the words a reader sees. When a scraper copies a page, those tags often come along with the text. The result is that a model may be trained on characters whose only job is layout.

Markdown works the same way in a different style. Symbols used to mark headings, emphasis, or lists are formatting tokens rather than content. The source treats both kinds of token as extraneous. They are present in the data because of how it was collected or written, not because they carry meaning the model should learn.

The clearest way to see the difference is to compare a raw scraped string with the same string after its formatting tokens are removed. The example below is an original illustration, not a source excerpt.

Before
<p>Scraped text with <b>bold</b> layout tags.</p>

Raw scraped string containing HTML tags that only control display

After

Scraped text with bold layout tags.

Plain words with the layout tags removed

Tracing One String Token by Token

Now follow a single scraped string through the decision. Each token is either content the model should learn or a formatting token that the source calls extraneous. The diagram marks which tokens are removed and what remains.

<p>HTML tagCleanword keptCleanworddataword kept<b>HTML tagdataword</b>HTML tag</p>HTML tag
Which tokens in the scraped string are noise, and what does the string look like after they are removed?
Worked example

Cleaning one scraped string

Given the scraped string <p>Clean <b>data</b></p>, and a general text training goal, which tokens should be removed and what should remain?

  1. 1
    Identify the tokens

    Split the string into its pieces: the opening paragraph tag, the word Clean, the opening bold tag, the word data, the closing bold tag, and the closing paragraph tag.

  2. 2
    Classify each token

    The three tags are HTML formatting tokens. They are instructions for display rather than words a reader sees. The two words are content.

  3. 3
    Check the training goal

    The model is meant to learn general text, not markup. The source says to remove these tags unless you want to train on HTML tags, so the removal rule applies.

  4. 4
    Remove and reassemble

    Delete the three tags and keep the words in their original order, joined by a space.

Result

Clean data

Deciding Whether Markup Stays

Removal is a decision based on what the model is supposed to learn, not a rule that applies everywhere. The source says that extraneous HTML tags and Markdown tokens are common in scraped data and that removing them is usually right, unless the model is meant to learn markup. So the question to ask is always the same: is the markup part of the lesson the model should take in?

If your goal is a model that writes or reads markup, the tags may be exactly the content you want to keep. For most general text training, they are noise. The flowchart below turns that question into a sequence of steps. Note that the source also says removal decisions should be checked against the model's goal and policy before any deletion happens.

Training goalwhat the model should learnShould the modellearn markup?Keep the tagsmarkup is the contentRemove HTML andMarkdown tokensfor general text trainingcheckyesno
Given the training goal, do I strip this markup or keep it, and what question do I ask to decide?

Policy Categories That Must Go

The second kind of removal is driven by policy, not by formatting. The source says you need to clean your data of anything that is not compliant with your policies. It names four categories that commonly fall into that group. The categories differ in kind, as the table shows.

CategoryWhat it means in the source
Personally identifiable informationData that can point to a specific person
Sensitive dataA broader group that your policies restrict
Copyrighted dataMaterial you do not have the right to use
Toxic dataContent considered harmful

The four policy categories named in the source

Structured Fields You Cannot Use

For structured data, the source gives a practical instruction: remove all the fields that you are not allowed to use. Its examples are a zip code, a name, and a gender field. The rule is about permission, not about whether a field seems important.

This matters because a restricted field may improve a model's predictions. If a policy forbids using the field, it leaves the dataset anyway. Usefulness to the model does not override a policy restriction.

Spotting Low-Quality Data

The third kind of removal targets low-quality data: examples that are weak for training. The source points to data verification techniques for finding them. These examples are harder to catch than formatting tokens or restricted fields, because nothing about them is obviously wrong when you look at one record in isolation.

The source gives manual inspection a central role. Staring at data can help you notice patterns. Those patterns can become heuristics, which are rules of thumb you apply to flag suspect examples at scale. The useful heuristics are not always obvious. They may depend on something outside the text itself, such as how or when the example was produced.

A concrete finding from the source illustrates this. Kern et al. (2024) found that annotations made in the second half of an annotation session are of lower quality, likely due to annotator boredom or fatigue. A heuristic built on that finding would not look at the words of the annotation at all. It would look at the position of the example within the annotator's session.

Raw recordsunverified examplesManual inspectionnotice patternsHeuristic rulerule of thumbFlag suspect examplecloser review or removalRecord passesno rule matchesinspectturn into rulematchesno match
In what order do the checks run, and where does a record get flagged, passed, or sent for manual review?

The diagram is an illustrative layering rather than a fixed procedure from the source. It shows the idea the source describes: human inspection produces a rule, the rule is applied across many records, and matching records are flagged for closer review or removal while the rest pass.

A Position-Based Heuristic in Practice

The following example is an original illustration that applies the session-position idea. It uses invented numbers to show the reasoning, not real figures from the source.

Worked example

Flagging late-session annotations

An annotation batch contains 200 examples produced in one long session. Manual inspection suggests annotation quality drops late in a session. Which examples should be flagged for closer review, and why does the rule ignore the annotation text?

  1. 1
    Recall the finding

    The source reports that annotations made in the second half of an annotation session are of lower quality, likely due to boredom or fatigue.

  2. 2
    Turn the finding into a rule

    Define the heuristic on position: an example is a candidate for review if it falls in the second half of its annotator's session. The rule reads the session order, not the words.

  3. 3
    Apply the rule at scale

    Compute each example's position within its session. For a session of 40 examples, examples 21 through 40 are in the second half and are flagged.

  4. 4
    Decide the action

    Flagged examples go to closer review or removal. Examples in the first half pass this check and move on to other verification steps.

Result

Examples in the second half of each session are flagged for review. The text of each annotation was never read by this rule, which is why it counts as a non-obvious heuristic.

Mistakes Beginners Make When Cleaning Data

  • Common mistake

    Stripping every tag without checking the goal

    What it looks like

    Deleting all HTML tags from a dataset meant to teach a model to write markup.

    Why it fails

    The source says to remove these tags unless you want to train on them. Removal depends on what the model should learn.

    Do this instead

    Confirm the training goal, then decide whether the markup is noise or the content.

  • Common mistake

    Keeping a field because it improves predictions

    What it looks like

    Retaining a zip code field because it helps the model, even though a policy forbids using it.

    Why it fails

    The source's rule for structured data is about permission. A field you are not allowed to use leaves the dataset regardless of usefulness.

    Do this instead

    Check each field against policy first, and remove forbidden fields even when they help.

  • Common mistake

    Treating each policy category as a separate, exclusive bin

    What it looks like

    Assuming a record that is copyrighted cannot also contain personally identifiable information.

    Why it fails

    A single record can belong to more than one category.

    Do this instead

    Check every record against the whole checklist of categories.

  • Common mistake

    Judging low-quality data by reading one record in isolation

    Why it fails

    Low-quality examples often look acceptable on their own. Their weakness can show up only in patterns or in context such as position in a session.

    Do this instead

    Use manual inspection to discover patterns, then turn them into heuristics applied across the dataset.

  • Common mistake

    Deleting data before checking it against the model's goal and the applicable policy

Practice: Decide What Goes

MEDIUM

A team is training a general-purpose text model. A scraped record reads: <h2>Refund policy</h2> Customers may return items within 30 days. The record also includes a customer's full name and home address. For each part of the record, decide whether it is kept, removed as formatting, or removed for policy reasons. Then explain what you would check before deleting anything, and whether a heuristic might also flag this record.

Hints
  • Start by separating formatting tokens from words the reader sees.
  • Ask whether the name and address fall under one of the four policy categories or the restricted-field rule.
  • Remember that the source says removal should be checked against the model's goal and policy before deletion.

Key Takeaways

  • Extraneous HTML tags and Markdown tokens are common in scraped data. Removing them is usually right, unless the model is meant to learn markup.
  • Policy drives a second kind of removal: personally identifiable information, sensitive data, copyrighted data, toxic data, and any fields you are not permitted to use. A record can fall into more than one category.
  • Low-quality data is hard to see in isolation. Manual inspection can reveal patterns, and non-obvious heuristics, such as the lower quality of annotations made late in a session, can flag suspect examples at scale.
  • Every removal decision should be checked against the model's goal and policy before any data is deleted.

More concepts starting with D