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
Metadata
Release files for torchy-nn 0.3.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| torchy-nn-0.3.5.3.tar.gz | 15.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torchy_nn-0.3.5.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 44.2 kB
Release files / torchy-nn-0.3.5.3.tar.gz
| Download URL | torchy-nn-0.3.5.3.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ebf9e9946698a10f62e542d95b050d040be34c2063e5023a09aad974d3b622c
|
|
BLAKE2b-256 checksum How to use checksums |
2cb45ead303ceff61764eb22a27cc594720288856ee8cc7efa78a190f84fcfe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / torchy_nn-0.3.5.3-py3-none-any.whl
| Download URL | torchy_nn-0.3.5.3-py3-none-any.whl |
|---|---|
| Size | 28.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f394083044302df1c5fa939fd6c96552bb608e55ab6b030655d27a5a4dee1e88
|
|
BLAKE2b-256 checksum How to use checksums |
0ac3cae1c93872245c04c78cd60f289c2ae199366c3ccfc280bd9b681fba4a9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|