Trustformer is a Transformer-based language model implementation in Rust. This project was built to learn how transformers work at a low level.
src/: Core implementation.embeddings/: Token and positional embeddings.model/: High-level model architecture (Decoder).sampling/: Text generation and sampling strategies.tensor/: Custom tensor operations and math backend.tokenizer/: BPE tokenizer training and inference.transformer/: Transformer blocks (Attention, FeedForward, LayerNorm).utils/: Helper functions.
data/: Directory for training data and other resources.tests/: Integration tests.
- Ensure you have Rust installed.
- Place your training data in
data/training_data.txt. - Run the project:
cargo run- Tokenizer: Byte Pair Encoding (BPE) tokenizer.
- Model: Decoder-only Transformer architecture.
- Sampling: Text generation with temperature sampling.
The main.rs file demonstrates how to:
- Load training data.
- Train the tokenizer.
- Initialize the model.
- Generate text based on a prompt.