Skip to main content

NumPy based neural network package with PyTorch-like API

Project description

Python Version PyPI Version Status

изображение

Overview

Torchy is a neural network framework implemented only using NumPy and based on PyTorch API but with manual backpropogation calculations. The main idea was to build a neural network from scratch for educational purposes.

Installation

pip install torchy-nn

Getting started

I suggest you to take a look at currently implemented stuff to be familiar with current possibilities for building neural network models with Torchy. Also I've created package structure in case if you stuck where to get specific layers.

Example usage

First we can define our model using Torchy with its PyTorch-like API

from nn.modules.sequential import Sequential  # Same as nn.Sequential
import nn.modules.module as layer

# Define 2-layer wtth 100 neurons hidden layer.
model = Sequential(
    layer.Linear(n_input=10, n_output=100),
    layer.BatchNorm1d(n_output=100),
    layer.ReLU(),
    layer.Linear(n_input=100, n_output=2)
)

Next step is to create instances of optimizer and criterion for loss function and scheduler for fun

import nn.modules.loss as loss
import optimizers.optim as optim
import optimizers.scheduler as sched

optimizer = optim.SGD(model.params(), lr=1e-3)
criterion = loss.CrossEntropyLoss()
scheduler = sched.StepLR(optimizer, step_size=10)

I won't cover whole training process like loops and stuff, just show you main differences while training

...
predictions = model(X)  # Nothing changed

loss, grad = criterion(predictions, y)  # Now return tuple of (loss, grad) instead of only loss 

optimizer.zero_grad()
model.backward(grad)  # Call backward on model object and pass gradient from loss as argument
optimizer.forward_step()

Demonstration

The demo notebook showcases what Torchy currently can do.

Roadmap

There is still a lot of work to be done, but here are the main points that will be completed soon

  • Docstring every entity & add type hinting
  • Add evaluation & inference for model

Resources

The opportunity to create such a project was given to me thanks to these people

License

MIT License

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

torchy-nn-0.3.5.3.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torchy_nn-0.3.5.3-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file torchy-nn-0.3.5.3.tar.gz.

File metadata

  • Download URL: torchy-nn-0.3.5.3.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for torchy-nn-0.3.5.3.tar.gz
Algorithm Hash digest
SHA256 5ebf9e9946698a10f62e542d95b050d040be34c2063e5023a09aad974d3b622c
MD5 8f1d1ec6d0b863f8c711f5301b3cce8a
BLAKE2b-256 2cb45ead303ceff61764eb22a27cc594720288856ee8cc7efa78a190f84fcfe7

See more details on using hashes here.

File details

Details for the file torchy_nn-0.3.5.3-py3-none-any.whl.

File metadata

  • Download URL: torchy_nn-0.3.5.3-py3-none-any.whl
  • Upload date:
  • Size: 28.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for torchy_nn-0.3.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f394083044302df1c5fa939fd6c96552bb608e55ab6b030655d27a5a4dee1e88
MD5 b2c56c467a65d73f342618f74b460a14
BLAKE2b-256 0ac3cae1c93872245c04c78cd60f289c2ae199366c3ccfc280bd9b681fba4a9c

See more details on using hashes here.

Supported by

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