OpenTransformer commited on
Commit
20b6ddb
·
verified ·
1 Parent(s): a8de6dc

Upload source/upload_crawler_source.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. source/upload_crawler_source.py +148 -0
source/upload_crawler_source.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ import tempfile, os
3
+
4
+ api = HfApi(token='HF_TOKEN_REDACTED')
5
+ REPO = 'OpenTransformer/web-crawl-2026'
6
+
7
+ # Upload main.rs
8
+ print('Uploading main.rs...')
9
+ api.upload_file(
10
+ path_or_fileobj='/workspace/rust_crawler/src/main.rs',
11
+ path_in_repo='crawler/rust/src/main.rs',
12
+ repo_id=REPO,
13
+ repo_type='dataset',
14
+ commit_message='Add Rust web crawler source (v3, 150-300 docs/s)'
15
+ )
16
+
17
+ # Upload Cargo.toml
18
+ print('Uploading Cargo.toml...')
19
+ api.upload_file(
20
+ path_or_fileobj='/workspace/rust_crawler/Cargo.toml',
21
+ path_in_repo='crawler/rust/Cargo.toml',
22
+ repo_id=REPO,
23
+ repo_type='dataset',
24
+ commit_message='Add Rust crawler Cargo.toml'
25
+ )
26
+
27
+ # Create and upload README
28
+ readme = '''---
29
+ license: apache-2.0
30
+ task_categories:
31
+ - text-generation
32
+ language:
33
+ - en
34
+ tags:
35
+ - web-crawl
36
+ - pretraining
37
+ - nlp
38
+ - text-corpus
39
+ pretty_name: Web Crawl 2026
40
+ size_categories:
41
+ - 10B<n<100B
42
+ ---
43
+
44
+ # Web Crawl 2026
45
+
46
+ A large-scale web crawl dataset for language model pretraining, collected by the OpenTransformer project.
47
+
48
+ ## Dataset Description
49
+
50
+ This dataset contains text extracted from web pages crawled directly from the internet using custom high-throughput crawlers. All data is freshly scraped — **not** re-uploaded from existing datasets like FineWeb or C4.
51
+
52
+ ### Data Format
53
+
54
+ Each record is a JSON line with fields:
55
+ - — extracted text content (200–200,000 chars)
56
+ - — source URL
57
+ - — source domain
58
+ - — crawl timestamp (ISO 8601)
59
+ - — crawler identifier (, , )
60
+
61
+ ### Collection Methods
62
+
63
+ Three crawlers run in parallel on a Vast.ai GPU box (Titan Xp, /usr/bin/bash.06/hr):
64
+
65
+ | Crawler | Language | Throughput | 1.2GB Chunk Time | Architecture |
66
+ |---------|----------|------------|-------------------|-------------|
67
+ | **crawl_rust** | Rust | **150–300 docs/s** | **5–6 min** | 500 async workers, tokio |
68
+ | crawl_go | Go | 11 docs/s | ~2 hrs | 150 goroutines |
69
+ | crawl_v5.py | Python | 0.8 docs/s | ~25 hrs | 20 async workers |
70
+
71
+ The Rust crawler is **27x faster than Go** and **375x faster than Python**.
72
+
73
+ ### Rust Crawler Architecture
74
+
75
+ Source:
76
+
77
+ **Key design decisions:**
78
+ - **500 concurrent async workers** via tokio + semaphore-based backpressure
79
+ - **Background queue refiller** — seed fetching runs in a separate task, never blocks crawling
80
+ - **Pre-generated seed file** — 593K URLs from Common Crawl index (12 crawl versions × 20 TLD patterns)
81
+ - **Link discovery** — extracts up to 50 links per crawled page, shuffled for domain diversity
82
+ - **Content dedup** — MD5 hash of first 500 chars, stored in DashMap (lock-free concurrent hashmap)
83
+ - **Domain throttling** — max 1000 pages per domain to ensure diversity
84
+ - **Streaming gzip** — writes compressed JSONL chunks (~1.2GB raw → ~350MB compressed)
85
+ - **Auto-upload** — each completed chunk is uploaded to HuggingFace Hub via Python subprocess
86
+
87
+ **Seed sources:**
88
+ 1. Common Crawl URL index (CC-MAIN-2024-10 through CC-MAIN-2025-08)
89
+ 2. Wikipedia random articles API (20K articles)
90
+ 3. Sitemaps from 34 major sites (Reuters, BBC, Nature, StackOverflow, etc.)
91
+ 4. Hacker News top/new/best stories
92
+
93
+ **Performance on Titan Xp box (/usr/bin/bash.06/hr):**
94
+ - Phase 1: 562K seeds loaded in 28 seconds
95
+ - Phase 2: 150–300 docs/s sustained throughput
96
+ - ~1.2GB chunk every 5–6 minutes
97
+ - ~12–15 GB/hour of raw crawled text
98
+ - Cost: ~/usr/bin/bash.004 per GB of crawled text
99
+
100
+ ### Building & Running
101
+
102
+
103
+ stable-x86_64-pc-windows-gnu installed - (timeout reading rustc version)
104
+
105
+
106
+ Rust is installed now. Great!
107
+
108
+ To get started you may need to restart your current shell.
109
+ This would reload its PATH environment variable to include
110
+ Cargo's bin directory (%USERPROFILE%\.cargo\bin).
111
+
112
+ ### Dependencies
113
+
114
+ - Rust 1.75+
115
+ - Python 3 with (for upload)
116
+ - hardcoded (or modify to use env var)
117
+
118
+ ### Quality Filtering
119
+
120
+ - HTML text extraction via crate (article/main/body selectors)
121
+ - Minimum 200 chars, maximum 200K chars
122
+ - Content-type filtering (only text/html)
123
+ - URL filtering: blocks social media, login pages, media files, admin pages
124
+ - Deduplication via MD5 content hash
125
+
126
+ ## Intended Use
127
+
128
+ Pretraining data for the AGILLM-3 language model (698M params, joint AR+SAT architecture).
129
+
130
+ ## License
131
+
132
+ Apache 2.0
133
+ '''
134
+
135
+ with tempfile.NamedTemporaryFile(mode='w', suffix='.md', delete=False) as f:
136
+ f.write(readme)
137
+ readme_path = f.name
138
+
139
+ print('Uploading README.md...')
140
+ api.upload_file(
141
+ path_or_fileobj=readme_path,
142
+ path_in_repo='README.md',
143
+ repo_id=REPO,
144
+ repo_type='dataset',
145
+ commit_message='Update README with crawler documentation and performance benchmarks'
146
+ )
147
+ os.unlink(readme_path)
148
+ print('All uploads complete!')