| Crates.io | scorch |
| lib.rs | scorch |
| version | 0.1.1 |
| created_at | 2025-02-25 18:29:30.223755+00 |
| updated_at | 2025-02-25 20:01:26.073682+00 |
| description | A straightforward and customizable neural network crate, built for machine learning tasks. |
| homepage | |
| repository | https://github.com/sa4dus/scorch |
| max_upload_size | |
| id | 1569423 |
| size | 41,097 |
Scorch is a straightforward , easy-to-use neural network library written in Rust. It is designed for educational purposes and quick experiments with neural networks, providing basic building blocks for building, training, and evaluating feedforward neural networks.
To use scorch in your Rust project, add it as a dependency in your Cargo.toml:
[dependencies]
scorch = "0.1"
Here's a simple example of how to create and train a neural network with scorch.
use crate::{Layer, activation::{relu, sigmoid}, loss::{MSE}, NeuralNetwork};
fn main() {
// Define the layers of the neural network.
let mut layers = vec![
Layer::new(2, 4, relu), // First layer with 2 input features and 4 output features (hidden layer)
Layer::new(4, 1, sigmoid), // Second layer with 4 input features and 1 output feature (output layer)
];
// Create the neural network
let mut nn = NeuralNetwork::new(&mut layers);
// Define the training data for XOR
let inputs = vec![
vec![0.0, 0.0], // XOR input: (0, 0)
vec![0.0, 1.0], // XOR input: (0, 1)
vec![1.0, 0.0], // XOR input: (1, 0)
vec![1.0, 1.0], // XOR input: (1, 1)
];
let targets = vec![
vec![0.0], // XOR output: 0
vec![1.0], // XOR output: 1
vec![1.0], // XOR output: 1
vec![0.0], // XOR output: 0
];
// Train the neural network with XOR data
nn.train(&inputs, &targets, 0.1, MSE, 10_000); // Using a learning rate of 0.1 and training for 10,000 epochs
// Test the trained model with the XOR inputs
let test_inputs = vec![
vec![0.0, 0.0],
vec![0.0, 1.0],
vec![1.0, 0.0],
vec![1.0, 1.0],
];
for test_input in test_inputs {
let prediction = nn.forward(&test_input);
println!("Input: {:?}, Predicted Output: {:?}", test_input, prediction);
}
}
Scorch is designed to be flexible and modular. You can add custom activation functions, loss functions, or layer types to suit your specific needs. For example:
This feature makes Scorch an ideal choice for experimenting with different network architectures and algorithms in a simple and understandable way.
While Scorch is intended for educational and experimental purposes, its design should be performant enough for small to medium-sized datasets. For larger datasets or more advanced use cases, consider using optimized libraries such as ndarray or tch-rs for higher performance.
Contributions are welcome! If you have ideas for new features, improvements, or bug fixes, feel free to open an issue or submit a pull request.
cargo test to ensure everything is working.This project is licensed under the MIT License - see the LICENSE file for details.