Skip to main content

A simple autograd engine along with a PyTorch/Tensorflow like API module 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(); output.label='output'

output.backward()

draw(output)

2. Neural Net Implementation

from micronets.nn import DNN  # Dense Neural Network
from micronets.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(input_features=3, layers=[2,2,1], activations=['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.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: micronets-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 0c500f912492789f1e22c0719e4cab1168c765c8419d538d33a7fe1a23e0762e
MD5 1657931f5607e447f54f3aaa879abc3a
BLAKE2b-256 bb0bba0b3fc09bbefa3deefe5d198c2f9c65c2d73739c91e0f3fd92627de26f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: micronets-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b28b43c0be12f308f92e60a07af84e16fce5d34746eed29cd8c015ce78a853e
MD5 c2c3b22169a9e97f869f19182642b5cc
BLAKE2b-256 d808ed92c87bd321d3647991040445e87e936ecfcc335e2668e3275fe700b3ed

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 Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page