Skip to main content

Module pre_processor

Module pre_processor 

Source
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§

CountVectorizer
Builds vocabulary and transforms texts to sparse term-frequency matrices.
TextCleaner
Main text cleaner that combines universal and dataset-specific cleaning Two-stage text cleaner for training and inference.
TfidfVectorizer
Applies TF-IDF weighting and L2 normalization to text features.
TfidfVectorizerBuilder
Builder for incremental TF-IDF vectorizer training.
TokenChunker
Splits token sequences into overlapping chunks with even distribution.
VectorizerParams
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 TextCleaner for inference
text_cleaner_for_training
Create a TextCleaner for training
tokenize
Tokenize texts using bpe-openai o200k_base encoding.