Skip to main content

is_it_slop_preprocessing/
lib.rs

1//! Fast TF-IDF text vectorization using token-level n-grams.
2//!
3//! This crate provides high-performance text preprocessing for machine learning,
4//! using tiktoken BPE tokenization and sparse matrix operations. Designed for both
5//! training (via Python bindings) and inference (native Rust).
6//!
7//! # Architecture
8//!
9//! The pipeline consists of:
10//! 1. **Tokenization** - Text → BPE token IDs using tiktoken `o200k_base`
11//! 2. **N-gram extraction** - Token IDs → token n-grams (sequences of consecutive tokens)
12//! 3. **Counting** (`CountVectorizer`) - N-grams → sparse term-frequency matrix
13//! 4. **TF-IDF weighting** ([`TfidfVectorizer`]) - TF matrix → normalized TF-IDF features
14//!
15//! # Key Features
16//!
17//! - **Token n-grams**: Uses sequences of BPE tokens (not characters or words)
18//! - **Parallel processing**: Automatic parallelization via rayon for large datasets
19//! - **Sparse matrices**: Memory-efficient `sprs::CsMat` representation
20//! - **sklearn-compatible**: Python API matches sklearn's `TfidfVectorizer`
21//!
22//! # Example (Rust)
23//!
24//! ```rust
25//! use is_it_slop_preprocessing::pre_processor::{TfidfVectorizer, VectorizerParams};
26//!
27//! let texts = vec!["example text 1", "example text 2"];
28//! let params = VectorizerParams::new(10.0, 0.8, true); // min_df, max_df, sublinear_tf
29//! let (vectorizer, tfidf_matrix) = TfidfVectorizer::fit_transform(&texts, params);
30//! // N-gram range is fixed at 2-4 (bigrams through 4-grams)
31//! ```
32//!
33//! [`TfidfVectorizer`]: pre_processor::TfidfVectorizer
34
35#[cfg(feature = "python")]
36mod python;
37
38pub mod pre_processor;