MarkupLM Baseline for News Attribute Extraction from HTML
This repository contains the fine-tuned MarkupLM baseline evaluated in the NewsXLM paper for news page HTML node classification. This version uses the original HTML text without translating it into English.
- Base model: MarkupLM base
- Fine-tuning dataset: NewsXLM
It labels HTML nodes as title, publication_date, text, author, tag, or none.
🚀 Usage
Installation
pip install -r requirements.txt
Prepare your HTML
html = '''
<html><body>
<nav><a>Home</a><a>News</a></nav>
<main><article>
<h1>Scientists discover new planet beyond our solar system</h1>
<div class="author"><span class="icon-user"></span>John Smith</div>
<time>November 3, 2026, 10:30 AM</time>
<div class="body">
<p>Scientists announced the discovery on Tuesday.</p>
<p>The planet is twice the size of Earth.</p>
</div>
<div>Tags: <a>Science</a><a>Space</a></div>
</article></main>
<footer>All rights reserved</footer>
</body></html>
'''
Attribute extraction
The extraction pipeline groups the results by attribute:
from transformers import pipeline
extractor = pipeline(
"extraction",
model="ispras-crawlers/newsxlm-markuplm-ae",
trust_remote_code=True,
)
extracted = extractor(html)
print(extracted)
Example result:
{
"title": ["Scientists discover new planet beyond our solar system"],
"publication_date": ["November 3, 2026, 10:30 AM"],
"text": ["Scientists announced the discovery on Tuesday.", ...],
"author": ["John Smith"],
"tag": ["Science", "Space"]
}
Node classification
The node-classification pipeline returns a prediction for each HTML node.
from transformers import pipeline
node_classifier = pipeline(
"node-classification",
model="ispras-crawlers/newsxlm-markuplm-ae",
trust_remote_code=True,
)
nodes = node_classifier(html)
print(nodes)
Example result:
{
"/html/body/main/article/h1": {
"pred": "title",
"probs": {
"title": 0.98,
"publication_date": 0.00,
"text": 0.00,
"author": 0.00,
"tag": 0.00,
"none": 0.02
},
"text": "Scientists discover new planet beyond our solar system"
}, ...
}
- The model supports tail granularity: text following an element is classified separately from the element's own text. Tail text is returned using the standard XPath suffix
/following-sibling::text()[1]. Paths refer to the cleaned DOM. - Both pipelines process chunks in batches of 32 by default to limit GPU memory use; set
chunk_batch_sizewhen creating the pipeline or calling it.
Raw model output
import torch
from transformers import AutoModelForTokenClassification, AutoProcessor
repo_id = "ispras-crawlers/newsxlm-markuplm-ae"
processor = AutoProcessor.from_pretrained(repo_id, trust_remote_code=True)
model = AutoModelForTokenClassification.from_pretrained(repo_id)
model.eval()
inputs = processor(html, return_tensors="pt")
with torch.inference_mode():
outputs = model(**inputs)
Citation
If you use NewsXLM in your research, please cite:
@article{newsxlm,
author = {Bedrin, P. A. and Varlamov, M. I. and Yatskov, A. K.},
title = {NewsXLM: A Multilingual Dataset and Model for Information Extraction from News Web Pages},
journal = {Proceedings of ISP RAS},
year = {2026},
volume = {38},
number = {2},
pages = {149--164},
doi = {10.15514/ISPRAS-2026-38(2)-10}
}