Giter Club home page Giter Club logo

npnet's Introduction

Simple Neural Networks

This is a repo for building a simple Neural Net based only on Numpy.

The usage is similar to Pytorch. There are only limited codes involved to be functional. Unlike those popular but complex packages such as Tensorflow and Pytorch, you can dig into my source codes smoothly.

The main purpose of this repo is for you to understand the code rather than implementation. So please feel free to read the codes.

Simple usage

Build a network with a python class and train it.

import npnet

class Net(npnet.Module):
    def __init__(self):
        super().__init__()
        self.l1 = npnet.layers.Dense(n_in=1, n_out=10, activation=npnet.act.tanh)
        self.out = npnet.layers.Dense(10, 1)

    def forward(self, x):
        x = self.l1(x)
        o = self.out(x)
        return o

The training procedure starts by defining an optimizer and loss.

net = Net()
opt = npnet.optim.Adam(net.params, lr=0.1)
loss_fn = npnet.losses.MSE()

for _ in range(1000):
    o = net.forward(x)
    loss = loss_fn(o, y)
    net.backward(loss)
    opt.step()

Demo

Install

pip install npnet

Download or fork

Download link

Fork this repo:

$ git clone https://github.com/MorvanZhou/npnet.git

Results

img

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.