Notes

HTML Stripping

Most of the text that feeds a language system came off the web, which means it did not arrive as text. It arrived wrapped in tags, scripts, navigation menus and cookie notices. HTML stripping is the step that recovers the prose a reader would actually have seen.

More than deleting angle brackets
Done properly this is a parse, not a search-and-replace: a parser such as Beautiful Soup or lxml builds the document tree, discards script and style content outright, and collects the text nodes. Two details matter more than they sound:

  • Character entities have to be decoded, or escaped ampersands and apostrophes survive as literal strings and enter the vocabulary as if they were words.
  • Block boundaries have to be preserved. Joining text nodes blindly welds "the end." to "Next article", and sentence segmentation downstream never recovers.

Where boilerplate removal begins
Stripping the markup still leaves every word on the page, including the footer, the share buttons and the subscription prompt. Across a crawl that template text repeats on thousands of pages and comes to dominate your frequency counts, which is why extraction tools such as trafilatura go further and keep only the main content block. Treat them as two steps: remove the markup, then decide which of the remaining text was the article.

Why it matters
Everything downstream inherits whatever this step leaves behind. Tags that survive become tokens, inflating the vocabulary with "div" and "href"; stray markup breaks a tokenizer's assumptions about where a word ends; and a model trained on navigation chrome learns the layout of a website instead of the language on it.

HTML stripping removes markup from web-sourced text — tags, script and style blocks, and character-entity escapes — leaving the readable prose a model can consume. It is the first step of any web ingestion pipeline, and its errors are inherited by everything after it: surviving tags become tokens and inflate the vocabulary, while lost block boundaries fuse adjacent sentences and break segmentation. Discarding page boilerplate such as menus and footers is a separate, later decision.

A web page is not only the words you read. Behind it sits a pile of instructions telling the browser what should be bold, where the menu goes and which advert to load. A person never sees any of it.

HTML stripping is the clean-up that throws that scaffolding away and keeps the writing — rather like photocopying just the article out of a cluttered newspaper page. Software that studies language needs plain sentences, and any leftover scaffolding gets counted as though it were vocabulary. Done carelessly, it also glues the end of one paragraph to the start of the next, leaving sentences that no longer make sense to anything reading them later.