Repository navigation
Releases
Releases · koivualeksi/htmlsift
v0.3.1
Docs-only release: README and PyPI description lead with the policy idea, a quick start and the article learning curve, plus a 'When not to use it' section; package description and keywords updated. No code or model change.
Full changelog: v0.3.0...v0.3.1
v0.3.0
Added
dedup=True(CLI--dedup): leaves out each selected line of 100 or more characters that repeats an earlier selected line, keeping the first copy, intext,htmlandmarkdown. Lines are compared ignoring case, punctuation and markers. Lines in a<pre>are never deduped. Off by default;with_blocks=True, the model input and the predictions are unchanged.threshold=(CLI--threshold): a line is kept when its probability is above it, 0 to 1, default 0.5. Lower keeps more, higher keeps less. Only 0.5 is benchmarked.with_blocks=Truestill returns every probability.
Changed
- New mini model: the embedding table is int8 rank-128 (34.6 MB, was 768 wide and 202 MB). The release pin moves to Hub commit
a86f08a;base/is unchanged apart from its addedtokenizer.json.gz. The first mini download is ~43 MB, and base fetches the 5.4 MB gzipped tokenizer instead of the 33 MB plain one. - Dependencies now have tested bounds:
lxml>=6.0.4,<7,tokenizers>=0.21,<0.24,onnxruntime>=1.20.1,numpy>=1.26.4,huggingface-hub>=0.26.5,w3lib>=2.3.1,<3(was>=2.5,<3), and for[full]torch>=2.7.1,transformers>=5.1,<6. Tested on Linux: across these ranges the mini model gives the sametext,htmlandmarkdownon 2,040 test pages (onnxruntime before 1.30 shifts probabilities by at most 2.4e-6). The base model gives the same line selection on a 13-page sample, except that torch 2.7-2.12 shifts probabilities by up to 0.014 and can flip a line that sits right at the 0.5 threshold. lxml 5.x is excluded: its older libxml2 renders some pages differently from the libxml2 2.14 the models were trained on. CI now also runs the suite with the lowest allowed versions. - The mini model now mean-pools each block's token embeddings with one vectorized segment sum, in batches of 32,768 tokens, instead of a Python loop over blocks. Probabilities can differ from before by about 1e-6; on 2,040 test pages no block changed side of the 0.5 threshold.
- The mini model's per-page memory estimate is sized for the rank-128 table: 1 KB per distinct token id and 12 KB per block (was 12 and 21, sized at 768 wide). Pages estimated above 100 MB still give onnxruntime's arena back after they run; with the new sizes that is pages with about 8,500 or more blocks. Output is unchanged.
- The tokenizer is read from
tokenizer.json.gzwhen the bundle has one, and fromtokenizer.jsonotherwise, both from the Hub and from a local bundle folder. Pinned bundles without the gzipped file load as before.
Fixed
- A document that parses to no element (only comments, a doctype, an
<?xml?>declaration or other processing instructions; with libxml2 2.11, as in lxml's Windows wheels, also a lone BOM or leading NUL bytes) raisedlxml.etree.ParserError: Document is empty. It now returns""in every output, and([], [])withwith_blocks=True, as an empty string does. - An unknown
output(e.g.output="md") raisedValueErroronly after the model had run on the page, and not at all withwith_blocks=True. It now raises before any inference, in every case. output="html"andoutput="markdown"no longer contain text from lines the model rejected. They kept whole elements, so the text of a parent element, the text right after a kept element and the children of a kept element came back with it. They now keep exactly the text of the selected lines, asoutput="text"does. A code block (a<pre>with no block elements inside) stays whole when any of its lines is selected.textoutput, the model input and the predictions are unchanged.output="html"andoutput="markdown"no longer glue separate lines together (Personal incomePopulation) when the<br>or block element between them was not kept; a<br>takes its place.- With
base_url=(or an absolute<base href>), a relative SVGxlink:hrefstayed relative inoutput="html"on lxml < 6.1. It is now made absolute on every lxml version, as on 6.1+. - With libxml2 2.14 (lxml's Linux wheels),
output="html"andoutput="markdown"raisedValueError: All strings must be XML compatibleon pages with C0 control characters (such as\x03or) in text or attributes. The parser now removes them, as libxml2 2.11 (lxml's Windows wheels) already did. Pages without them, and every page on Windows, give the same output as before; on Linux, thetextoutput and the model input of affected pages lose the characters too. None of the 7,825 WebMainBench training and test pages contain them.
Security
output="html"andoutput="markdown"are now cleaned of active content. Kept elements could carry<script>,<style>, event handlers (onclick=),srcdocandjavascript:links, and markdown wrote[text](javascript:...). Now the elements the model never reads (script,style,title,meta,link,base) and SVG<animate>/<set>are dropped,on*andsrcdocattributes are removed, and a link or source whose scheme is nothttp,https,mailto,tel,ftpor relative loses its target (its text stays);data:image/in<img src>is kept. SVGxlink:hrefis checked the same way on every lxml version (lxml < 6.1 does not list it as a link attribute). A basic cleanup, not a guarantee.textoutput, the model input and the predictions are unchanged.
Full changelog: v0.2.1...v0.3.0
v0.2.1
Added
htmlsift --versionprints the htmlsift and Python versions and the installed backends: onnxruntime formini, torch and transformers forbase.drop_title=Trueinextract()and--drop-titlein the CLI leave out the page title that starts the content: the first selected line, when it comes from anh1–h6orpelement holding only that line and matches the page's<title>orog:title. Applies totext,htmlandmarkdown. Off by default.
Changed
- With w3lib 2.6 or newer, the five bytes windows-1252 leaves undefined (
0x81,0x8D,0x8F,0x90,0x9D) decode to C1 control characters, as in browsers, instead ofU+FFFD. output="text"(the default) returns plain text, as documented. Heading#, emphasis, inline-code and strikethrough markers,>quote prefixes,* * *rules and code-fence lines are no longer in it; list bullets, ordered-list numbers and table rows stay. Literal#,*,_or|in the page text are kept. The selected content is the same as in 0.2.0, and the model input and predictions are unchanged.textoutput renders the page a second time, without markers: about 3 ms per page more on one CPU core (mini, measured on CommonCrawl pages).- The lines as the model scored them, markers included, are still available through
with_blocks=True.
Fixed
output="text"no longer contains lines made only of invisible characters (zero-width spaces and joiners, byte order marks, soft hyphens, control characters), which pages use as spacers.minimemory on very long pages. The embedding step no longer grows with page length (a 3M-token page peaked at 39 GB, now 1.2 GB), and pages estimated above 100 MB hand their memory back to the system when they finish instead of keeping it for the life of the process. Output is unchanged; model time is about 15 % lower on CommonCrawl pages.mode="base"without torch or transformers installed raised a bareNo module named 'torch', and only after downloading the ~1 GB base bundle. It now raisesImportErrorbefore any download, naming the missing packages andpip install "htmlsift[full]". The CLI prints the same message.
Full changelog: v0.2.0...v0.2.1
v0.2.0
Added
extract()acceptsbytesand decodes them: byte order mark, thenencoding=, then the page's<meta>declaration, then utf-8, falling back to cp1252. Legacy charset labels map the way browsers read them (latin1→ cp1252,shift_jis→ cp932,gb2312→ gb18030).- Keyword-only
encoding=onExtractor.extractandextract, for a charset known from an HTTP or WARC header. - Dependency:
w3lib(BSD-3-Clause) for charset sniffing. - Keyword-only
base_url=onExtractor.extractandextract: links and image URLs inhtmlandmarkdownoutput are made absolute against it. The page's first<base href>is resolved againstbase_url; malformed links are left as they are.textoutput andwith_blocksare unaffected. htmlsift extractcommand: files, quoted globs or stdin in; the content of a single input, or one JSON line per file (--jsonlto force), out. Flags--output,--mode,--device,--base-url,--encoding. Failed files are reported as records and the run exits with 1.
Changed
- Input other than
strorbytesraisesTypeError;extract(None)previously returned"". encoding=withstrinput raisesTypeError, since astris already decoded.- A page with an absolute
<base href>gets absolute links inhtmlandmarkdownoutput even withoutbase_url. Previously<base>was dropped with<head>, leaving its links relative.
Fixed
- Non-utf-8
bytesinput crashed withUnicodeDecodeError. htmlandmarkdownoutput could drop images and other inline content inside a kept block, varying from run to run on the same page.textoutput was unaffected.
Full changelog: v0.1.1...v0.2.0
htmlsift 0.1.1
v0.1.0
First release of htmlsift
Web main-content extraction: HTML string in, clean text / HTML / markdown out.
mini(default) — int8 ONNX, CPU, torch-free:pip install htmlsiftbase— 311M encoder, GPU-capable:pip install htmlsift[full]
Model weights are fetched from the Hugging Face Hub on first use.
See the README for benchmarks and usage.