rusting_brain 3.0.1

A Rust deep-learning library for training and running transformer language models, dense and mixture-of-experts, on CPU or CUDA.
Documentation
use rusting_brain::{Activation, Dataset, Loss, Network, Optimizer, TrainConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let dataset = Dataset::new(
        vec![
            vec![1.0, 0.0],
            vec![0.9, 0.1],
            vec![0.0, 1.0],
            vec![0.1, 0.9],
            vec![0.8, 0.8],
            vec![0.7, 0.9],
        ],
        vec![
            vec![1.0, 0.0, 0.0],
            vec![1.0, 0.0, 0.0],
            vec![0.0, 1.0, 0.0],
            vec![0.0, 1.0, 0.0],
            vec![0.0, 0.0, 1.0],
            vec![0.0, 0.0, 1.0],
        ],
    );

    let mut model = Network::builder()
        .input_size(2)
        .dense(10, Activation::Relu)
        .dense(3, Activation::Softmax)
        .loss(Loss::CrossEntropy)
        .optimizer(Optimizer::adam(0.03))
        .build();

    model.fit(
        &dataset,
        TrainConfig {
            epochs: 1_000,
            batch_size: 6,
            shuffle: true,
            seed: Some(19),
        },
    )?;

    for input in &dataset.inputs {
        println!("{input:?} -> {:?}", model.predict(input)?);
    }

    // Loss is what the optimizer minimized; accuracy is what the result is
    // reported in. Six samples and no held-out split, so this only says the
    // model fitted what it was shown.
    println!("\naccuracy {:.1}%", 100.0 * model.accuracy(&dataset)?);

    Ok(())
}