Skip to main content

A simple autograd engine along with PyTorch/Tensorflow like API to easily train neural nets

Project description

Micronets

Micronets is a python framework for the simple implementation and training of deep neural networks. The project consists of a small auto-gradient engine module which implements back propagation through a DAG (Directed Acyclic Graph) and a module resembling the PyTorch/Tensorflow APIs to create and train dense neural networks on top of it.

The package also provides additional functionalities such as plotting of the training curve, make predictions and visualisation of computational graphs after training

Installation

pip install micronets

Usage

1. Building Computational Graphs

from micronets.autograd_engine import Value
from micronets.graph import draw

#inputs
x1 = Value(2.0,label='x1')
x2 = Value(4.0, label='x2')

#weights
w1 = Value(-3.0,label='w1')
w2 = Value(1.0,label='w2')

#bias
b = Value(3.3,label='b')

x1w1=x1*w1; x1w1.label='x1*w1'
x2w2=x2*w2; x2w2.label='x2*w2'

x1w1x2w2 = x1w1+x2w2; x1w1x2w2.label='x1w1 + x2w2'

z = x1w1x2w2 + b; z.label='z'

output = z.tanh(); out.label='output'

output.backward()

draw(out)

Output :

[image placeholder graph1]

2. Neural Net Implementation

from nn import DNN  # Dense Neural Network
from losses import binary_cross_entropy


xs = [
    [2.0, 3.0, -1.0],
    [3.0, -1.0, 0.5],
    [-0.5, -1.0, -1.0],
    [-1.0, -1.0, 0.5]
]

ys = [1.0, 0.0, 1.0, 0.0]

model = DNN(inpu3, [2,2,1], ['relu', 'relu', 'sigmoid'])  # creates model architecture

history, graph = model.train(X=xs, Y=ys, iterations=500, loss_function=binary_cross_entropy, learning_rate=0.1)  # trains network and stores loss function history and computational graph

predictions = model.predict([  # outputs predictions
    [2.0, -1.0, 3.5],
    [-1.0, -3.0, 0.5]
]) 

model.plot(history)  # plots learning curve

Additionally the playground.ipynb file demonstrates functionality through a more complex example along with its outputs.

Lastly, a big thank you to Andrej Karpathy for inspiring this project :)

License

MIT

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

micronets-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

micronets-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file micronets-0.1.0.tar.gz.

File metadata

  • Download URL: micronets-0.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for micronets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3086e57dc74f9c84722aa8efb944dd399093ff5f07a3300b423118cbae22efb1
MD5 f006766eae482daaf7b776d846ddc9b3
BLAKE2b-256 d31cebbf863dc354795ddc3bacd5050e7289f7b0c369f12ed3095d20fbf0af6c

See more details on using hashes here.

File details

Details for the file micronets-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: micronets-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for micronets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 36058011cc854eac1460173e95c05d56abac7503011ac888ea1fa012b73746b2
MD5 25aee79feddde6321b9259a8da29fa2c
BLAKE2b-256 a6c8fc086207092a90a8f1211160be689531c53a7020a2399dfee72bebd8bb7b

See more details on using hashes here.

Supported by

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