Categories
Software Technology

Introducing ‘runn’: A Compact Neural Network Library in Rust

Let me start by saying this, I am relatively new to neural networks and Rust. But here it is: A compact neural network library written in Rust. I know that the best way to learn something is to get your hands dirty. That’s what inspired me to create runn: a beginner-friendly, end-to-end Rust API that takes you from raw data to a trained network in a handful of lines.

My Starting Point: No Prior ML Experience

  • Rust only: I loved its safety and performance.
  • Zero neural-network knowledge: I needed something that would guide me through the basic training loop without hiding the core concepts.

Manually implementing forward and backward passes, update weights, optimizers… taught me a ton.

Building Blocks of a Neural Network with runn

Without further ado, lets start using runn library with an example.

First lets add runn into our project.


> cargo add runn

Here’s how straightforward it is to train a simple feed-forward network on the classic Iris dataset (4 inputs → 3 classes) once you have runn in your Cargo.toml:


use std::{error::Error, fs::File};

use csv::ReaderBuilder;
use runn::{
    adam::Adam,
    cross_entropy::CrossEntropy,
    dense_layer::Dense,
    helper,
    matrix::{DMat, DenseMatrix},
    network_model::NetworkBuilder,
    relu::ReLU,
    softmax::Softmax,
};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1️⃣ Load CSV data
    let (t_inp, t_tar) = iris_inputs_outputs("train").unwrap();

    // 2️⃣ Define network with builder API
    let mut network = NetworkBuilder::new(4, 3)
        .layer(Dense::default().size(3).activation(ReLU::build()).build())
        .layer(Dense::default().size(3).activation(Softmax::build()).build())
        .loss_function(CrossEntropy::default().build())
        .optimizer(Adam::default().build())
        .batch_size(2)
        .seed(42)
        .epochs(10)
        // .summary(TensorBoard::default().directory("summary").build())
        // .debug(true)
        .build()?;

    // 3️⃣ train network
    let t_res = network.train(&t_inp, &t_tar);

    match t_res {
        Ok(_) => {
            println!("Training completed successfully");
            let net_results = network.predict(&t_inp, &t_tar).unwrap();
            println!(
                "{}",
                helper::pretty_compare_matrices(
                    &t_inp,
                    &t_tar,
                    &net_results.predictions,
                    helper::CompareMode::Classification
                )
            );
            println!("Metrics: {}", net_results.display_metrics());
        }
        Err(e) => {
            eprintln!("Training failed: {}", e);
        }
    }

    // 4️⃣ Validate our network with validation data
    let (v_inp, v_tar) = iris_inputs_outputs("test").unwrap();
    let val_results = network.predict(&v_inp, &v_tar).unwrap();
                println!(
                "{}",
                helper::pretty_compare_matrices(
                    &v_inp,
                    &v_tar,
                    &val_results.predictions,
                    helper::CompareMode::Classification
                )
            );
            println!("Metrics: {}", val_results.display_metrics());

    Ok(())
}

pub fn iris_inputs_outputs(name: &str) -> Result<(DMat, DMat), Box<dyn Error>> {
    let input_count = 4;
    let target_count = 3;

    let file_path = format!("./data/{}.csv", name);
    let file = File::open(&file_path)?;
    let mut reader = ReaderBuilder::new().has_headers(true).from_reader(file);

    let mut inputs_data = Vec::new();
    let mut targets_data = Vec::new();

    for result in reader.records() {
        let record = result?;
        for (i, value) in record.iter().enumerate() {
            let parsed_val: f32 = value.parse()?;
            if i >= 4 {
                targets_data.push(parsed_val);
            } else {
                inputs_data.push(parsed_val);
            }
        }
    }

    let data_length = inputs_data.len() / input_count;

    let inputs = DenseMatrix::new(data_length, input_count)
        .data(&inputs_data)
        .build()
        .unwrap();
    let targets = DenseMatrix::new(data_length, target_count)
        .data(&targets_data)
        .build()
        .unwrap();

    Ok((inputs, targets))
}

That’s it! In just four sections you:

  1. Load training data from CSV
  2. Assemble a network including layer, loss, and optimizer via a fluent builder API
  3. Call .train() and then .predict() to see your metrics
  4. Validate the trained model with test data using .predict() and compare results.

Under the hood, runn still performs the forward passes, computes the cross-entropy loss, does backprop, and updates weights—but you never have to retype that loop. You get still get full visibility while skipping the endless boilerplate:

  • debug: Display weights and metrics after each epoch for visibility into training.
  • summary: Generate TensorBoard-compatible logs for visual analysis.

and here is the result:

Iris Training completed successfully

              Input                           Target                    Prediction        
⎡   0.08    0.67    0.00    0.04 ⎤  ⎡   1.00    0.00    0.00 ⎤     ⎡   0.98    0.00    0.02 ⎤
⎢   0.72    0.46    0.69    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.95    0.05 ⎥
⎢   0.67    0.42    0.68    0.67 ⎥  ⎢   0.00    0.00    1.00 ⎥ <>  ⎢   0.00    0.52    0.48 ⎥
⎢   0.78    0.42    0.83    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.97    0.03 ⎥
⎢   0.67    0.46    0.78    0.96 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.98    0.02 ⎥
⎢   0.39    0.42    0.54    0.46 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.02    0.95 ⎥
⎢   0.67    0.54    0.80    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.91    0.09 ⎥
⎢   0.31    0.58    0.08    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.42    0.29    0.53    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.04    0.02    0.94 ⎥
⎢   0.08    0.58    0.07    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.22    0.21    0.34    0.42 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.09    0.02    0.89 ⎥
⎢   0.56    0.21    0.68    0.75 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.91    0.09 ⎥
⎢   0.33    0.17    0.46    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.04    0.03    0.92 ⎥
⎢   0.33    0.62    0.05    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.56    0.54    0.63    0.62 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.15    0.84 ⎥
⎢   0.39    1.00    0.08    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.53    0.58    0.75    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.92    0.08 ⎥
⎢   0.36    0.38    0.44    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.03    0.03    0.95 ⎥
⎢   0.94    0.75    0.97    0.88 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.96    0.04 ⎥
⎢   0.36    0.42    0.59    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.13    0.86 ⎥
⎢   0.17    0.21    0.59    0.67 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.57    0.43 ⎥
⎢   0.42    0.29    0.69    0.75 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.86    0.14 ⎥
⎢   0.39    0.75    0.12    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.47    0.29    0.69    0.62 ⎥  ⎢   0.00    0.00    1.00 ⎥ <>  ⎢   0.00    0.59    0.41 ⎥
⎢   0.19    0.62    0.10    0.21 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.33    0.17    0.47    0.42 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.05    0.92 ⎥
⎢   0.61    0.42    0.76    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.78    0.22 ⎥
⎢   0.56    0.29    0.66    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.75    0.25 ⎥
⎢   0.47    0.42    0.64    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.53    0.47 ⎥
⎢   0.28    0.71    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.14    0.58    0.15    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.25    0.58    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.39    0.33    0.59    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.09    0.90 ⎥
⎢   0.22    0.75    0.15    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.36    0.42    0.53    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.03    0.95 ⎥
⎢   0.03    0.38    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.17    0.17    0.39    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.09    0.02    0.88 ⎥
⎢   0.72    0.46    0.75    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.92    0.08 ⎥
⎢   0.53    0.33    0.64    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.67    0.33 ⎥
⎢   0.03    0.50    0.05    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.67    0.46    0.58    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.07    0.92 ⎥
⎢   0.33    0.21    0.51    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.09    0.90 ⎥
⎢   0.08    0.50    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.19    0.42    0.10    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.50    0.38    0.63    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.15    0.84 ⎥
⎢   0.31    0.79    0.12    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.58    0.38    0.56    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.06    0.93 ⎥
⎢   0.17    0.42    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.58    0.46    0.76    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.72    0.28 ⎥
⎢   0.67    0.21    0.81    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.95    0.05 ⎥
⎢   0.22    0.62    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.61    0.33    0.61    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.26    0.73 ⎥
⎢   0.50    0.42    0.61    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.11    0.89 ⎥
⎢   0.42    0.33    0.69    0.96 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.98    0.02 ⎥
⎢   0.39    0.38    0.54    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.05    0.94 ⎥
⎢   0.17    0.46    0.08    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.47    0.08    0.68    0.58 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.73    0.27 ⎥
⎢   0.44    0.42    0.69    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.63    0.37 ⎥
⎢   0.36    0.33    0.66    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.85    0.15 ⎥
⎢   0.56    0.12    0.58    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.26    0.74 ⎥
⎢   0.94    0.42    0.86    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.99    0.01 ⎥
⎢   0.61    0.50    0.69    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.76    0.24 ⎥
⎢   0.56    0.38    0.78    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.83    0.17 ⎥
⎢   0.25    0.29    0.49    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.07    0.92 ⎥
⎢   0.25    0.88    0.08    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.17    0.46    0.08    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.14    0.58    0.10    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.67    0.54    0.80    1.00 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.99    0.01 ⎥
⎢   0.31    0.79    0.05    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.75    0.50    0.63    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.09    0.91 ⎥
⎢   0.64    0.38    0.61    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.09    0.90 ⎥
⎢   0.83    0.38    0.90    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.94    0.06 ⎥
⎢   0.22    0.54    0.12    0.17 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.58    0.33    0.78    0.88 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.98    0.02 ⎥
⎢   0.33    0.25    0.58    0.46 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.08    0.91 ⎥
⎢   0.56    0.33    0.69    0.58 ⎥  ⎢   0.00    1.00    0.00 ⎥ <>  ⎢   0.00    0.41    0.59 ⎥
⎢   0.33    0.92    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.86    0.33    0.86    0.75 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.96    0.04 ⎥
⎢   0.39    0.21    0.68    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.93    0.07 ⎥
⎢   0.94    0.33    0.97    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.99    0.01 ⎥
⎢   0.42    0.29    0.69    0.75 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.86    0.14 ⎥
⎢   0.39    0.25    0.42    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.07    0.02    0.92 ⎥
⎢   0.19    0.62    0.05    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.06    0.12    0.05    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.91    0.00    0.09 ⎥
⎢   0.22    0.75    0.10    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.69    0.42    0.76    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.94    0.06 ⎥
⎢   0.36    0.21    0.49    0.42 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.04    0.93 ⎥
⎢   0.58    0.33    0.78    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.97    0.03 ⎥
⎢   0.31    0.42    0.59    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.13    0.87 ⎥
⎢   0.11    0.50    0.10    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.69    0.50    0.83    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.98    0.02 ⎥
⎢   0.31    0.71    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.11    0.50    0.05    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.56    0.54    0.85    1.00 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.99    0.01 ⎥
⎢   0.14    0.42    0.07    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.61    0.42    0.71    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.86    0.14 ⎥
⎢   0.47    0.08    0.51    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.07    0.91 ⎥
⎢   0.42    0.29    0.49    0.46 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.02    0.04    0.94 ⎥
⎢   0.19    0.54    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.67    0.42    0.71    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.97    0.03 ⎥
⎢   0.81    0.42    0.81    0.62 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.69    0.31 ⎥
⎢   0.72    0.50    0.80    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.97    0.03 ⎥
⎢   0.44    0.50    0.64    0.71 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.40    0.60 ⎥
⎢   0.53    0.08    0.59    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥ <>  ⎢   0.00    0.58    0.42 ⎥
⎢   0.81    0.50    0.85    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.83    0.17 ⎥
⎢   0.19    0.58    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.50    0.42    0.66    0.71 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.57    0.43 ⎥
⎢   0.58    0.50    0.73    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.95    0.05 ⎥
⎢   0.58    0.50    0.59    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.10    0.90 ⎥
⎢   0.19    0.50    0.03    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.19    0.67    0.07    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.22    0.71    0.08    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.67    0.46    0.63    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.17    0.83 ⎥
⎢   0.39    0.33    0.53    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.05    0.94 ⎥
⎢   0.25    0.62    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.50    0.33    0.63    0.46 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.08    0.91 ⎥
⎢   0.33    0.12    0.51    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.14    0.85 ⎥
⎢   1.00    0.75    0.92    0.79 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.85    0.15 ⎥
⎢   0.47    0.38    0.59    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.18    0.82 ⎥
⎣   0.31    0.58    0.12    0.04 ⎦  ⎣   1.00    0.00    0.00 ⎦     ⎣   0.98    0.00    0.02 ⎦

Metrics: Loss:0.1287, Classification Metrics: Accuracy:96.6667, Micro Precision:0.9667, Micro Recall:0.9667, Macro F1 Score:0.9668, Micro F1 Score:0.9667
  Metrics by Class:
    Class 0:    Precision:1.0000    Recall:1.0000    F1 Score:1.0000
    Class 1:    Precision:0.9333    Recall:0.9767    F1 Score:0.9545
    Class 2:    Precision:0.9722    Recall:0.9211    F1 Score:0.9459


              Input                           Target                    Prediction        
⎡   0.58    0.29    0.73    0.75 ⎤  ⎡   0.00    1.00    0.00 ⎤     ⎡   0.00    0.90    0.10 ⎤
⎢   0.08    0.46    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.19    0.58    0.10    0.12 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.92    0.42    0.95    0.83 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.99    0.01 ⎥
⎢   0.61    0.42    0.81    0.88 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.97    0.03 ⎥
⎢   0.69    0.33    0.64    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.24    0.76 ⎥
⎢   0.17    0.46    0.08    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.14    0.42    0.07    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.22    0.62    0.07    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.50    0.25    0.78    0.54 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.59    0.41 ⎥
⎢   0.56    0.21    0.66    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥ <>  ⎢   0.00    0.53    0.46 ⎥
⎢   0.47    0.58    0.59    0.62 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.09    0.91 ⎥
⎢   0.22    0.75    0.08    0.08 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.19    0.00    0.42    0.38 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.04    0.08    0.88 ⎥
⎢   0.42    0.25    0.51    0.46 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.05    0.93 ⎥
⎢   0.44    0.42    0.54    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.10    0.90 ⎥
⎢   0.72    0.46    0.66    0.58 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.00    0.22    0.78 ⎥
⎢   0.81    0.67    0.86    1.00 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.98    0.02 ⎥
⎢   0.50    0.33    0.51    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.05    0.94 ⎥
⎢   0.14    0.46    0.10    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.42    0.83    0.03    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.99    0.00    0.01 ⎥
⎢   0.94    0.25    1.00    0.92 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    1.00    0.00 ⎥
⎢   0.22    0.58    0.08    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.98    0.00    0.02 ⎥
⎢   0.53    0.38    0.56    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.06    0.93 ⎥
⎢   0.64    0.42    0.58    0.54 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.09    0.90 ⎥
⎢   0.03    0.42    0.05    0.04 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.96    0.00    0.04 ⎥
⎢   0.00    0.42    0.02    0.00 ⎥  ⎢   1.00    0.00    0.00 ⎥     ⎢   0.97    0.00    0.03 ⎥
⎢   0.56    0.58    0.78    0.96 ⎥  ⎢   0.00    1.00    0.00 ⎥     ⎢   0.00    0.96    0.04 ⎥
⎢   0.36    0.29    0.54    0.50 ⎥  ⎢   0.00    0.00    1.00 ⎥     ⎢   0.01    0.07    0.92 ⎥
⎣   0.19    0.12    0.39    0.38 ⎦  ⎣   0.00    0.00    1.00 ⎦     ⎣   0.07    0.03    0.89 ⎦

Metrics: Loss:0.1051, Classification Metrics: Accuracy:96.6667, Micro Precision:0.9667, Micro Recall:0.9667, Macro F1 Score:0.9633, Micro F1 Score:0.9667
  Metrics by Class:
    Class 0:    Precision:1.0000    Recall:1.0000    F1 Score:1.0000
    Class 1:    Precision:0.8750    Recall:1.0000    F1 Score:0.9333
    Class 2:    Precision:1.0000    Recall:0.9167    F1 Score:0.9565

Although, it is not perfect, even with default values and relatively small epoch the results are not bad either. We have 96% accuracy for both training and validation datasets. Of course it can better but it is up to reader to improve it by tweaking and overriding various parameters such as layer sizes, learning rates, batch sizes etc.

In short Runn is:

  • Rust-only workflow: No external dependency.
  • Easy to use: The builder pattern reads like a recipe: define layers, set parameters, train.

I hope you find runn helpful. Contributions, suggestions, or even bug reports are more than welcome!