How chatelo/machine-learning-in-rust-from-scratch works
This is a chapter-based Rust machine-learning project. Its current focus is loading SmolLM2 with Candle, checking it against a reference, generating text, scoring it on Shakespeare, and fine-tuning it; earlier chapters also provide tabular and tweet-sentiment workflows plus HTTP predictions. The shown main dispatches several chapter commands, while the README documents the LLM stages. Many earlier model implementations were not excerpted, so their internal calls are not inferred here.
Main entry points: main.rs Stage dispatcher · server.rs Prediction API · llm.rs SmolLM2 runtime · metrics.rs Model metrics
Components 22
Entry and serving
- Stage dispatcher
src/main.rs - Prediction API
src/server.rs
Data preparation
- Heart data prep
src/data.rs - Tweet preprocessing
src/text.rs - Data exploration
src/explore.rs - Framingham files
data/framingham.csv - Shakespeare text
data/shakespeare.txt
Prediction models
- Linear regression
src/linear.rs - Logistic regression
src/logistic.rs - Decision tree
src/tree.rs - Random forest
src/forest.rs - Tweet SVM
src/svm.rs - Naive Bayes
src/bayes.rs - Patient k-NN
src/knn.rs - Neural networks
src/nn.rs - Saved model files
models/svm/catalog.json
Language models
- Tiny GPT
src/gpt.rs - SmolLM2 runtime
src/llm.rs - Pretrained weights
gpt_model.json
Evaluation
- Model metrics
src/metrics.rs
Other components
- CLI user
- HTTP client
Connections 33
- CLI user → Stage dispatcher: selects stage
src/main.rs - Stage dispatcher → Data exploration: runs exploration
src/main.rs - Stage dispatcher → Heart data prep: runs clean or split
src/main.rs - Stage dispatcher → Linear regression: runs training
src/main.rs - Stage dispatcher → Logistic regression: dispatches stages
src/main.rs - Stage dispatcher → Prediction API: starts serving
src/main.rs - Stage dispatcher → Decision tree: dispatches stages
src/main.rs - Stage dispatcher → Random forest: dispatches stages
src/main.rs - Stage dispatcher → Tweet preprocessing: dispatches stages
src/main.rs - Stage dispatcher → Neural networks: dispatches stages
src/main.rs - Stage dispatcher → Tiny GPT: dispatches stages
src/main.rs - Stage dispatcher → SmolLM2 runtime: dispatches LLM stages
src/main.rs - HTTP client → Prediction API: sends requests
README.md - Prediction API → Logistic regression: predicts with
src/server.rs - Prediction API → Decision tree: predicts with
src/server.rs - Prediction API → Random forest: predicts with
src/server.rs - Prediction API → Tiny GPT: generates with
src/server.rs - Prediction API → SmolLM2 runtime: generates with
src/server.rs - Random forest → Decision tree: grows trees
src/forest.rs - SmolLM2 runtime → Tiny GPT: compares against
src/llm.rs - SmolLM2 runtime → Shakespeare text: trains and scores
README.md - SmolLM2 runtime → Pretrained weights: loads model weights
README.md - Heart data prep → Framingham files: cleans and splits
src/data.rs - Heart data prep → Model metrics: supports evaluation
- Tweet preprocessing → Tweet SVM: vectorizes text
src/svm.rs - Logistic regression → Model metrics: scores predictions
src/logistic.rs - Decision tree → Model metrics: scores predictions
src/tree.rs - Random forest → Model metrics: scores predictions
src/forest.rs - Neural networks → Model metrics: scores predictions
src/nn.rs - Saved model files → Tweet SVM: stores versions
- Stage dispatcher → Naive Bayes: dispatches stages
src/main.rs - Stage dispatcher → Patient k-NN: dispatches stages
src/main.rs - Heart data prep → Logistic regression: supplies features
src/logistic.rs