Status: active.
This crate is the first executable companion for R4 Data in the CS336 Rust equivalent track.
It teaches data preparation as a typed corpus pipeline:
RawDocument -> NormalizedDocument -> FilterDecision -> CorpusShard
DatasetCard -> PublicCorpusManifest
- assignment: R4 Data
- track: CS336 Rust Equivalent
- active teaching crate
- typed document IDs, source names, raw text, normalized text, token counts, dedup keys, filter reasons, corpus shards, and mixture weights
- deterministic lowercase and whitespace normalization
- explicit filtering decisions with durable rejection reasons
- deterministic duplicate keys for normalized text
- corpus shard construction from accepted filter decisions
- source mixture validation with non-negative weights and positive total weight
- public corpus manifests that reject restricted or private source cards before publication
- ops-based checked addition for document counts and token budgets
src/
error.rs
lib.rs
examples/
01_normalize_documents.rs
02_filter_and_dedup.rs
03_build_shard.rs
04_source_mixture.rs
05_public_manifest.rs
01_normalize_documentsturns one raw public-safe document into normalized text and a dedup key.02_filter_and_dedupshows accepted, duplicate, and too-short decisions with explicit reasons.03_build_shardbuilds a tiny shard from accepted decisions.04_source_mixturevalidates a source mixture.05_public_manifestmakes the public/private corpus boundary executable.
Read the pipeline as a composition of data-quality maps:
RawDocument -> NormalizedDocument
NormalizedDocument -> DedupKey
NormalizedDocument -> FilterDecision
AcceptedDocuments -> CorpusShard
SourceWeights -> SourceMixture
DatasetCard -> PublicCorpusManifest
The composition rule is evidence preservation. A document should not become training data unless its source, normalized text, dedup key, and filtering decision remain visible. A source should not become public learner-facing material unless its license and visibility evidence pass the manifest boundary.
cargo test --manifest-path code/Cargo.toml -p rust_ml_data --all-targetscargo run --manifest-path code/Cargo.toml -p rust_ml_data --example 01_normalize_documents
cargo run --manifest-path code/Cargo.toml -p rust_ml_data --example 02_filter_and_dedup
cargo run --manifest-path code/Cargo.toml -p rust_ml_data --example 03_build_shard
cargo run --manifest-path code/Cargo.toml -p rust_ml_data --example 04_source_mixture
cargo run --manifest-path code/Cargo.toml -p rust_ml_data --example 05_public_manifestThis crate intentionally uses tiny public-safe strings, not real web-scale corpora.
The goal is to teach the invariants first: every document has a source, every transformation is deterministic, every rejection has a reason, every source mixture has a meaningful total, and every public manifest excludes restricted or private source cards.