Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.2 KB

File metadata and controls

63 lines (43 loc) · 1.2 KB

MicroGrad

A minimal neural network and autograd engine written in Go.

Computation Graph

MicroGrad is a scalar-valued autograd engine, computation graph, backpropagation, and a simple Multi-Layer Perceptron (MLP) built from scratch without any external machine learning libraries.

Architecture

Value
├── data
├── grad
├── source nodes
└── backward function

Neuron
├── weights
├── bias
└── activation

Layer
└── collection of neurons

MLP
└── collection of layers

Training Example

for i := 0; i < 100; i++ {
    output := mlp.Init(input)

    loss := Loss(target, output)

    for _, p := range mlp.Params() {
        p.grad = 0
    }

    loss.Backward()

    for _, p := range mlp.Params() {
        p.data += -0.01 * p.grad
    }

    fmt.Println(loss.data)
}

A simple gradient descent training loop using backpropagation.

References