Feature Extraction
Transformers
Safetensors
modernbert
html
document-embedding
text-embeddings-inference
Instructions to use Seznam/html-lm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Seznam/html-lm with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Seznam/html-lm")# Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("Seznam/html-lm") model = AutoModel.from_pretrained("Seznam/html-lm", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,24 +10,22 @@ pipeline_tag: feature-extraction
|
|
| 10 |
|
| 11 |
# HTML-LM
|
| 12 |
|
| 13 |
-
HTML-LM is a compact encoder model designed to generate general-purpose embeddings for HTML web pages, capturing both textual content and HTML structure. The embeddings can be used as inputs to lightweight downstream models for various classification and regression tasks
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
* **Explicit content classification** — determine whether a page contains explicit or adult content.
|
| 18 |
-
* **Article-page detection** — identify whether a webpage is primarily an article or editorial content.
|
| 19 |
-
* **Product-page detection** — determine whether a page represents a product or e-commerce listing.
|
| 20 |
-
* **Page clustering** — group similar webpages based on their content and structure.
|
| 21 |
-
* **Page-quality regression** — estimate the overall quality and usefulness of a webpage.
|
| 22 |
-
* **Web-spam detection** — estimate the level of spam or low-quality content on a page.
|
| 23 |
-
* **Other** — HTML-LM representations can be reused for many other web-document understanding tasks, including **classification, regression, clustering, and other downstream applications**.
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
## Model details
|
| 27 |
|
| 28 |
| Property | Value |
|
| 29 |
| --------------- | -------------- |
|
| 30 |
-
| Architecture | ModernBERT
|
| 31 |
| Parameters | 154M |
|
| 32 |
| Hidden size | 768 |
|
| 33 |
| Layers | 22 |
|
|
@@ -39,7 +37,7 @@ The model was trained from scratch for one pass over the training corpus using a
|
|
| 39 |
|
| 40 |
* Masked Language Modeling (MLM)
|
| 41 |
* Bag-of-Words prediction from `[CLS]`
|
| 42 |
-
* Contrastive distillation from Qwen3-Embedding-8B and SeLLMa 8B
|
| 43 |
|
| 44 |
## Training data
|
| 45 |
|
|
@@ -54,7 +52,7 @@ The corpus contains approximately:
|
|
| 54 |
|
| 55 |
## HTML preprocessing
|
| 56 |
|
| 57 |
-
HTML-LM expects
|
| 58 |
|
| 59 |
The included `HTMLLMProcessor` performs the following preprocessing steps:
|
| 60 |
|
|
@@ -65,10 +63,7 @@ The included `HTMLLMProcessor` performs the following preprocessing steps:
|
|
| 65 |
5. Simplifying the DOM hierarchy.
|
| 66 |
6. Normalizing whitespace.
|
| 67 |
|
| 68 |
-
The
|
| 69 |
-
|
| 70 |
-
> ⚠️ **Performance note:** The bundled processor may be slow out of the box for high-throughput or large-scale workloads. For improved performance, we recommend using it with `torch.utils.data.DataLoader` and setting `num_workers > 1`.
|
| 71 |
-
|
| 72 |
|
| 73 |
## Usage
|
| 74 |
|
|
@@ -82,10 +77,12 @@ from transformers import AutoModel, AutoProcessor
|
|
| 82 |
|
| 83 |
model_id = "Seznam/html-lm"
|
| 84 |
|
|
|
|
| 85 |
processor = AutoProcessor.from_pretrained(
|
| 86 |
model_id,
|
| 87 |
trust_remote_code=True,
|
| 88 |
)
|
|
|
|
| 89 |
model = AutoModel.from_pretrained(model_id).to("cuda")
|
| 90 |
model.eval()
|
| 91 |
|
|
@@ -112,6 +109,12 @@ document_embeddings = outputs.last_hidden_state[:, 0, :]
|
|
| 112 |
|
| 113 |
print(document_embeddings.shape)
|
| 114 |
# torch.Size([1, 768])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
```
|
| 116 |
|
| 117 |
## Performance
|
|
@@ -140,11 +143,24 @@ from transformers import AutoProcessor
|
|
| 140 |
|
| 141 |
model_id = "Seznam/html-lm"
|
| 142 |
|
|
|
|
| 143 |
processor = AutoProcessor.from_pretrained(
|
| 144 |
model_id,
|
| 145 |
trust_remote_code=True,
|
| 146 |
)
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
```
|
| 149 |
|
| 150 |
### Faster Preprocessing
|
|
@@ -255,4 +271,4 @@ If you use HTML-LM, please cite:
|
|
| 255 |
|
| 256 |
## Acknowledgements
|
| 257 |
|
| 258 |
-
HTML-LM was developed by the **Seznam.cz Research team** as part of the HTML-LM project.
|
|
|
|
| 10 |
|
| 11 |
# HTML-LM
|
| 12 |
|
| 13 |
+
HTML-LM is a compact encoder model designed to generate general-purpose embeddings for HTML web pages, capturing both textual content and HTML structure. The embeddings can be used as inputs to lightweight downstream models for various classification and regression tasks.
|
| 14 |
|
| 15 |
+
HTML-LM representations can be reused across a **wide range of downstream applications**, supporting tasks such as **classification, regression, clustering, and broader web-document understanding**. Specifically, we use them for:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
* **Explicit content classification** — determining whether a webpage contains explicit or adult content.
|
| 18 |
+
* **Article-page detection** — identifying whether a webpage primarily contains article or editorial content.
|
| 19 |
+
* **Product-page detection** — determining whether a webpage represents a product or e-commerce listing.
|
| 20 |
+
* **Page clustering** — grouping webpages with similar content and structural characteristics.
|
| 21 |
+
* **Page-quality regression** — estimating the overall quality and usefulness of a webpage.
|
| 22 |
+
* **Web-spam detection** — estimating the degree of spam or low-quality content on a webpage.
|
| 23 |
|
| 24 |
## Model details
|
| 25 |
|
| 26 |
| Property | Value |
|
| 27 |
| --------------- | -------------- |
|
| 28 |
+
| Architecture | [ModernBERT](https://huggingface.co/answerdotai/ModernBERT-base) |
|
| 29 |
| Parameters | 154M |
|
| 30 |
| Hidden size | 768 |
|
| 31 |
| Layers | 22 |
|
|
|
|
| 37 |
|
| 38 |
* Masked Language Modeling (MLM)
|
| 39 |
* Bag-of-Words prediction from `[CLS]`
|
| 40 |
+
* Contrastive distillation from [Qwen3-Embedding-8B](https://huggingface.co/Qwen/Qwen3-Embedding-8B) and [Seznam SeLLMa 8B](https://blog.seznam.cz/2024/10/diana-hlavacova-sellma-aneb-jak-v-seznamu-krotime-drave-jazykove-modely/)
|
| 41 |
|
| 42 |
## Training data
|
| 43 |
|
|
|
|
| 52 |
|
| 53 |
## HTML preprocessing
|
| 54 |
|
| 55 |
+
> ⚠️ HTML-LM expects HTML documents to be preprocessed in a specific way, which is handled by the bundled AutoProcessor.from_pretrained("Seznam/html-lm").
|
| 56 |
|
| 57 |
The included `HTMLLMProcessor` performs the following preprocessing steps:
|
| 58 |
|
|
|
|
| 63 |
5. Simplifying the DOM hierarchy.
|
| 64 |
6. Normalizing whitespace.
|
| 65 |
|
| 66 |
+
> **Performance note:** The bundled processor may be slow out of the box for high-throughput or large-scale workloads. For improved performance, we recommend using it with `torch.utils.data.DataLoader` and setting `num_workers > 1`. See the example below.
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
## Usage
|
| 69 |
|
|
|
|
| 77 |
|
| 78 |
model_id = "Seznam/html-lm"
|
| 79 |
|
| 80 |
+
# <class 'transformers_modules.hf.processor.HTMLLMProcessor'>
|
| 81 |
processor = AutoProcessor.from_pretrained(
|
| 82 |
model_id,
|
| 83 |
trust_remote_code=True,
|
| 84 |
)
|
| 85 |
+
# <class 'transformers.models.modernbert.modeling_modernbert.ModernBertModel'>
|
| 86 |
model = AutoModel.from_pretrained(model_id).to("cuda")
|
| 87 |
model.eval()
|
| 88 |
|
|
|
|
| 109 |
|
| 110 |
print(document_embeddings.shape)
|
| 111 |
# torch.Size([1, 768])
|
| 112 |
+
|
| 113 |
+
print(document_embeddings)
|
| 114 |
+
# tensor([[-2.0882e-01, 9.9287e-01, -1.0417e+00, 9.4297e-01, -8.4005e-01,
|
| 115 |
+
# 1.1509e+00, 8.4631e-01, -3.2688e-01, 7.1889e-01, 3.8875e-02,
|
| 116 |
+
# ...
|
| 117 |
+
# -2.9921e-01, -1.0583e+00, 1.4555e+00]], device='cuda:0')
|
| 118 |
```
|
| 119 |
|
| 120 |
## Performance
|
|
|
|
| 143 |
|
| 144 |
model_id = "Seznam/html-lm"
|
| 145 |
|
| 146 |
+
# <class 'transformers_modules.hf.processor.HTMLLMProcessor'>
|
| 147 |
processor = AutoProcessor.from_pretrained(
|
| 148 |
model_id,
|
| 149 |
trust_remote_code=True,
|
| 150 |
)
|
| 151 |
+
|
| 152 |
+
html = """
|
| 153 |
+
<html>
|
| 154 |
+
<body>
|
| 155 |
+
<div></div>
|
| 156 |
+
<h1 class='big'>Example</h1>
|
| 157 |
+
<p class='small'>Some article text.</p>
|
| 158 |
+
</body>
|
| 159 |
+
</html>
|
| 160 |
+
"""
|
| 161 |
+
|
| 162 |
+
print(processor.preprocess_html(html))
|
| 163 |
+
# <html><body><h1>Example</h1><p>Some article text.</p></body></html>
|
| 164 |
```
|
| 165 |
|
| 166 |
### Faster Preprocessing
|
|
|
|
| 271 |
|
| 272 |
## Acknowledgements
|
| 273 |
|
| 274 |
+
HTML-LM was developed by the **Seznam.cz Research team** as part of the HTML-LM project.
|