Skip to content

A tiny autograd + neural network + visualization library built from scratch Inspired by Karpathy’s micrograd, extended with a visualization engine and CLI.

Notifications You must be signed in to change notification settings

falloficarus22/bitgrad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BITGRAD: A small autograd engine + neural network + visualization library Bitgrad is a minimal neural network built from scratch in Python

Key Features:

Value Class with reverse-mode autodiff Neurons, Layers and MLPs Graph Visualization (SVG) Structured project files and directories + packaging

INSTALLATION

Install from PyPI:

pip install bitgrad

Or install from source:

git clone https://github.com/falloficarus22/bitgrad
cd bitgrad
pip install -e .

Example Usage:

from bitgrad import MLP, Value

# A simple 2 → 4 → 4 → 1 network
model = MLP(2, [4, 4, 1])

xs = [[2.0, 3.0], [1.0, -1.0], [-3.0, 0.5]]
ys = [1.0, -1.0, 1.0]

for k in range(200):
    ypred = [model(x)[0] for x in xs]
    loss = sum((yp - y)**2 for yp, y in zip(ypred, ys))

    # zero grads
    for p in model.parameters():
        p.grad = 0.0
    
    # backprop
    loss.backward()

    # SGD update
    for p in model.parameters():
        p.data -= 0.05 * p.grad

print("Final loss:", loss.data)

GRAPH VISUALIZATION

Bitgrad includes computational graph visualizer usin Graphviz

Saving a graph:

from bitgrad.viz import save_graph

save_graph(loss, "loss.pkl")

Rendering it:

bitgrad viz --file loss.pkl
bitgrad viz -f loss.pkl

COMMAND LINE INTERFACE

Bitgrad installs a CLI called bitgrad

XOR Demo:

bitgrad xor

About

A tiny autograd + neural network + visualization library built from scratch Inspired by Karpathy’s micrograd, extended with a visualization engine and CLI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages