OpenWebMath: An Open Dataset of High-Quality Mathematical Web Text

Keiran Paster, Marco Dos Santos, Zhangir Azerbayev, Jimmy Ba

TL;DR

OpenWebMath is a new, open-source dataset containing 14.7 billion tokens of high-quality mathematical text scraped from the web. By using a custom pipeline to faithfully preserve LaTeX notation and filter for technical quality, the authors provide a public alternative to the proprietary datasets used to train reasoning giants like Google's Minerva. Models trained on this data significantly outperform general-purpose LLMs on quantitative reasoning, even when those general models are trained on 20x more data.

What Problem Does This Paper Address?

Large Language Models (LLMs) have shown a remarkable ability to reason, but this capability is heavily dependent on the quality of their pretraining data—specifically code and mathematics. While models like Minerva have achieved state-of-the-art results in quantitative reasoning, the datasets used to train them are proprietary.

Existing open-source web crawls, such as C4 or RefinedWeb, are "math-blind." Their preprocessing pipelines typically strip out LaTeX formatting or treat mathematical symbols as noise, resulting in a loss of the very structure required for a model to learn mathematical logic. The authors tackle the challenge of extracting, cleaning, and filtering mathematical content from the "messy" HTML of the open web to create a high-fidelity, large-scale dataset for the research community.

Methods

The authors developed a multi-stage pipeline to process 237 billion HTML pages from Common Crawl, as illustrated in the pipeline overview:

Figure 1: The pipeline for constructing OpenWebMath involves aggressive filtering so that the final dataset only contains high quality, English, and mathematical content.

Key technical contributions include:

  • High-Recall Prefiltering: To manage compute costs, they first scanned for 100 common LaTeX symbols and keywords (e.g., "mathjax", "katex") to reduce the document pool to less than 1% of the total crawl.
  • Custom LaTeX Extraction: Unlike standard tools that miss math embedded in non-standard ways, their pipeline handles math in image alt text, custom delimiters (like [tex]...[/tex]), and MathJax-rendered scripts.
  • MathScore Classifier: They trained a FastText classifier to predict if a document is "mathematical" based on surrounding text, even if the LaTeX itself was removed. This helped identify high-quality technical discussions that might have failed the initial extraction.
  • Quality Filtering & Deduplication: They used KenLM perplexity scores (trained on the technical ProofPile dataset) to remove low-quality text and employed SimHash for document-level deduplication.

Datasets

  • OpenWebMath: The primary contribution, consisting of 14.7B tokens across 6.3M documents.
  • Common Crawl: The raw source for the dataset.
  • ProofPile: An existing dataset of formal and informal math used here for training filters and as a baseline for comparison.
  • The Pile: A standard 800GB general-purpose dataset used as a baseline.
  • Benchmarks: Evaluation was performed on GSM8k (grade school math), MATH (competition-level problems), and LILA-multiarith.

Key Insights and Ideas

  • Math is Encoded Chaos: Mathematical notation on the web is not standardized. As shown in the figure below, it can be hidden in image URLs, special tags, or arbitrary delimiters. Standard NLP pipelines that ignore these nuances effectively "de-educate" the models they train. LaTeX formulas are embedded in HTML in many diverse ways, from image alt-text to special tags.

  • Domain Specificity Trumps Scale: A 1.4B parameter model trained on 14.7B tokens of OpenWebMath outperformed a similar model (Pythia) trained on 300B tokens of general text from The Pile. This suggests that for reasoning, what you read is far more important than how much you read.

  • Forums are Goldmines: 40% of the dataset comes from Q&A forums like StackExchange and PhysicsForums. These are particularly valuable because they contain natural language explanations paired with step-by-step mathematical logic. OpenWebMath is composed largely of forum posts and educational content, primarily focused on Mathematics and Physics.
Figure 3: LATEX formulas can be embedded in HTML documents in many ways, including in images, within arbitrary delimiters, and within special tags. Most common text-extraction pipelines do not extract LATEX code properly.
Figure 2: Left: The documents in OpenWebMath are sourced from forum posts, educational content, reference pages, scientific papers, blogs, and more. Most content comes from Q&A forums where users discuss how to solve problems. Right: The majority of the content in OpenWebMath is related to mathematics, but a large part is related to other technical subjects like Physics, Computer Science, Statistics, and more.

Key Results

The authors evaluated 1.4B parameter models trained on different data mixes:

  • Perplexity: Models trained on OpenWebMath achieved significantly lower (better) perplexity on the MATH benchmark (1.90 vs. 2.20 for The Pile).
  • Accuracy: On the "MATH Algebra-Easy" subset, the OpenWebMath model achieved 5.62% accuracy, doubling the 2.81% achieved by models trained on The Pile or ProofPile alone.
  • Synergy: A 50/50 mixture of OpenWebMath and ProofPile often yielded the best results, suggesting that diverse sources of technical text (web vs. papers/books) are complementary.

Limitations and Future Work

  • Language Bias: The current dataset is English-only. The authors acknowledge that their filtering stage likely discarded valuable mathematical documents in other languages.
  • Text-Only: While they extract math from image metadata, the dataset does not include the actual images/figures, which are often crucial for geometric or topological reasoning.
  • Pipeline Rigidity: Due to the high cost of processing Common Crawl, the authors could only run their pipeline once, meaning they couldn't perform an ablation study to see which specific filter was most effective.
  • Future Directions: The authors suggest that future work should focus on multimodal extraction (images + text) and expanding the pipeline to support non-English technical content.

Summary updated

Abstract

There is growing evidence that pretraining on high quality, carefully thought-out tokens such as code or mathematics plays an important role in improving the reasoning abilities of large language models. For example, Minerva, a PaLM model finetuned on billions of tokens of mathematical documents from arXiv and the web, reported dramatically improved performance on problems that require quantitative reasoning. However, because all known open source web datasets employ preprocessing that does not faithfully preserve mathematical notation, the benefits of large scale training on quantitive web documents are unavailable to the research community. We introduce OpenWebMath, an open dataset inspired by these works containing 14.7B tokens of mathematical webpages from Common Crawl. We describe in detail our method for extracting text and LaTeX content and removing boilerplate from HTML documents, as well as our methods for quality filtering and deduplication. Additionally, we run small-scale experiments by training 1.4B parameter language models on OpenWebMath, showing that models trained on 14.7B tokens of our dataset surpass the performance of models trained on over 20x the amount of general language data. We hope that our dataset, openly released on the Hugging Face Hub, will help spur advances in the reasoning abilities of large language models.
BibTeX
@inproceedings{paster2024openwebmath,
  author = {Keiran Paster and Marco Dos Santos and Zhangir Azerbayev and Jimmy Ba},
  title = {{OpenWebMath: An Open Dataset of High-Quality Mathematical Web Text}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=jKHmjlpViu},
}
Figure