All Projects → kennysong → Minigrad

kennysong / Minigrad

A minimal implementation of autograd (in pure Python) 🍰

Projects that are alternatives of or similar to Minigrad

Image Classification Using Cnn And Keras
Classify images, specifically document images like ID cards, application forms, and cheque leafs, using CNN and the Keras libraries.
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Sentiment Analysis Nltk Ml Lstm
Sentiment Analysis on the First Republic Party debate in 2016 based on Python,NLTK and ML.
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Wikipedia ner
📖 Labeled examples from wiki dumps in Python
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Learn To Code For Data Analysis
Jupyter notebooks and datasets for this course
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Activityinequality
Data release for Activity Inequality paper
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Keras stft layer
Do STFT in Keras
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Fromscratch
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Kaggle moa winner hungry for gold
Winning Solution of Kaggle Mechanisms of Action (MoA) Prediction.
Stars: ✭ 62 (+0%)
Mutual labels:  jupyter-notebook
Hands On Machine Learning
Contains Jupyter Notebooks/Resources provided by the author and my work on problem sets.
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
3dscanscience
All scientific background, image processing, calibration and scanning algorithms for 3D laser scanner in IPython notebooks
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Ntds 2017
Material for the EPFL master course "A Network Tour of Data Science", edition 2017.
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
The evolution of gradient descent
This is the code for "The Evolution of Gradient Descent" by Siraj Raval on Youtube
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Titanic Machine Learning
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Principles Of Machine Learning R
Principles of Machine Learning R
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Pychebfun
Python implementation of chebfun
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Pose estimation cvpr eccv 2018
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
4tu Css
Material for a Computational Social Science (CSS) Workshop hosted by the four Dutch technical universities.
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Weakly Supervised 3d Object Detection
Weakly Supervised 3D Object Detection from Point Clouds (VS3D), ACM MM 2020
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Tjo.hatenablog.samples
Samples for tjo.hatenablog
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook
Sentiment Analysis With Convolutional Networks
Convolutional Neural Network model for Sentiment Analysis of IMDB movie reviews
Stars: ✭ 61 (-1.61%)
Mutual labels:  jupyter-notebook

MiniGrad

A minimal implementation of reverse-mode automatic differentiation (a.k.a. autograd / backpropagation) in pure Python.

Inspired by Andrej Karpathy's micrograd, but with more comments and less cleverness. Thanks for the wonderful reference implementation and tests!

Overview

Create a Scalar.

a = Scalar(1.5)

Do some calculations.

b = Scalar(-4.0)
c = a**3 / 5
d = c + (b**2).relu()

Compute the gradients.

d.backward()

Plot the computational graph.

draw_graph(d)

Repo Structure

  1. demo.ipynb: Demo notebook of MiniGrad's functionality.
  2. tests.ipynb: Test notebook to verify gradients against PyTorch and JAX. Install both to run tests.
  3. minigrad/minigrad.py: The entire autograd logic in one (~100 loc) numeric class. See section below for details.
  4. minigrad/visualize.py: This just draws nice-looking computational graphs. Install Graphviz to run it.
  5. requirements.txt: MiniGrad requires no external modules to run. This file just sets up my dev environment.

Implementation

MiniGrad is implemented in one small (~100 loc) Python class, using no external modules.

The entirety of the auto-differentiation logic lives in the Scalar class in minigrad.py.

A Scalar wraps a float/int and overrides its arithmetic magic methods in order to:

  1. Stitch together a define-by-run computational graph when doing arithmetic operations on a Scalar
  2. Hard code the derivative functions of arithmetic operations
  3. Keep track of ∂self/∂parent between adjacent nodes
  4. Compute ∂output/∂self with the chain rule on demand (when .backward() is called)

This is called reverse-mode automatic differentiation. It's great when you have few outputs and many inputs, since it computes all derivatives of one output in one pass. This is also how TensorFlow and PyTorch normally compute gradients.

(Forward-mode automatic differentiation also exists, and has the opposite advantage.)

Not in Scope

This project is just for fun, so the following are not planned:

  • Vectorization
  • Higher order derivatives (i.e. Scalar.grad is a Scalar itself)
  • Forward-mode automatic differentiation
  • Neural network library on top of MiniGrad
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].