How cxcscmu/craw4llm works
Project type and purpose
• Craw4LLM is an open‑source Python tool designed for efficient web crawling of the ClueWeb22 dataset to produce document collections for LLM pretraining. It provides multiple crawling strategies (e.g., DCLM‑fastText scoring, random, in‑degree) and supports downstream fetching of raw document text.
File structure
• Top‑level CLI entry scripts:
• crawl.py – orchestrates a crawl run
• fetch_docs.py – retrieves document texts after crawling
• access_data.py – ad hoc inspection of ClueWeb22 docs
• Core modules:
• crawler.py – implements the crawler engine, queue management, visited set
• corpus_interface.py – abstracts access to the ClueWeb22 content store
• document_rater.py – defines rating methods (length, fastText_score, etc.)
• normalizer.py – cleans/normalizes URLs or document representations
• utils.py – shared utilities (e.g., file I/O, YAML loader)
• wandb_logger.py – wraps Weights & Biases logging
• Other scripts:
• crawl.py calls into crawler.py, document_rater.py, wandb_logger.py
• fetch_docs.py uses corpus_interface.py & utils.py
• Config folder (user‑created) “configs/” holds YAML files specifying:
• Paths (cw22_root_path, output_dir)
• Crawler parameters (seed_docs_file, num_workers, selection_method, rating_methods)
• Data files:
• seed.txt – initial seed document IDs
• seed/ output_dir – crawl results: lists of document IDs per iteration
README for additional insights
• Emphasis on placing ClueWeb22 on SSD for performance
• wandb integration for logging metrics per iteration
• Instructions for multiple crawling strategies (baseline random, indegree)
• Post‑crawl step to fetch raw texts for downstream LLM pretraining via DCLM framework
1. CLI Layer
• crawl.py
• fetch_docs.py
• access_data.py
2. Config Loader
• YAML parser (utils.py) reads “configs/*.yaml”
3. Crawler Controller
• CrawlerEngine (crawler.py)
• QueueManager & VisitedSet
4. Rating Engine
• DocumentRater (document_rater.py)
• Scoring methods: length, fasttext_score, inlink_count, random
5. Corpus Interface
• ClueWeb22 Data Store (on SSD)
• corpus_interface.py
6. Persistence & I/O
• Output: crawl_results/ (lists of doc IDs per iteration)
• State checkpoint (queue & visited set if enabled)
7. Fetch Module
• fetch_docs.py reads IDs + corpus_interface → raw texts
8. Logging & Monitoring
• wandb_logger.py → Weights & Biases
9. External Dependencies
• fastText models (fasttext_scorers/)
• Python libraries: numpy, tqdm, pyyaml, wandb
• CLI “crawl.py” → Config Loader → Crawler Controller
• Crawler Controller ⇄ QueueManager & VisitedSet (pop / push doc IDs)
• Crawler Controller → Corpus Interface → read seed docs / outlinks
• Documents fetched from Corpus → Rating Engine → scores
• Rated docs → Controller → selection_method → new docs enqueued
• Controller → Persistence → write crawl_results/ & optional state file
• Controller → Logging → wandb_logger → wandb backend
• CLI “fetch_docs.py” → reads crawl_results/ → fetch via Corpus Interface → writes raw texts
c. Architectural Patterns & Principles
• Modular separation: CLI / Controller / Rating / I/O
• Pluggable strategies: rating methods and selection_method via configuration
• Producer‑consumer model: multi‑worker document fetching & scoring
• Checkpointing for fault tolerance (save_state_every)
• Externalized config (YAML) for reproducibility
d. Technologies & Frameworks to annotate
• Python 3.10+
• fastText (HuggingFace models)
• Weights & Biases (wandb)
• ClueWeb22 dataset (SSD)
Detailed Capture of Essential Elements
• Break out the “Corpus Interface” and “Rating Engine” as separate components, not lumped into one
• Worker pool (num_workers) inside CrawlerEngine for concurrency