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.
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?
Reveal 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.
<p>Scraped text with <b>bold</b> layout tags.</p>Raw scraped string containing HTML tags that only control display
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.
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?
- 1Identify 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.
- 2Classify 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.
- 3Check 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.
- 4Remove and reassemble
Delete the three tags and keep the words in their original order, joined by a space.
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.
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.
| Category | What it means in the source |
|---|---|
| Personally identifiable information | Data that can point to a specific person |
| Sensitive data | A broader group that your policies restrict |
| Copyrighted data | Material you do not have the right to use |
| Toxic data | Content 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.
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.
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?
- 1Recall 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.
- 2Turn 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.
- 3Apply 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.
- 4Decide 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.
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 likeDeleting all HTML tags from a dataset meant to teach a model to write markup.
Why it failsThe source says to remove these tags unless you want to train on them. Removal depends on what the model should learn.
Do this insteadConfirm 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 likeRetaining a zip code field because it helps the model, even though a policy forbids using it.
Why it failsThe 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 insteadCheck 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 likeAssuming a record that is copyrighted cannot also contain personally identifiable information.
Why it failsA single record can belong to more than one category.
Do this insteadCheck every record against the whole checklist of categories.
Common mistake Judging low-quality data by reading one record in isolation
Why it failsLow-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 insteadUse 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
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.