DOM-LM: Learning Generalizable Representations for HTML Documents

Xiang Deng, Prashant Shiralkar, Colin Lockard, Binxuan Huang, Huan Sun

Introduction

The modern web is a vast repository of semi-structured information encoded in HTML. While humans easily navigate these pages using visual cues and structural hierarchies, automated systems often struggle. Traditional approaches typically fall into two categories: text-only methods that flatten the document into a sequence of words, losing vital structural context, and visual methods that render pages to use computer vision, which are computationally expensive and slow.

DOM-LM addresses this gap by jointly encoding textual content and the underlying Document Object Model (DOM) structure. By treating the DOM tree as the primary source of semantics, DOM-LM achieves high performance without the overhead of full visual rendering.

Figure 1: Comparison of visual layout (a-c), raw text (d), and HTML source (e). Structural semantics are often lost in plain text representations.

Methodology

DOM-LM extends the Transformer architecture to be "structure-aware" through several key innovations:

Structure-Aware Encoding

To capture the hierarchical nature of HTML, DOM-LM utilizes a multi-dimensional position embedding. Every token is assigned a 6D embedding representing its node index, parent node index, index within siblings, depth in the DOM tree, HTML tag type, and sequential token position. This allows the model to distinguish between text in a header versus text in a table cell, even if the words are identical.

Subtree Processing

Given the massive size of many HTML documents, DOM-LM employs a sliding window algorithm to decompose the DOM tree into overlapping subtrees. This ensures that the model processes manageable chunks of data while preserving sufficient structural context for accurate inference.

Node-Level Masking

In addition to standard Masked Language Modeling (MLM), DOM-LM introduces a node-level masking pre-training strategy. By masking entire DOM nodes and requiring the model to reconstruct them, the model learns the "grammar" of web design and the relationships between different layout components.

Figure 2: The DOM-LM framework, illustrating the structure-aware encoder and the node-level masking pre-training tasks.

Experimental Evaluation

The researchers evaluated DOM-LM across three diverse benchmarks: the SWDE dataset for attribute extraction, the WebSRC dataset for structural Question Answering (QA), and a new Movie-Music dataset containing nearly 3,000 pages from 96 websites with diverse, real-world layouts.

Key Results

DOM-LM demonstrated superior performance, particularly in data-scarce scenarios:

  • Attribute Extraction: Achieved a 94.2 F1 score on SWDE with only 10 training pages per site.
  • Open Information Extraction: Outperformed the Ceres baseline by 24 F1 points in few-shot settings.
  • Question Answering: Surpassed strong visual-feature-based baselines on WebSRC by 7.6 exact match points, suggesting that structural data can effectively substitute for visual rendering.

Conclusion

DOM-LM proves that the structural signals inherent in HTML are critical for deep document understanding. By integrating these signals into a transformer-based architecture, the model achieves state-of-the-art results in attribute extraction and QA while remaining more efficient than visual-based alternatives. Future work will explore incorporating fine-grained CSS information and scaling pre-training to larger web crawls.

Summary updated

BibTeX
@misc{deng2022dom,
  author = {Xiang Deng and Prashant Shiralkar and Colin Lockard and Binxuan Huang and Huan Sun},
  title = {{DOM-LM: Learning Generalizable Representations for HTML Documents}},
  year = {2022},
  eprint = {2201.10608},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2201.10608},
}
Figure