Datasets:

Modalities:
Tabular
Text
Formats:
parquet
DOI:
Libraries:
Datasets
Dask
License:
File size: 12,013 Bytes
a7dd0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5110dc
a7dd0df
 
e5110dc
 
 
 
a0422cd
e5110dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7dd0df
 
 
e5110dc
 
a7dd0df
e5110dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8f233cf
60a94d6
e5110dc
 
 
 
 
 
 
 
 
 
 
ab30704
e5110dc
 
 
 
 
874ad80
e5110dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aa074c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
---
license: odc-by
dataset_info:
- config_name: finemath-3plus
  features:
  - name: url
    dtype: string
  - name: fetch_time
    dtype: int64
  - name: content_mime_type
    dtype: string
  - name: warc_filename
    dtype: string
  - name: warc_record_offset
    dtype: int32
  - name: warc_record_length
    dtype: int32
  - name: text
    dtype: string
  - name: token_count
    dtype: int32
  - name: char_count
    dtype: int32
  - name: metadata
    dtype: string
  - name: score
    dtype: float64
  - name: int_score
    dtype: int64
  - name: crawl
    dtype: string
  - name: snapshot_type
    dtype: string
  - name: language
    dtype: string
  - name: language_score
    dtype: float64
  splits:
  - name: train
    num_bytes: 137764105388.93857
    num_examples: 21405610
  download_size: 65039196945
  dataset_size: 137764105388.93857
- config_name: finemath-4plus
  features:
  - name: url
    dtype: string
  - name: fetch_time
    dtype: int64
  - name: content_mime_type
    dtype: string
  - name: warc_filename
    dtype: string
  - name: warc_record_offset
    dtype: int32
  - name: warc_record_length
    dtype: int32
  - name: text
    dtype: string
  - name: token_count
    dtype: int32
  - name: char_count
    dtype: int32
  - name: metadata
    dtype: string
  - name: score
    dtype: float64
  - name: int_score
    dtype: int64
  - name: crawl
    dtype: string
  - name: snapshot_type
    dtype: string
  - name: language
    dtype: string
  - name: language_score
    dtype: float64
  splits:
  - name: train
    num_bytes: 39101488149.09091
    num_examples: 6699493
  download_size: 18365184633
  dataset_size: 39101488149.09091
- config_name: infiwebmath-3plus
  features:
  - name: url
    dtype: string
  - name: metadata
    dtype: string
  - name: score
    dtype: float64
  - name: int_score
    dtype: int64
  - name: token_count
    dtype: int64
  - name: char_count
    dtype: int64
  - name: text
    dtype: string
  splits:
  - name: train
    num_bytes: 96485696853.10182
    num_examples: 13882669
  download_size: 46808660851
  dataset_size: 96485696853.10182
- config_name: infiwebmath-4plus
  features:
  - name: url
    dtype: string
  - name: metadata
    dtype: string
  - name: score
    dtype: float64
  - name: int_score
    dtype: int64
  - name: token_count
    dtype: int64
  - name: char_count
    dtype: int64
  - name: text
    dtype: string
  splits:
  - name: train
    num_bytes: 40002719500.1551
    num_examples: 6296212
  download_size: 19234328998
  dataset_size: 40002719500.1551
configs:
- config_name: finemath-3plus
  data_files:
  - split: train
    path: finemath-3plus/train-*
- config_name: finemath-4plus
  data_files:
  - split: train
    path: finemath-4plus/train-*
- config_name: infiwebmath-3plus
  data_files:
  - split: train
    path: infiwebmath-3plus/train-*
- config_name: infiwebmath-4plus
  data_files:
  - split: train
    path: infiwebmath-4plus/train-*
---

# 📐 FineMath


![image/png](https://cdn-uploads.huggingface.co/production/uploads/61c141342aac764ce1654e43/0GAdY8wZx6bGtUzqX4Lvi.png)

## What is it?

📐 FineMath consists of **34B tokens** (FineMath-3+) and **54B tokens** (FineMath-3+ with InfiMM-WebMath-3+) of mathematical educational content filtered from CommonCrawl. To curate this dataset, we trained a mathematical content [classifier](https://huggingface.co/HuggingFaceTB/finemath-classifier) using annotations generated by LLama-3.1-70B-Instruct. We used the classifier to retain only the most educational mathematics content, focusing on clear explanations and step-by-step problem solving rather than advanced academic papers.

The [Dataset Curation](#dataset-curation) section details the process for creating the dataset.

<img src="assets/train_curves.png" width="800"/>

## What is being released?

The dataset is released in two versions:
- **FineMath-3+**: 34B tokens, 21.4M documents containing mathematical reasoning and problem solving, formatted with Markdown and LaTeX.  
- **FineMath-4+** (a subset of FineMath-3+): 9.6B tokens, 6.7M documents of higher quality with detailed explanations. Models trained on this dataset perform better on GSM8k and MATH.

<!-- (the image looks kinda meh) <img src="assets/stats.png" width="512"/> -->

We also release a filtered English text-only portion of the **[InfiMM-WebMath-40B](https://huggingface.co/datasets/Infi-MM/InfiMM-WebMath-40B)** dataset, classified using the same approach as FineMath:
- **InfiMM-WebMath-3+**: 20.5B tokens, 13.9M documents.
- **InfiMM-WebMath-4+** (a subset of InfiMM-WebMath-3+): 8.5B tokens, 6.3M documents.

## How to load the dataset

Use one of the available configs: `finemath-3plus`, `finemath-4plus`, `infiwebmath-3plus`, or `infiwebmath-4plus`.

```python
from datasets import load_dataset

# Load the high-quality subset
data = load_dataset("HuggingFaceTB/finemath", "finemath-4plus", split="train", num_proc=8)

# Or load the larger subset
data = load_dataset("HuggingFaceTB/finemath", "finemath-3plus", split="train", num_proc=8)
```

## Dataset curation

Recent language models like DeepSeekMath and MathStral have demonstrated strong mathematical capabilities, trained on specialized datasets that aren't publicly available. We developed a pipeline to identify and extract high-quality mathematical content from CommonCrawl, with several iterations of refinement to improve quality.

### Phase 1: Initial content extraction and classification
We began by re-extracting pages from CommonCrawl WARCs using URLs from the FineWeb dataset, collecting both the latest and largest versions of each page to capture the evolution of pages across the years. 
Unlike FineWeb which uses Trafilatura, we employed Resiliparse for text extraction as it better preserves forum discussions and QA answers that often contain crucial reasoning steps and solutions.

For initial quality assessment, we used [Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-70B-Instruct) to generate annotations on a 3-point scale:
1. Contains general mathematical content
2. Shows logical reasoning in mathematical context
3. Contains clear step-by-step solutions at appropriate level

A `multilingual-e5-small`-based classifier finetuned on these annotations was used to score the initial corpus. 
However, this first version performed below the OpenWebMath baseline, leading to several important refinements.

### Phase 2: Recalling more candidate pages
Analysis revealed that FineWeb's C4 filter removes pages containing '{' characters, inadvertently filtering out content with LaTeX notation. To address this and expand coverage, we:

1. Identified promising website domains by selecting those where at least 10% of pages received a classifier score ≥ 2
2. Added URLs from OpenWebMath and InfiMM-WebMath datasets
3. Recovered URLs of pages filtered by FineWeb's '{' rule from its rejection logs
4. Re-extracted all content from scratch using the [OpenWebMath pipeline](https://github.com/keirp/OpenWebMath), which properly handles mathematical notation across various HTML markup formats and standardizes them to LaTeX

### Phase 3: Refined quality assessment
The expanded corpus underwent a more fine-grained quality evaluation:

Once again, we used LLama-3.1-70B-Instruct to score a sample of newly extracted pages on a 5-point scale (full prompt available in [here](assets/prompt.txt)):
We finetuned a new [classifier](https://huggingface.co/HuggingFaceTB/finemath-classifier) on these annotations and scored the entire corpus.
After leaving only pages with a score of 3 or higher, and deduplicating the samples using simple single-band MinHash-LSH, we obtained FineMath-3+ with 34B tokens.

The same classifier was applied to InfiMM-WebMath's text content, focusing more on reasoning rather than advanced mathematics.

Both datasets were additionally filtered using FineWeb's language classification pipeline to remove non-English content.

### Decontamination
Following Qwen2.5-Math's approach, we removed samples with 13-gram overlaps against test sets from GSM8k, MATH, MMLU and ARC. Decontamination logs are available at [HuggingFaceTB/finemath_contamination_report](https://huggingface.co/datasets/HuggingFaceTB/finemath_contamination_report).

## Results and Performance

<img src="assets/eval_bar.png" width="600"/>

Our evaluations show several key findings:

1. FineMath-3+ outperforms the base InfiWebMath on GSM8k and MATH benchmarks
2. FineMath-4+ demonstrates superior performance compared to both FineMath-3+ and InfiWebMath-4+ on GSM8k and MATH
3. Combining the datasets (50% FineMath-3+ with 50% InfiWebMath-3+) yields approximately 50B tokens while matching the performance of FineMath-3+
4. Deduplicating the pages repeated between FineMath and InfiWebMath reduces performance compared to a non-deduplicated combination

## Dataset Schema

```python
{
    'url': string,               # Source page URL
    'fetch_time': int64,         # Crawler timestamp
    'content_mime_type': string, # MIME type
    'warc_filename': string,     # Common Crawl WARC source file
    'warc_record_offset': int32, # WARC record offset, in bytes
    'warc_record_length': int32, # WARC record size, in bytes
    'text': string,             # Page content
    'token_count': int32,       # Number of Llama tokens
    'char_count': int32,        # Character count
    'metadata': string,         # Additional OpenWebMath metadata
    'score': float64,           # Raw quality score
    'int_score': int64,         # Integer quality score
    'crawl': string,            # Common Crawl crawl identifier
    'snapshot_type': string,    # Whether the page is the latest or the largest for this URL
    'language': string,         # Document language
    'language_score': float64   # LangID probability
}
```

## Considerations for Using the Data

### Social Impact of Dataset
With the release of this dataset, we aim to make high-quality mathematical educational content more accessible to the machine learning community. While multiple language models have demonstrated strong mathematical capabilities, the datasets used to train these capabilities are often not publicly available. By releasing FineMath, we hope to:
- Make the dataset creation process more transparent
- Reduce the barrier to entry for training models with strong mathematical capabilities
- Provide a benchmark for mathematical content quality filtering

### Discussion of Biases
The dataset may have certain inherent biases:
- Focus on English language content
- Emphasis on popular educational approaches to mathematics
- Bias towards certain types of mathematical notation and formatting

### Other Known Limitations
- The dataset is limited to English language content
- The filtering criteria may not capture advanced mathematical content (e.g. advanced research subjects)
- Some mathematical notation (e.g. image-based) may not be preserved
- Long-form content may have varying quality even within high-scoring documents

## Licensing Information
The dataset is released under the **Open Data Commons Attribution License (ODC-By) v1.0** [license](https://opendatacommons.org/licenses/by/1-0/). The use of this dataset is also subject to [CommonCrawl's Terms of Use](https://commoncrawl.org/terms-of-use).

## Future work
There are several avenues for future work:
- Expand language coverage beyond English
- Improve mathematical notation extraction and preservation
- Develop more sophisticated quality metrics
- Create specialized subsets for different educational levels

### Citation Information

```
@misc{lozhkov2024finemath,  
    author       = { Lozhkov, Anton and Ben Allal, Loubna and Bakouch, Elie and von Werra, Leandro and Wolf, Thomas },  
    title        = { FineMath: the Finest Collection of Mathematical Content }, 
    year         = 2024,  
    url          = { https://huggingface.co/datasets/HuggingFaceTB/finemath },  
    doi          = { 10.57967/hf/3847 },
	publisher    = { Hugging Face }
}

```