Giter Club home page Giter Club logo

telegrad's Introduction

telegrad

Rust implementation of micrograd for educational purposes to learn Rust and Neural networks.

alt text

There are binaries for examples of linear regressions, logistic regression and a small neural network for recognizing zeros and ones a small subset of the MNIST dataset.

Main difference from micrograd, except of using Rust, is that the nodes are stored on a stack to get a topological order of the graph while creating it, instead of sorting it at backpropagation. Another difference is that the node graph is only constructed once, and then traversed instead of recreated during training or prediction.

You can like in micrograd create a graph using operator overloading like this:

    println!("Test simple linear regression");
    fn f_target(x: f32) -> f32 { x * 4. - 5. }
    let ns = NodeStack::new(); // Stack to store graph

    val!(ns, w, 2.); // macro to create variables with a label
    val!(ns, b, 1.);
    val!(ns, x, 1.);
    val!(ns, y_hat, f_target(1.));

    let f = x * w + b;
    let loss = (&f - y_hat).pow(&ns.val(2.)); // squared error term
    ...

You can create a SVG file for a given graph like in this small example of creating a neuron with two inputs.

#[test]
fn test_neuron() {
    let ns = NodeStack::new();
    let input = (0..2).map(|_| ns.val_labeled(1., "x")).collect();
    let n = Neuron::new(ns.clone(), input, UnaryOp::ReLu);
    ns.create_svg(&n.output, "neuron.svg");
    println!("neuron: {:?}", &n);
}

Resulting in this image

alt text

telegrad's People

Contributors

tnlogy avatar

Stargazers

Ahmet Kaan GÜMÜŞ avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.