Understanding HTML with Large Language Models

Izzeddin Gur, Ofir Nachum, Yingjie Miao, Mustafa Safdari, Austin V. Huang, Aakanksha Chowdhery, Sharan Narang, Noah Fiedel, Aleksandra Faust

TL;DR

This paper demonstrates that Large Language Models (LLMs) pretrained on standard natural language corpora are remarkably effective at understanding and interacting with raw HTML. By fine-tuning models like T5 and PaLM on web-based tasks, the researchers achieved state-of-the-art performance on autonomous web navigation—completing 50% more tasks than previous specialized models while requiring 192x less training data.

What Problem Does This Paper Address?

Automating web-based tasks, such as filling out forms or navigating complex sites, typically requires a model to understand the underlying HTML. Historically, researchers believed this necessitated specialized neural network architectures designed to handle HTML’s hierarchical tree structure (the Document Object Model, or DOM).

However, building these specialized models is expensive, requires domain-specific knowledge, and necessitates massive, task-specific datasets. The authors of this paper ask a fundamental question: Can general-purpose LLMs, which are mostly trained on plain text, "transfer" their reasoning capabilities to the structured, messy world of raw HTML?

Methods

The researchers took a "minimalist" approach, treating HTML not as a complex tree, but as a raw sequence of text tokens. Their methodology involved:

  • HTML Un-Parsing: Instead of complex preprocessing, they fed raw HTML snippets directly into the models.
  • Snippet Extraction: Because real-world HTML can be massive (exceeding the 2,000-token context window of many LLMs), they developed a heuristic to extract "snippets"—small sub-trees of HTML centered around a "salient element" (like a button or input field).
  • Architecture Comparison: They tested three types of architectures: Encoder-only (BERT), Encoder-Decoder (T5), and Decoder-only (PaLM, LaMDA).
Summary of tasks, datasets, and model architectures used in the study.

Datasets

The study utilized a mix of existing benchmarks and a newly created dataset:

  • MiniWoB: A standard benchmark for web navigation containing 62 different web applications.
  • Annotated Shopping Webpages: A dataset of 28,000 examples for semantic classification.
  • CommonCrawl (New): The authors introduced a new, large-scale dataset of 85,000 HTML snippets distilled from CommonCrawl. They used the HTML for attribute to automatically pair input elements with their corresponding labels, creating a high-quality benchmark for description generation.

Key Insights and Ideas

  • Pretraining is the Secret Sauce: LLMs pretrained on massive text corpora (which naturally includes some code and HTML) perform significantly better than models trained on HTML from scratch. The "common sense" and linguistic patterns learned from the web help the model infer the purpose of poorly structured HTML.
  • Bidirectional Attention Wins: Encoder-Decoder models (like T5) performed the best. The authors suggest this is because the bidirectional attention in the encoder allows the model to "look ahead" and "look back" across the HTML sequence, which is crucial for understanding elements whose labels might be far away in the code.
  • Extreme Sample Efficiency: The most surprising finding was that LLMs could beat the previous state-of-the-art (SOTA) on the MiniWoB benchmark using only 12,000 demonstrations, compared to the 2.4 million demonstrations used by previous specialized models.
  • Structure vs. Content: While specialized models focus on the structure (the DOM), LLMs excel at understanding the content and the relationship between text labels and functional elements.

Key Results

  • Navigation: On the MiniWoB benchmark, the fine-tuned WebN-T5-3B model achieved a success rate of ~52%, a massive leap over the previous best supervised model (~18%).
  • Classification: Fine-tuning an off-the-shelf LLM improved accuracy on semantic classification by over 12% compared to training the same architecture from scratch on HTML data alone.
  • Scaling: Performance scales sub-linearly with model size. While the 62B parameter PaLM model was the most accurate, smaller models like the 3B parameter T5 were surprisingly competitive, offering a better balance of performance and efficiency.
Comparison of success rates on MiniWoB, highlighting the sample efficiency of LLMs (12K demos) vs. previous specialized models (2.4M demos).

Limitations and Future Work

  • Context Window Constraints: Even with snippet extraction, the relatively short context windows of current LLMs (around 2,000 tokens in this study) limit the model's ability to see the "big picture" of a very large webpage.
  • Simulated vs. Real World: While the results on MiniWoB are impressive, the authors note that these are simulated environments. Real-world websites are significantly more complex, inconsistent, and dynamic.
  • Reinforcement Learning (RL): This paper focused on supervised learning (learning from demonstrations). The authors suggest that integrating these LLMs into an RL framework—where the model learns by trial and error on live websites—is a promising next step for creating truly autonomous web agents.

Summary updated

BibTeX
@inproceedings{gur2023understanding,
  author = {Izzeddin Gur and Ofir Nachum and Yingjie Miao and Mustafa Safdari and Austin V. Huang and Aakanksha Chowdhery and Sharan Narang and Noah Fiedel and Aleksandra Faust},
  title = {{Understanding HTML with Large Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.185},
}
Figure