Skip to main content

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

Release files for npnet 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for npnet 0.0.10
File Size Uploaded
npnet-0.0.10.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for npnet 0.0.10
File Interpreter ABI Platform
npnet-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 25.2 kB

Release files / npnet-0.0.10.tar.gz

Download URL npnet-0.0.10.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b881b5f926f4c4509ab8795c90dab78659da5b172639d5838d7fba11e5fb19f5
BLAKE2b-256 checksum
How to use checksums
8a83aaa4370562f88f7f63b68c0e839fc5f357133cbf2749f0466bf837246e94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.13

Release files / npnet-0.0.10-py3-none-any.whl

Download URL npnet-0.0.10-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1e38952af8767b8eb078e309c807690468911c1fb3f9a8be3041a29fd6d70bc
BLAKE2b-256 checksum
How to use checksums
72a3fe34105090f20527f91132816ee2523f6f8f1dd0b8929d64c72c51ea2a1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.13

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page