Expand description
Text preprocessing pipeline for machine learning.
This module provides a complete text processing pipeline combining:
- Text cleaning (HTML entities, encoding artifacts, dataset-specific patterns)
- Tokenization (tiktoken BPE encoding)
- Token-based chunking (splitting long documents into overlapping segments)
- TF-IDF vectorization with token n-grams
- Statistical feature extraction (writing style analysis)
The pipeline is designed for both training (Python bindings) and inference (native Rust), with automatic parallelization and sparse matrix representations for efficiency.
Modules§
- ngrams
- Token n-gram extraction and vocabulary building.
Structs§
- Count
Vectorizer - Builds vocabulary and transforms texts to sparse term-frequency matrices.
- Text
Cleaner - Main text cleaner that combines universal and dataset-specific cleaning Two-stage text cleaner for training and inference.
- Tfidf
Vectorizer - Applies TF-IDF weighting and L2 normalization to text features.
- Tfidf
Vectorizer Builder - Builder for incremental TF-IDF vectorizer training.
- Token
Chunker - Splits token sequences into overlapping chunks with even distribution.
- Vectorizer
Params - Configuration parameters for text vectorization.
Constants§
- DEFAULT_
MAX_ NGRAM - Default maximum n-gram size.
- DEFAULT_
MIN_ NGRAM - Default minimum n-gram size.
Functions§
- attempt_
reverse_ tokenize - Attempt to decode token IDs back to text, returning None on failure.
- reverse_
tokenize - Decode token IDs back to text.
- text_
cleaner_ for_ inference - Create a
TextCleanerfor inference - text_
cleaner_ for_ training - Create a
TextCleanerfor training - tokenize
- Tokenize texts using bpe-openai
o200k_baseencoding.