RML Core โ Rust Language Model
rml-core
is a simple N-Gram language model implemented in Rust. The name is a play on LLM (Large Language Models) and stands for "Rust Language Model".
๐ง Overview
This project implements a character-level N-Gram language model using a basic neural architecture with one hidden layer. It uses a context of 4 characters to predict the next character in a sequence.
โจ Features
- Train a language model on any text file
- Generate text based on a seed string
- Supports letters, numbers, and basic punctuation
- Configurable training parameters (e.g. number of epochs)
- Save and load trained models
๐ Installation
In your Cargo.toml
:
[]
= "0.1.0"
๐งช Usage
๐ Train a model
Example:
๐ Generate text
Example:
๐ Use as a library
use ;
// Training
let text = read_to_string.unwrap;
let training_data = prepare_training_data;
let mut model = new;
for in training_data
model.save.unwrap;
// Generation
let mut model = load.unwrap;
// Use model.forward() and sampling logic
โ๏ธ How It Works
- Preprocessing: The input text is filtered to include only allowed characters (ASCII aโz, AโZ, 0โ9, punctuation).
- Training Data: Generates (context, target) pairs where the context is 4 characters long.
- Training: The model learns to predict the next character using backpropagation.
- Generation: Given a seed, the model predicts the next character and slides the context window forward.
๐งฌ Technical Details
Component | Value |
---|---|
Context Size | 4 characters |
Hidden Layer | 128 neurons |
Learning Rate | 0.005 |
Sampling Temperature | 0.3 (conservative) |
Vocabulary | a-z, A-Z, 0โ9, punctuation |
๐ Example
# Train on Shakespeare for 10 epochs
# Generate 200 characters using "To be" as the seed
๐ค Contributing
Contributions are welcome! Please feel free to open an issue or submit a pull request.
๐ License
This project is licensed under the MIT License.
Feel free to customize this README to fit your needs.