Skip to content
Simple neural networks based only on Numpy
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
neuralnets show test probability Nov 2, 2018 add CNN support Oct 30, 2018
demo.png init net Oct 27, 2018
mnist.npz add CNN support Oct 30, 2018 add saver Oct 27, 2018 init net Oct 27, 2018 show test probability Nov 2, 2018 update code Nov 2, 2018 add CNN support Oct 30, 2018

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 neuralnets as nn

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

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

The training procedure starts by defining a optimizer and loss.

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

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


Download or fork

Download link

Fork this repo:

$ git clone



You can’t perform that action at this time.