Giter Club home page Giter Club logo

micrograd-karpathy-sensei's Introduction

A tiny implementation of PyTorch's autograd engine

Based on Karpathy sensei's micrograd engine, this project implements from scratch, a minimalist neural network library featuring backpropagation through automatic differentiation on a dynamically built DAG. I wanted to take my learnings to the next level so I added a few improvements:

  1. Incorporated full support for vector values and mathematical operations like dot product and concat.
  2. Convenient methods in the MLP class to predict outputs and train neural networks.

Using tinygrad

Trying out on a tiny dataset

xs = [
    [2, 3, -1],
    [3, -1, 0.5],
    [0.5, 1, 1],
    [1, 1, -1],
]

ys = [1, -1, -1, 1]

Initialising the network

# 3 featured input shape, (5, 4, 1) neural network shape
n = MLP(3, [5, 4, 1])

Making predictions and calculating the RMS loss

predictions = n.predict(xs)
loss_before_training = n.loss(predictions, ys).data
print(f"Loss before training: {loss_before_training} and predictions: {predictions}")

# prints Loss before training: 14.646449126643851 and predictions: [17.067146324690277, 15.92326097064621, 15.238256397218107, 8.059954982580635]

Training the network

loss_after_training = n.train(xs, ys, iterations=1000, lr=0.01)
print(f"Loss after training: {loss_after_training['loss']} and predictions: {loss_after_training['predictions']}")

# prints Loss after training: 0.7102683487043046 and predictions: [1.0597375025781735, 0.0, 0.0, 0.8801837261876291]

micrograd-karpathy-sensei's People

Contributors

samz905 avatar

Stargazers

 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.