Data Verification and Quality Checks
Raw scraped data often contains formatting tokens such as HTML and Markdown, and removing them can improve accuracy while cutting input length.
Why a Model Learns Whatever It Is Given
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 means the people preparing training data must decide, before training begins, what stays, what goes, and what might be worth keeping in a smaller form.
This article follows that decision-making from start to finish. It covers cleaning data that is not usable as it stands, detecting records that are low in quality, and filtering a collection that is larger than the project can afford to use.
What do you think happens?
A scraped line reads: <p>Hello <b>world</b></p>. If the HTML tags are removed and only the text is kept, what remains?
Reveal answer
Hello world
The angle-bracketed tags are formatting markup, not content the model needs to learn. Removing them leaves the words themselves, which is the purpose of the first cleaning step.
What Raw Scraped Text Contains
Many public datasets are assembled by collecting text from across the internet. Web pages are written in markup languages, so text pulled from them often arrives wrapped in HTML tags. These tags may describe page structure, add styling hints, or mark links. Unless the goal is to teach a model to read those tags, they are noise.
The first cleaning task is therefore to remove extraneous formatting tokens, including HTML and Markdown markup that ended up inside the text itself. The source pack summarizes the benefit directly: removing these tokens can improve accuracy while also cutting the length of the input.
In the diagram, the tags on the left are marked as changed because they are the parts removed. Only the words survive on the right. The tags were never part of what the model should learn to produce, so their removal changes nothing useful about the text itself.
Removing Formatting Tokens in Code
A simple way to strip angle-bracketed tags is a regular expression that matches anything between a less-than sign and a greater-than sign. The example below is an illustration of the idea, not a full cleaning pipeline.
import re
raw = '<p>Hello <b>world</b></p>'
cleaned = re.sub(r'<[^>]+>', '', raw)
print(cleaned)- 1Line 1 imports the regular expression module.
- 2Line 3 stores a scraped string that contains HTML tags.
- 3Line 4 removes every tag and keeps the text between them.
- 4Line 5 prints the cleaned text, which contains only the words.
- The pattern <[^>]+> matches an opening angle bracket, one or more characters that are not a closing bracket, and a closing bracket.
re.subreplaces every match with an empty string, deleting the tags.
Hello worldEnforcing Project Rules on the Data
Cleaning also means enforcing rules. Data has to be checked against the policies that govern the project, and anything that does not comply has to be removed. The source names several categories that fall under this heading: personally identifiable information (PII), sensitive data, copyrighted material, and content considered toxic.
Techniques for handling these categories are covered in an earlier chapter on privacy and safety. This article focuses on the filtering step itself: the point in the pipeline where non-compliant material is actually taken out.
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. A record can be clean in form and still be a weak example for learning. Finding these records relies on a combination of two activities: looking closely at the data by hand, and turning what is noticed into rules that can be applied across the whole collection.
Manual inspection reveals patterns. Once a person notices that a certain kind of record is poor, that pattern can become a heuristic, a rule that flags similar records automatically. The source notes that some heuristics depend on context, such as the record's position within an annotation session. A rule like that cannot be judged from the record alone; it depends on where the record sits in the process that produced it.
The two activities feed each other. Manual review finds the pattern, the heuristic applies it at scale, and further review checks whether the rule is catching the right records. The diagram below shows the order of the cleaning stages that surround this step.
The Cleaning Pipeline from Raw Data to Trimmed Set
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. Raw scraped data first has its formatting tokens removed, then is checked against project policies, then has non-compliant fields dropped, then is screened for low-quality records. Only after that, if the project has more data than it can use, does an optional filtering stage select a subset.
Read the diagram from left to right. Each stage removes something, so the collection on the right is smaller and cleaner than the one on the left. The final filtering stage is marked as a decision because it applies only when there is more data than the project can afford to use.
Trimming a Dataset That Is Too Large
Sometimes the problem is not bad data but too much of it. If there is more data than you need or can afford to use, for example because of your compute budget, you can filter further. The source names two techniques for choosing which examples to keep.
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 of the collection.
Active learning works as a cycle rather than a single choice. The model is trained, a selection step picks the examples it would learn most from, a human reviewer labels those examples, and the model is retrained on the result. The cycle then repeats. The diagram below shows the order in which these parties interact across rounds.
Importance sampling is different in emphasis. It keeps the examples judged most important to the task, and it does not depend on repeated rounds of retraining in the way the active learning loop does. In both cases, the subset is chosen deliberately rather than by chance.
Why the Pruning Metric Decides Everything
Both techniques 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; a strong measure lets a much smaller set carry most of the value.
Consider a simple cut-off made of a score for each record. Every record scoring above the threshold is kept and every record below it is dropped. If the score is accurate, the records above the line are the ones that matter, and a large share of the collection can be removed safely. If the score is noisy, good records can fall below the line and be lost, while poor records can climb above it and stay in the set.
Two metrics, one threshold
A collection of six records each has a score, and the project keeps records scoring 0.5 or higher. Compare what survives under an accurate metric and a noisy one. Assume the true usefulness of the records is ranked A, B, C, D, E, F from most to least useful.
- 1Accurate metric
Scores fall in the same order as true usefulness: A 0.9, B 0.8, C 0.6, D 0.3, E 0.2, F 0.1. Keeping scores of 0.5 or higher retains A, B, and C, and drops D, E, and F. The kept set is the most useful third of the collection.
- 2Noisy metric
Suppose the same records receive scores A 0.4, B 0.9, C 0.3, D 0.6, E 0.2, F 0.1. Keeping scores of 0.5 or higher retains B and D. Record A, the most useful, is lost, and D, one of the weaker records, is kept.
- 3Comparison
Both metrics keep the same number of records, but only the accurate metric keeps the examples that matter. The threshold is identical in both runs; the difference comes entirely from the quality of the score.
The usefulness of a filter is set by the metric behind it. A cut-off applied to a noisy score can discard the best examples and keep poor ones, even with a sensible threshold.
The source ties the value of this work 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, because it determines how much of a large dataset can be dropped without losing the examples that matter.
Mistakes Beginners Make When Cleaning Data
Common mistake Assuming all markup is noise
Why it failsTags are noise only unless the goal is to teach a model to read them.
Do this insteadDecide first what the model should learn, then remove only the formatting that is not part of that goal.
Common mistake Dropping whole records to remove one bad field
Why it failsThe rest of the record may still be allowed and useful.
Do this insteadRemove the non-compliant field and keep the remaining record where possible.
Common mistake Writing a heuristic without looking at the data
Why it failsHeuristics are meant to capture patterns found by manual inspection, so a rule invented without inspection may not match real poor records.
Do this insteadInspect records by hand first, turn the observed pattern into a rule, then check the rule against records it flags.
Common mistake Ignoring context when applying a heuristic
Why it failsSome heuristics depend on context, such as position in an annotation session, so a record may look different depending on where it appears.
Do this insteadState the context a heuristic depends on and apply it only where that context holds.
Common mistake Trusting a pruning metric without checking it
Why it failsThe usefulness of importance-based selection depends on how well the metric measures importance.
Do this insteadCheck which records the metric keeps and which it drops before using it to cut a large dataset.
Tracing a Record Through the Cleaning Stages
A scraped record contains the text <div>Good example of a clear answer</div>, has a zip code column that the project is not permitted to use, and is one of many records with the same low-effort pattern found during manual inspection. Trace what happens to this record through the pipeline, stage by stage, and state what remains at the end.
Hints
- Start with formatting removal: which part of the record is markup and which part is content?
- Next check the compliance stage: is the problem with the whole record or with a single field?
- Finally consider whether the low-effort pattern is a heuristic that applies to this record, and whether the record would survive an optional trimming step.
Key Takeaways
- Raw scraped text often contains HTML and Markdown formatting tokens that are noise unless the goal is to teach a model to read them, and removing them can improve accuracy while shortening the input.
- Compliance cleaning removes non-compliant material, and non-compliant fields such as a zip code, name, or gender value should usually be dropped while keeping the rest of the record.
- Low-quality records are found by combining manual inspection with heuristics; some heuristics depend on context such as position in an annotation session.
- When data exceeds the budget, active learning selects the most helpful examples and importance sampling selects the most important ones, and both work only as well as the measure of each example's importance.