Source-linked AI summary

ReaderLM-v2: Small Language Model for HTML to Markdown and JSON

Feng Wang, Zesheng Shi, Bo Wang, Nan Wang, Han Xiao

arXiv:2503.01151v1cs.CLcs.AIcs.IR

TL;DR

ReaderLM-v2 addresses the difficulty of extracting structured content from messy, long HTML under hallucination, context, and efficiency constraints. It fine-tunes a compact model with synthetic Draft-Refine-Critique data and four-stage training, achieving competitive or better extraction performance than larger models while remaining resource-efficient.

  • Problem

    Structured HTML extraction is challenged by hallucination, limited context windows, computational inefficiency, and messy or highly variable documents.

    Source: §1 · p. 2, §2 · p. 2
  • Method

    ReaderLM-v2 fine-tunes a 1.5 billion parameter model for Markdown and JSON extraction using Draft-Refine-Critique data and continued pretraining, SFT, DPO, and self-play tuning.

    Source: §1 · p. 2, §2 · p. 2, §3.2 · p. 5
  • Results

    ReaderLM-v2 achieves competitive or better performance than larger models, with significant gains on main Markdown extraction and remaining behind larger models on complex JSON extraction.

    Source: §1 · p. 2, §4.2 · p. 7, §4.3 · p. 8
  • Takeaways & Limitations

    ReaderLM-v2 offers a more resource-efficient solution for HTML-to-Markdown conversion, particularly main content extraction from long-context documents.

    Source: §6 · p. 9

Abstract

from arXiv · show

We present ReaderLM-v2, a compact 1.5 billion parameter language model designed for efficient web content extraction. Our model processes documents up to 512K tokens, transforming messy HTML into clean Markdown or JSON formats with high accuracy -- making it an ideal tool for grounding large language models. The model's effectiveness results from two key innovations: (1) a three-stage data synthesis pipeline that generates high quality, diverse training data by iteratively drafting, refining, and critiquing web content extraction; and (2) a unified training framework combining continuous pre-training with multi-objective optimization. Intensive evaluation demonstrates that ReaderLM-v2 outperforms GPT-4o-2024-08-06 and other larger models by 15-20\% on carefully curated benchmarks, particularly excelling at documents exceeding 100K tokens, while maintaining significantly lower computational requirements.

1 INTRODUCTION

ReaderLM-v2 targets accurate, scalable extraction of messy HTML into structured Markdown or JSON despite hallucination, context, efficiency, and deployment challenges. It combines a compact specialized model with iterative data synthesis and multi-stage training.

  • Structured extraction supports retrieval, matching, and knowledge grounding by converting unstructured data into formats usable by humans, machines, and LLMs.Source: §1 · p. 2
  • LLM-based extraction faces hallucination, limited context windows, computational inefficiency, and difficulty being hosted locally.Source: §1 · p. 2
  • ReaderLM-v2 is a 1.5 billion parameter model designed to transform messy HTML into JSON and Markdown.Source: §1 · p. 2
  • The training approach combines Draft-Refine-Critique data synthesis with continuous pre-training, supervised fine-tuning, DPO, and self-play iterative tuning.Source: §1 · p. 2

2 MODEL OBJECTIVES

ReaderLM-v2 addresses messy HTML, highly variable document lengths, inference bottlenecks, and training misalignment through long-context fine-tuning with dedicated Markdown and JSON extraction objectives.

  • Messy HTML contains legacy markup, JavaScript, comments, and CSS that complicate extraction and parsing.Source: §2 · p. 2
  • HTML documents have long-tail lengths, and current models can miss critical content in longer inputs.Source: §2 · p. 2
  • Long inputs can produce lengthy decoded outputs that create significant inference bottlenecks.Source: §2 · p. 2
  • Pre-trained LLMs are optimized for reasoning, coding, and mathematics rather than HTML content extraction and structuring.Source: §2 · p. 2
  • ReaderLM-v2 fine-tunes an under-2B-parameter SLM to support ideally 512K-token contexts for structured HTML extraction.Source: §2 · p. 2
  • The model targets instructed Markdown extraction and schema-guided JSON extraction as dedicated objectives.Source: §2 · p. 3

3 MULTI-STAGE DATA SYNTHESIS AND TRAINING PIPELINE

ReaderLM-v2 is improved through four sequential training stages that combine continued pretraining, synthetic-data SFT, DPO, and self-play iterative tuning.

  • The four-stage pipeline progresses from continued pretraining to SFT, DPO, and self-play iterative tuning.SFT and DPO use data generated through the Draft-Refine-Critique pipeline, while the final stage regenerates data from the Stage 3 checkpoint.Source: §3 · p. 3

3.1 DATASETS AND DATA SYNTHESIS

The data strategy combines a curated million-page dataset with Draft-Refine-Critique synthetic data because no public dataset directly supports these extraction tasks. The pipeline refines raw HTML into filtered instruction data, critique examples, and preference triplets.

3.1 DATASETS AND DATA SYNTHESIS

  • WebMarkdown-1M contains one million web pages converted to Markdown and JSON, supplemented with synthetic data because no suitable existing dataset supports the task.Source: §3.1 · p. 3

3.1.1 WEBMARKDOWN-1M

  • WebMarkdown-1M samples one million URLs from the top 500 Common Crawl domains and averages 56,000 tokens per document.English represents 62.7% of the dataset and Chinese 20%, together exceeding 80% collectively.Source: §3.1.1 · p. 3

3.1.2 SYNTHETIC DATA WITH DRAFT-REFINE-CRITIQUE

  • Draft-Refine-Critique generates synthetic training data because no public dataset directly supports HTML-to-Markdown or schema-guided HTML-to-JSON extraction.Source: §3.1.2 · p. 3
  • Drafting creates diverse but noisy outputs, refinement removes redundancy and enforces consistency, and critique judges quality against prompt requirements.Source: §3.1.2 · pp. 3–4
  • The pipeline produces 250,000 filtered instruction pairs, 100,000 critique examples, and 150,000 preference triplets.Source: §3.1.2 · pp. 4–5

3.2 TRAINING PIPELINE

ReaderLM-v2 uses an iterative four-stage training pipeline that progressively extends context, specializes extraction, learns output preferences, and refines itself through self-play.

3.2 TRAINING PIPELINE

  • Four stages combine continued pretraining, supervised fine-tuning, direct preference optimization, and self-play iterative tuning.Each stage uses a dedicated training process, culminating in another SFT and DPO cycle based on the Stage 3 checkpoint.Source: §3.2 · p. 5

3.2.1 STAGE 1: CONTINUED PRETRAINING

  • 256,000-token training sequences enable inference extrapolation up to 512,000 tokens through progressive context expansion and RoPE scaling.Training progresses through 32,768, 125,000, and 256,000 tokens while using a RoPE base frequency of 5,000,000.Source: §3.2.1 · p. 5

3.2.2 STAGE 2: SUPERVISED FINE-TUNING

  • Supervised fine-tuning trains four specialized checkpoints for HTML-to-Markdown and HTML-to-JSON data, then merges their parameters into one model.The approach separates data types to mitigate distribution conflicts and combines task-specific capabilities through weighted interpolation.Source: §3.2.2 · pp. 5–6

3.2.3 STAGE 3: DIRECT PREFERENCE OPTIMIZATION

  • DPO learns quality preferences from draft–refined output pairs generated by the Draft-Refine-Critique pipeline without manual annotations.The preference training uses 65K-token sequences and distinguishes higher-quality refined renderings from initial drafts.Source: §3.2.3 · p. 6

3.2.4 STAGE 4: SELF-PLAY ITERATIVE TUNING

  • Self-play regenerates SFT and DPO datasets from the Stage 3 checkpoint, creating a feedback loop that iteratively improves training data and performance.The model independently produces instructed Markdown/JSON data and preference data for subsequent training.Source: §3.2.4 · p. 6

4 EVALUATION

The evaluation uses manually verified HTML-to-Markdown and HTML-to-JSON test sets with task-specific metrics, comparing ReaderLM-v2 against proprietary and open-source baselines across training stages.

4.1 DATASET

  • 500 HTML-to-Markdown and 300 HTML-to-JSON documents form manually verified evaluation sets for content fidelity, syntax, and structure.Markdown checks preserve tags, text, and hierarchy, while JSON checks grammar, node content, and hallucination.Source: §4.1 · p. 6

4.2 INSTRUCTED MARKDOWN EXTRACTION

  • ReaderLM-v2 reaches Rouge-L 0.86, exceeding gpt-4o-2024-08-06 and gemini2-flash-expr at 0.69 and qwen2.5-32B-instruct at 0.71.This corresponds to reported gains of 24.6% over the first two baselines and 21.1% over Qwen2.5-32B-Instruct.Source: §4.2 · p. 7, Table 1 · p. 7
  • DPO drives the largest Markdown improvement, raising Rouge-L from 0.71 to 0.84 and Jaro-Winkler from 0.71 to 0.82.Levenshtein distance falls from 0.35 to 0.22, while Damerau distance decreases from 1300.20 to 1262.75.Source: §4.2 · p. 7
  • ReaderLM-v2 outperforms competitors on instructed Markdown extraction, but its smaller gains reveal size-related limitations relative to larger models.Larger models maintain more consistent performance across main-content and instruction-guided extraction.Source: §4.2 · p. 8

4.3 SCHEMA GUIDED JSON EXTRACTION

  • JSON extraction remains relatively stable across training stages, with DPO mainly improving reliability through higher pass rates.ReaderLM-v2 performs solidly despite 1.5 billion parameters but still trails larger models on this more complex task.Source: §4.3 · p. 8, Table 2 · p. 8

5 RELATED WORK

Related work spans traditional HTML extraction, modern LLM-based approaches, and synthetic-data methods, while emphasizing the need to control synthetic-data quality and relevance.

5.1 HTML UNDERSTANDING AND CONTENT EXTRACTION

  • Traditional HTML extraction relies on DOM trees, template detection, and heuristic filtering, whereas newer methods use LLMs and web-aware architectures.Recent systems include GPT-3 extraction, WebFormer, transfer from language pretraining, and HtmlRAG’s structure preservation.Source: §5.1 · pp. 8–9

5.2 SYNTHETIC DATA GENERATION

  • Synthetic data supports scalable training across translation, summarization, question answering, and structured text generation.Approaches include paraphrasing, backtranslation, noise injection, and language-model generation of structurally constrained text.Source: §5.2 · p. 9
  • Synthetic-data pipelines must balance scalability and customization against risks from noise and bias through validation and quality controls.The paper positions these controls as necessary for keeping generated data relevant to model improvement.Source: §5.2 · p. 9

6 CONCLUSION

ReaderLM-v2 shows that a compact model can perform competitive HTML-to-Markdown extraction on long-context documents, while larger models retain advantages on some complex tasks.

6 CONCLUSION

  • ReaderLM-v2 offers a resource-efficient solution for structured extraction from long-context documents, especially main-content HTML-to-Markdown conversion.The conclusion identifies future work in additional formats and modalities while preserving computational efficiency.Source: §6 · p. 9
Loading 2503.01151v1…