Skip to content

Project Overview

This project is designed to assist those who wish to work with the Rust language in the field of artificial intelligence and its sub-disciplines.

  • Provide practical, runnable examples of AI/ML in Rust
  • Demonstrate popular Rust ML libraries (Candle, Linfa, Burn, etc.)
  • Cover various domains: NLP, Computer Vision, Traditional ML, Deep Learning
  • Serve as a learning resource for Rust developers interested in AI
Library Purpose Examples
Candle Tensor operations, neural networks Text Classification, Sentiment Analysis, OCR, Image Classification
Linfa Classical ML algorithms KNN, Decision Tree, Linear Regression, Language Detection
Tokenizers Text tokenization Text Classification, Sentiment Analysis
Hugging Face Hub Model hosting Sentiment Analysis, OCR, Image Classification
  • Decision Tree Classifier - Loan approval prediction
  • House Price Prediction - Linear regression
  • KNN Classifier - Iris dataset classification
  • Image Classification - ResNet-18 on ImageNet
  • OCR - TrOCR for text recognition
  • Keyword Extraction - TF-IDF based extraction
  • Language Detection - Character n-gram features
  • Sentiment Analysis - DistilBERT for sentiment
  • Text Classification - BERT for custom datasets
  • Email Spam Classification - Transformer-based spam detection
rust-ai-examples/
├── examples/ # All example projects (standalone Cargo crates)
│ ├── OCR/
│ ├── decision-tree-classifier/
│ ├── email-spam-classification/
│ ├── house-price-prediction/
│ ├── image-classification/
│ ├── keyword-extraction/
│ ├── knn-classifier/
│ ├── language-detection/
│ ├── sentiment-analysis/
│ └── text-classification/
├── src/content/docs/ # Documentation content (this site)
├── public/ # Static assets
├── package.json # Node.js dependencies
├── astro.config.mjs # Astro configuration
├── tsconfig.json # TypeScript configuration
├── Cargo.toml # (Not at root - each example has its own)
└── README.md # Project README

Every example is an independent Cargo crate. They share a common shape, but the number of modules and required assets varies:

example-name/
├── Cargo.toml # Its own manifest and dependencies
├── src/
│ ├── main.rs # Entry point (usually the whole pipeline)
│ ├── model.rs # Optional: model/classifier code
│ ├── dataset.rs # Optional: data loading
│ └── ... # Optional: preprocessing, downloader
├── data/ # Optional: committed datasets
└── models/ # Optional: model files (committed or downloaded)
Example Source files Requires
Text Classification src/main.rs Local models/ BERT checkpoint
Sentiment Analysis src/main.rs Downloads models/ from Hugging Face
Email Spam Classification (none yet) BERT assets present; source missing
Language Detection src/{main,model,dataset}.rs data/languages.json
Keyword Extraction src/main.rs .txt files in documents/
KNN Classifier src/main.rs data/iris.csv
Decision Tree Classifier src/main.rs data/loans.csv
House Price Prediction src/main.rs data/house.csv
Image Classification src/{main,model,preprocessing,downloader}.rs Downloads models/ on first run
OCR src/{main,image_processor}.rs Download helpers only; inference missing
Example Runnable? Notes
Decision Tree Classifier ✅ Yes Trains and evaluates on the committed CSV
House Price Prediction ✅ Yes Trains and evaluates on the committed CSV
KNN Classifier ✅ Yes Hand-written KNN with full metrics
Language Detection ✅ Yes Trains on languages.json, then interactive
Keyword Extraction ✅ Yes Reads documents/*.txt
Sentiment Analysis ✅ Yes Downloads DistilBERT, then predict/evaluate
Text Classification ✅ Yes Trains a linear head on a local BERT
Image Classification ✅ Yes Downloads ResNet-18, then classifies an image
Email Spam Classification ❌ No Assets only; no src/ yet
OCR ❌ No No fn main; inference not implemented

Contributions are welcome! Please feel free to submit issues or pull requests.