File size: 4,857 Bytes
e1cbc03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
task_categories:
- text-classification
- object-detection
language:
- en
size_categories:
- 10K<n<100K
---

# Mathematical Documents Dataset

This dataset contains 36,661 scientific documents with OCR-extracted text and mathematical content probability scores.
Documents were filtered from the **CommonCrawl PDF corpus** based on mathematical content probability.

## Quick Start

```python
from datasets import load_dataset
import json

# Load metadata
with open("metadata.jsonl") as f:
    for line in f:
        doc = json.loads(line)
        doc_id = doc['doc_id']
        
        # Read extracted text for each page
        # texts/{doc_id}/page_1.md, page_2.md, ...
        with open(f"texts/{doc_id}/page_1.md") as page:
            text = page.read()
            print(text)
        break
```

## Dataset Structure

```
math-docs-dataset/
├── metadata.jsonl           # Document metadata with probability scores
├── metadata_updated.jsonl   # Updated metadata (if applicable)
├── token_counts.jsonl       # Token counts per document
├── token_stats.json         # Aggregate token statistics
├── texts/                   # OCR-extracted text (2.5GB)
│   ├── {doc_id}/
│   │   ├── page_1.md
│   │   ├── page_2.md
│   │   └── ...
└── samples/                 # 50 sample documents for preview
    ├── pdfs/
    │   └── {doc_id}.pdf
    ├── texts/
    │   └── {doc_id}/
    └── sample_metadata.jsonl
```

## Statistics

- **Total documents**: 36,661
- **Total pages**: 885,333
- **Average pages per document**: 24.1
- **Mean probability range**: [0.8007, 1.0000]

### Token Statistics

- **Total tokens**: 756,843,504
- **Average tokens per document**: 20,644
- **Average tokens per page**: 854

Token counts calculated using tiktoken (cl100k_base encoding, GPT-4 tokenizer).

## Accessing Full PDFs

Due to size constraints, full PDF files (30+ GB) are hosted on Wasabi S3 storage.

### Download All PDFs

```bash
# Install AWS CLI if needed
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./aws/install -i ~/.local/aws-cli -b ~/.local/bin

# Download PDFs (no authentication required)
aws s3 sync s3://igor-bucket/math_docs_dataset/pdfs/ ./pdfs/ \
  --endpoint-url=https://s3.eu-central-1.wasabisys.com \
  --no-sign-request
```

### Download Specific PDF

```bash
# Download single document
aws s3 cp s3://igor-bucket/math_docs_dataset/pdfs/{doc_id}.pdf ./pdfs/ \
  --endpoint-url=https://s3.eu-central-1.wasabisys.com \
  --no-sign-request
```

### Preview Samples

50 sample PDFs are included in the `samples/` directory for preview without downloading the full dataset.

## Metadata Fields

Each entry in `metadata.jsonl` contains:

- `doc_id`: Unique document identifier
- `pdf_path`: Relative path to PDF file
- `num_pages`: Number of pages in the document
- `mean_proba`: Mean probability that document contains mathematical content

## Data Collection

1. **Source**: CommonCrawl PDF corpus
2. **Filtering**: Documents classified by mathematical content probability
3. **Text Extraction**: [doct.ocr](https://github.com/parse-data/doct.ocr)

## Usage Examples

### Load and Process Documents

```python
import json
from pathlib import Path

# Load metadata
docs = []
with open("metadata.jsonl") as f:
    for line in f:
        docs.append(json.loads(line))

# Filter high-quality math documents
high_quality = [d for d in docs if d['mean_proba'] > 0.95]
print(f"Found {len(high_quality)} high-quality documents")

# Read document text
def read_document(doc_id):
    text_dir = Path(f"texts/{doc_id}")
    full_text = []
    
    for page_file in sorted(text_dir.glob("page_*.md")):
        with open(page_file) as f:
            full_text.append(f.read())
    
    return "\n\n".join(full_text)

# Example usage
doc = high_quality[0]
text = read_document(doc['doc_id'])
print(f"Document {doc['doc_id']}: {len(text)} characters")
```

### Token Analysis

```python
import json

# Load token statistics
with open("token_stats.json") as f:
    stats = json.load(f)
    print(f"Total tokens: {stats['total_tokens']:,}")
    print(f"Avg tokens/doc: {stats['avg_tokens_per_doc']:.0f}")

# Load per-document token counts
with open("token_counts.jsonl") as f:
    for line in f:
        doc_tokens = json.loads(line)
        # Process individual document token counts
        break
```

## Citation

If you use this dataset, please cite:

```bibtex
@dataset{math_docs_dataset,
  title={Mathematical Documents Dataset},
  author={Your Name},
  year={2025},
  publisher={HuggingFace},
  url={https://huggingface.co/datasets/your-username/math-docs-dataset}
}
```

## License

MIT License

## Contact

For questions or issues, please open an issue on the dataset repository.