Skip to main content

neural net powered by numpy

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

npnet-0.0.10.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

npnet-0.0.10-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file npnet-0.0.10.tar.gz.

File metadata

  • Download URL: npnet-0.0.10.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.13

File hashes

Hashes for npnet-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b881b5f926f4c4509ab8795c90dab78659da5b172639d5838d7fba11e5fb19f5
MD5 64cb58c6360b924295ce74b4793f3539
BLAKE2b-256 8a83aaa4370562f88f7f63b68c0e839fc5f357133cbf2749f0466bf837246e94

See more details on using hashes here.

File details

Details for the file npnet-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: npnet-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.13

File hashes

Hashes for npnet-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 a1e38952af8767b8eb078e309c807690468911c1fb3f9a8be3041a29fd6d70bc
MD5 a0d1cdba005eb655eeb02469d8814ee6
BLAKE2b-256 72a3fe34105090f20527f91132816ee2523f6f8f1dd0b8929d64c72c51ea2a1a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page