htmlsift 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- htmlsift-0.1.0/.gitattributes +5 -0
- htmlsift-0.1.0/.github/workflows/ci.yml +24 -0
- htmlsift-0.1.0/.gitignore +48 -0
- htmlsift-0.1.0/AGENTS.md +45 -0
- htmlsift-0.1.0/LICENSE +201 -0
- htmlsift-0.1.0/PKG-INFO +89 -0
- htmlsift-0.1.0/README.md +207 -0
- htmlsift-0.1.0/README.pypi.md +61 -0
- htmlsift-0.1.0/docs/assets/architecture.svg +137 -0
- htmlsift-0.1.0/docs/assets/concept.svg +90 -0
- htmlsift-0.1.0/docs/assets/cpu_speed_accuracy.svg +67 -0
- htmlsift-0.1.0/docs/assets/data-efficiency.svg +119 -0
- htmlsift-0.1.0/docs/assets/gpu_speed_accuracy_lite.svg +31 -0
- htmlsift-0.1.0/docs/assets/signals.svg +76 -0
- htmlsift-0.1.0/pyproject.toml +61 -0
- htmlsift-0.1.0/src/htmlsift/__init__.py +9 -0
- htmlsift-0.1.0/src/htmlsift/_artifacts.py +64 -0
- htmlsift-0.1.0/src/htmlsift/cli.py +29 -0
- htmlsift-0.1.0/src/htmlsift/core/__init__.py +6 -0
- htmlsift-0.1.0/src/htmlsift/core/band.py +144 -0
- htmlsift-0.1.0/src/htmlsift/core/features.py +129 -0
- htmlsift-0.1.0/src/htmlsift/core/onnx_infer.py +38 -0
- htmlsift-0.1.0/src/htmlsift/core/prep_page.py +93 -0
- htmlsift-0.1.0/src/htmlsift/core/prune.py +42 -0
- htmlsift-0.1.0/src/htmlsift/core/render.py +328 -0
- htmlsift-0.1.0/src/htmlsift/core/tokenizer.py +38 -0
- htmlsift-0.1.0/src/htmlsift/core/torch_infer.py +165 -0
- htmlsift-0.1.0/src/htmlsift/extractor.py +91 -0
- htmlsift-0.1.0/src/htmlsift/loader.py +82 -0
- htmlsift-0.1.0/src/htmlsift/py.typed +0 -0
- htmlsift-0.1.0/tests/__init__.py +0 -0
- htmlsift-0.1.0/tests/data/sample.extracted.html +15 -0
- htmlsift-0.1.0/tests/data/sample.extracted.md +20 -0
- htmlsift-0.1.0/tests/data/sample.extracted.txt +15 -0
- htmlsift-0.1.0/tests/data/sample.html +52 -0
- htmlsift-0.1.0/tests/data/sample.rendered.txt +24 -0
- htmlsift-0.1.0/tests/test_api.py +32 -0
- htmlsift-0.1.0/tests/test_extract_golden.py +46 -0
- htmlsift-0.1.0/tests/test_features.py +38 -0
- htmlsift-0.1.0/tests/test_manifest.py +45 -0
- htmlsift-0.1.0/tests/test_prep_page.py +35 -0
- htmlsift-0.1.0/tests/test_prune.py +38 -0
- htmlsift-0.1.0/tests/test_render_golden.py +25 -0
- htmlsift-0.1.0/tests/test_render_links.py +29 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.10", "3.13"] # floor + latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- name: Install (base deps only, no torch)
|
|
20
|
+
run: pip install -e . ruff pytest
|
|
21
|
+
- name: Lint
|
|
22
|
+
run: ruff check src tests
|
|
23
|
+
- name: Test (model goldens skip without HTMLSIFT_BUNDLE)
|
|
24
|
+
run: pytest -q
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
.eggs/
|
|
6
|
+
|
|
7
|
+
# Build artifacts
|
|
8
|
+
build/
|
|
9
|
+
dist/
|
|
10
|
+
|
|
11
|
+
# Virtual environments
|
|
12
|
+
.venv*/
|
|
13
|
+
venv/
|
|
14
|
+
|
|
15
|
+
# Secrets / local config
|
|
16
|
+
.env
|
|
17
|
+
|
|
18
|
+
# Tooling caches
|
|
19
|
+
.pytest_cache/
|
|
20
|
+
.ruff_cache/
|
|
21
|
+
.mypy_cache/
|
|
22
|
+
|
|
23
|
+
# Local model artifacts (weights are never committed; the package fetches them from HF)
|
|
24
|
+
*.pt
|
|
25
|
+
*.onnx
|
|
26
|
+
|
|
27
|
+
# Local dev bundles (e.g. localbundle/mini with graphs + tokenizer.json + manifest.json)
|
|
28
|
+
localbundle/
|
|
29
|
+
|
|
30
|
+
# Local agent instructions (kept local, not shipped; AGENTS.md is the committed one)
|
|
31
|
+
CLAUDE.md
|
|
32
|
+
|
|
33
|
+
# Editors
|
|
34
|
+
.vscode/
|
|
35
|
+
.idea/
|
|
36
|
+
|
|
37
|
+
# OS junk
|
|
38
|
+
.DS_Store
|
|
39
|
+
Thumbs.db
|
|
40
|
+
desktop.ini
|
|
41
|
+
|
|
42
|
+
# Coverage / other test tooling
|
|
43
|
+
.coverage
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
|
|
48
|
+
.env
|
htmlsift-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# AGENTS.md — htmlsift
|
|
2
|
+
|
|
3
|
+
## What this is
|
|
4
|
+
|
|
5
|
+
A pip-installable web main-content extractor. HTML string in, clean
|
|
6
|
+
text / HTML / markdown out, using the trained htmlsift models. Apache-2.0.
|
|
7
|
+
This is the production inference package; model training and reproduction
|
|
8
|
+
live in the separate research repo (see Resources).
|
|
9
|
+
|
|
10
|
+
Two modes:
|
|
11
|
+
- `mini` (default) — int8 ONNX, CPU, torch-free. `pip install htmlsift`
|
|
12
|
+
- `base` — 311M torch encoder, GPU-capable. `pip install htmlsift[full]`
|
|
13
|
+
|
|
14
|
+
Model weights are not in the repo. They are fetched from the Hugging Face
|
|
15
|
+
Hub on first use, pinned by commit SHA per release (see
|
|
16
|
+
`src/htmlsift/_artifacts.py`).
|
|
17
|
+
|
|
18
|
+
## Licence and dependencies
|
|
19
|
+
|
|
20
|
+
Apache-2.0. Rendering and serialization are lxml-only, and the package
|
|
21
|
+
keeps its dependency tree free of GPL-licensed code — that is what lets it
|
|
22
|
+
stay Apache-2.0. Changes that pull in a GPL dependency (for example
|
|
23
|
+
`html2text`) won't be accepted into the project.
|
|
24
|
+
|
|
25
|
+
## Layout
|
|
26
|
+
|
|
27
|
+
- `src/htmlsift/` — the package. Public API in `extractor.py`
|
|
28
|
+
(`Extractor`, `extract`); model assembly in `loader.py`; bundle fetch
|
|
29
|
+
in `_artifacts.py`; CLI in `cli.py`.
|
|
30
|
+
- `src/htmlsift/core/` — the pipeline: parse/render, prep, features,
|
|
31
|
+
inference (`onnx_infer.py` for mini, `torch_infer.py` for base).
|
|
32
|
+
- `tests/` — golden and unit tests.
|
|
33
|
+
|
|
34
|
+
## Working with the code
|
|
35
|
+
|
|
36
|
+
- Backends are imported lazily, so a default install never loads torch;
|
|
37
|
+
the torch/transformers imports live in `core/torch_infer.py`.
|
|
38
|
+
- Lint: `ruff check src tests`
|
|
39
|
+
- Test: `pytest -q`. Model golden tests skip unless `HTMLSIFT_BUNDLE`
|
|
40
|
+
points at a local bundle (e.g. `localbundle/mini`).
|
|
41
|
+
|
|
42
|
+
## Resources
|
|
43
|
+
|
|
44
|
+
- `htmlsift-research` — training, evaluation, and reproduction:
|
|
45
|
+
https://github.com/koivualeksi/htmlsift-research
|
htmlsift-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
htmlsift-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: htmlsift
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Main-content extraction for web pages
|
|
5
|
+
Project-URL: Repository, https://github.com/koivualeksi/htmlsift
|
|
6
|
+
Author-email: Aleksi Koivu <koivu.aleksi@gmail.com>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: boilerplate-removal,content-extraction,html,main-content,web-scraping
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: huggingface-hub
|
|
20
|
+
Requires-Dist: lxml
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: onnxruntime
|
|
23
|
+
Requires-Dist: tokenizers
|
|
24
|
+
Provides-Extra: full
|
|
25
|
+
Requires-Dist: torch; extra == 'full'
|
|
26
|
+
Requires-Dist: transformers; extra == 'full'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# htmlsift
|
|
30
|
+
|
|
31
|
+
Web main-content extraction: HTML in, clean text / HTML / markdown out. A small model,
|
|
32
|
+
trained on [WebMainBench](https://github.com/opendatalab/WebMainBench), scores each rendered
|
|
33
|
+
line of a page as main content or boilerplate (nav, ads, cookie banners, and footers) and
|
|
34
|
+
returns just the content.
|
|
35
|
+
|
|
36
|
+
Apache-2.0. Full documentation, diagrams, and benchmarks:
|
|
37
|
+
https://github.com/koivualeksi/htmlsift
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install htmlsift # default: the mini model (CPU, ONNX)
|
|
43
|
+
pip install htmlsift[full] # adds the base 311M model (torch; GPU-capable)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `htmlsift` — the `mini` model only; a small install (onnxruntime + tokenizers + lxml +
|
|
47
|
+
numpy + huggingface-hub). First use downloads ~230 MB of model files.
|
|
48
|
+
- `htmlsift[full]` — adds `torch` + `transformers` to run `base`. First use of `base`
|
|
49
|
+
downloads ~1 GB.
|
|
50
|
+
|
|
51
|
+
Requires Python 3.10+. Model files download from the Hugging Face Hub on first use and are
|
|
52
|
+
cached; run `htmlsift download <mode>` to prefetch, or set `HF_HUB_OFFLINE=1` to run from
|
|
53
|
+
cache only.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from htmlsift import Extractor
|
|
59
|
+
|
|
60
|
+
ex = Extractor() # defaults to "mini"
|
|
61
|
+
ex.extract(html) # -> str (plain text)
|
|
62
|
+
ex.extract(html, output="html") # structure, links, images kept
|
|
63
|
+
ex.extract(html, output="markdown") # clean markdown: [text](url), 
|
|
64
|
+
ex.extract(html, with_blocks=True) # -> (blocks, probs)
|
|
65
|
+
|
|
66
|
+
import htmlsift
|
|
67
|
+
htmlsift.extract(html) # module-level convenience
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The larger model, from `htmlsift[full]`:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
ex = Extractor("base") # 311M encoder; GPU when present, else CPU (with a warning)
|
|
74
|
+
ex = Extractor("base", device="cuda") # require the GPU
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`mini` is CPU-only; only `base` runs on the GPU.
|
|
78
|
+
|
|
79
|
+
## Output modes
|
|
80
|
+
|
|
81
|
+
| `output` | what you get |
|
|
82
|
+
|---|---|
|
|
83
|
+
| `text` (default) | selected content as plain text |
|
|
84
|
+
| `html` | selected DOM, with structure / links / images kept |
|
|
85
|
+
| `markdown` | clean markdown, links and images preserved |
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0. Model weights are distributed separately, from the Hugging Face Hub.
|
htmlsift-0.1.0/README.md
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# htmlsift
|
|
2
|
+
|
|
3
|
+
Main-content extraction for web pages: hand it a raw HTML string and get back the main content
|
|
4
|
+
- nav, ads, cookie banners, and footers stripped
|
|
5
|
+
- outputs raw text, **HTML**, or **markdown**.
|
|
6
|
+
|
|
7
|
+
Two models shipped, both trained on [WebMainBench][wmb] (WMB) — 7,825 labelled pages, custom split
|
|
8
|
+
6,548 train / 732 val / 545 test:
|
|
9
|
+
|
|
10
|
+
- **`mini`** (default) - a small int8-ONNX model that runs on CPU. `pip install htmlsift`
|
|
11
|
+
- **`base`** - a 311M encoder, most accurate and GPU-capable. `pip install htmlsift[full]`
|
|
12
|
+
|
|
13
|
+
Each model is fully re-trainable with your own annotated data and the whole research suite is available at [htmlsift-research](https://github.com/koivualeksi/htmlsift-research)
|
|
14
|
+
|
|
15
|
+
[wmb]: https://github.com/opendatalab/WebMainBench
|
|
16
|
+
|
|
17
|
+
## Results
|
|
18
|
+
|
|
19
|
+
| model | desc | WMB test F1 | seeds | CPU (pages/s) | GPU (pages/s) | install |
|
|
20
|
+
|---|---|---|---|---|---|---|
|
|
21
|
+
| `base` | 311m-10 | **0.9311** | 3 | 0.4 | 24.6 | `htmlsift[full]` |
|
|
22
|
+
| unpublished | 97m-6, int8 QAT | 0.9256 | 3 | 0.9 | 30.2 | — |
|
|
23
|
+
| `mini` | int8 table | 0.9010 | 3 | **27.7** | — | `htmlsift` |
|
|
24
|
+
|
|
25
|
+
* GPU = RTX 4090
|
|
26
|
+
* CPU = Ryzen 5 3600 single thread
|
|
27
|
+
|
|
28
|
+
### On CPU
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
One CPU core, WMB test (544 pages), extraction only. `mini` gets close to trafilatura's
|
|
33
|
+
per-page time (36 vs 31 ms median) and scores ~15 F1 points higher. readability and resiliparse are faster but markedly less accurate.
|
|
34
|
+
|
|
35
|
+
### On GPU
|
|
36
|
+
|
|
37
|
+

|
|
38
|
+
|
|
39
|
+
RTX 4090, WMB test (544 pages). `base` with band attention sustains 24.6 pages/s against
|
|
40
|
+
MinerU-HTML v1.1's 1.16. A 21x gap at matched accuracy (F1 0.9311 vs 0.9306).
|
|
41
|
+
|
|
42
|
+
### Cross benchmark accuracy
|
|
43
|
+
|
|
44
|
+
The shipped models are trained on WMB, so WMB is in-domain. The other two columns are
|
|
45
|
+
**zero-shot**, the model never saw WCXB or the multilingual DAnIEL in training. Each column is
|
|
46
|
+
scored with that benchmark's own metric.
|
|
47
|
+
|
|
48
|
+
| model | WMB (ROUGE-5) | WCXB (word-F1, zero-shot) | DAnIEL (ROUGE-L, zero-shot) |
|
|
49
|
+
|---|---|---|---|
|
|
50
|
+
| `base` (311m-10) | 0.9311 | 0.8633 | 0.9175 |
|
|
51
|
+
| `mini` (int8) | 0.9010 | 0.8474 | 0.8797 |
|
|
52
|
+
|
|
53
|
+
All results are 3-seed test means.
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install htmlsift # default: the mini model (CPU, ONNX)
|
|
59
|
+
pip install htmlsift[full] # adds the base 311M model (torch; GPU-capable)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- **`htmlsift`** — the `mini` model only; a small install (onnxruntime + tokenizers + lxml +
|
|
63
|
+
numpy + huggingface-hub). First use downloads ~230 MB of model files.
|
|
64
|
+
- **`htmlsift[full]`** — adds `torch` + `transformers` to run `base`. First use of `base`
|
|
65
|
+
downloads ~1 GB.
|
|
66
|
+
|
|
67
|
+
Requires Python 3.10+. Model files download from the Hugging Face Hub on first use and are
|
|
68
|
+
cached; prefetch with `htmlsift download mini` (or `base`), or set `HF_HUB_OFFLINE=1` to run
|
|
69
|
+
from cache only.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from htmlsift import Extractor
|
|
75
|
+
|
|
76
|
+
ex = Extractor() # defaults to "mini"
|
|
77
|
+
ex.extract(html) # -> str (plain text)
|
|
78
|
+
ex.extract(html, output="html") # keep structure, links, images
|
|
79
|
+
ex.extract(html, output="markdown") # clean markdown: [text](url), 
|
|
80
|
+
ex.extract(html, with_blocks=True) # -> (blocks, probs) for callers who want each line and its prediction individually
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Module-level convenience (cached singleton):
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import htmlsift
|
|
87
|
+
htmlsift.extract(html) # default mini
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The larger model, from the `[full]` install:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
ex = Extractor("base") # 311M encoder; uses the GPU when one is present,
|
|
94
|
+
# else CPU (with a warning)
|
|
95
|
+
ex = Extractor("base", device="cuda") # require the GPU (errors if none is available)
|
|
96
|
+
ex = Extractor("base", device="cpu", threads=4) # force CPU; `threads` sets parallelism
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`mini` is CPU-only (int8 ONNX); asking it for a GPU raises. Only `base` runs on the GPU.
|
|
100
|
+
|
|
101
|
+
### Example
|
|
102
|
+
|
|
103
|
+
Nearly 1 MB of Wikipedia HTML ([Photosynthesis](https://en.wikipedia.org/wiki/Photosynthesis))
|
|
104
|
+
in — the boilerplate (nav, sidebar, citations, footer) dropped, the article kept. The verbatim
|
|
105
|
+
head of the markdown (`mini` and `base` return the same here):
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
md = Extractor().extract(html, output="markdown")
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```markdown
|
|
112
|
+
# Photosynthesis
|
|
113
|
+
|
|
114
|
+
From Wikipedia, the free encyclopedia
|
|
115
|
+
|
|
116
|
+
For other uses, see [Photosynthesis (disambiguation)](https://en.wikipedia.org/wiki/Photosynthesis_(disambiguation)).
|
|
117
|
+
|
|
118
|
+
Schematic of photosynthesis in plants. The [carbohydrates](https://en.wikipedia.org/wiki/Carbohydrate) produced are stored in or used by the plant.
|
|
119
|
+
|
|
120
|
+
Composite image showing the global distribution of photosynthesis, including both oceanic [phytoplankton](https://en.wikipedia.org/wiki/Phytoplankton) and terrestrial [vegetation](https://en.wikipedia.org/wiki/Vegetation). Dark red and blue-green indicate regions of high photosynthetic activity in the ocean and on land, respectively.
|
|
121
|
+
|
|
122
|
+
**Photosynthesis** is a [system](https://en.wikipedia.org/wiki/Biological_system) of [biological processes](https://en.wikipedia.org/wiki/Biological_process) by which [photopigment](https://en.wikipedia.org/wiki/Photopigment)-bearing [autotrophic](https://en.wikipedia.org/wiki/Autotroph) [organisms](https://en.wikipedia.org/wiki/Organism), such as most [plants](https://en.wikipedia.org/wiki/Plant), [algae](https://en.wikipedia.org/wiki/Algae) and [cyanobacteria](https://en.wikipedia.org/wiki/Cyanobacteria), convert light energy—typically from sunlight—into the chemical energy necessary to fuel their metabolism…
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Output modes
|
|
126
|
+
|
|
127
|
+
| `output` | what you get |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `text` (default) | selected content as plain text |
|
|
130
|
+
| `html` | selected DOM, with structure / links / images kept |
|
|
131
|
+
| `markdown` | clean markdown, links and images preserved |
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Concept
|
|
135
|
+
|
|
136
|
+
<details>
|
|
137
|
+
<summary><b>How it works</b></summary>
|
|
138
|
+
|
|
139
|
+
### Line level labeling
|
|
140
|
+

|
|
141
|
+
|
|
142
|
+
Most extractors decide keep-or-drop on HTML *elements*. htmlsift first renders the page to
|
|
143
|
+
markdown *lines*, then decides keep-or-drop on each line. The trade-off is in the figure above, a line-based ceiling sits below the element level gold ceiling but there are far fewer units to classify per page.
|
|
144
|
+
|
|
145
|
+
### HTML 'signals' utilized
|
|
146
|
+
|
|
147
|
+
- **Where it sits**: in the DOM - tag, nesting depth, whether it's inside a link.
|
|
148
|
+
- **What it says**: a multilingual embedding of the line's tokens.
|
|
149
|
+
- **The whole-page context**: repeated boilerplate only stands out in contrast to the rest
|
|
150
|
+
of the page, so every line is judged against all the others by a BiGRU.
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
Heuristic extractors carry the first one and a half of these; an LLM carries all three but
|
|
155
|
+
pays to generate the page token by token. htmlsift carries all three in one pass, and outputs predictions without needing a decoder.
|
|
156
|
+
|
|
157
|
+

|
|
158
|
+
|
|
159
|
+
Both tiers share the render, the per-line pooling, and the BiGRU head. They differ only in the text processing section
|
|
160
|
+
- mini converts text to tokens and mean-pools them, has no internal attention allowing fast CPU processing
|
|
161
|
+
- base uses granite r2 311m embedder using only first 10 layers requiring GPU for efficient usage
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
</details>
|
|
165
|
+
|
|
166
|
+
<details>
|
|
167
|
+
<summary><b>Training and retraining</b></summary>
|
|
168
|
+
|
|
169
|
+
Most of the accuracy arrives in the first few hundred labelled pages — the model learns a
|
|
170
|
+
benchmark's labelling policy quickly, so retraining on your own labels is cheap.
|
|
171
|
+
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+
These models were trained in the **htmlsift-research** repository. To reproduce the boards or
|
|
175
|
+
retrain on your own data, see [htmlsift-research](https://github.com/koivualeksi/htmlsift-research)
|
|
176
|
+
and its `docs/REPRODUCE.md`.
|
|
177
|
+
|
|
178
|
+
</details>
|
|
179
|
+
|
|
180
|
+
<details>
|
|
181
|
+
<summary><b>Known limits</b></summary>
|
|
182
|
+
|
|
183
|
+
A standalone hero image that is its own block renders to no text line, so it can't be selected
|
|
184
|
+
today. Inline images inside a kept block are preserved in `html` and `markdown`.
|
|
185
|
+
|
|
186
|
+
</details>
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
191
|
+
|
|
192
|
+
htmlsift does **not** depend on `html2text`, directly or transitively — rendering and
|
|
193
|
+
serialization are lxml-only, which is what keeps the licence clean. Model weights are
|
|
194
|
+
distributed separately, from the Hugging Face Hub.
|
|
195
|
+
|
|
196
|
+
## References
|
|
197
|
+
|
|
198
|
+
- **WMB — WebMainBench.** The training benchmark; ROUGE-5 main-content metric.
|
|
199
|
+
[opendatalab/WebMainBench](https://github.com/opendatalab/WebMainBench)
|
|
200
|
+
- **WCXB — Web Content Extraction Benchmark.** Foley, *WCXB: A Multi-Type Web Content Extraction
|
|
201
|
+
Benchmark*. [arXiv:2605.21097](https://arxiv.org/abs/2605.21097) ·
|
|
202
|
+
[repo](https://github.com/Murrough-Foley/web-content-extraction-benchmark)
|
|
203
|
+
- **DAnIEL.** Multilingual news corpus (Mutuvi et al.,
|
|
204
|
+
[LREC 2020](https://aclanthology.org/2020.lrec-1.509/)); main-content scoring follows
|
|
205
|
+
*Multilingual Evaluation of Main Content Extractors for Web Pages*, SIGIR 2025
|
|
206
|
+
([ACM](https://dl.acm.org/doi/10.1145/3726302.3730234)).
|
|
207
|
+
|