A tiny PyTorch-like neural network library built from scratch using NumPy
Project description
TinyTorch
A tiny PyTorch-like neural network library built from scratch using NumPy.
This project was created to understand how deep learning frameworks like PyTorch work internally.
Features
- Linear layers
- Activation functions (ReLU, Sigmoid, Tanh, LeakyReLU, ELU, PReLU)
- Loss functions
- Optimizers (SGD, Momentum, RMSProp, Adam)
- Batch Normalization
- Dropout
- Sequential model API
- Automatic parameter detection
Installation
pip install knoxtinytorch
Quick Example
import numpy as np
from tinytorch import Sequential, Linear, ReLU
from tinytorch import MeanSquaredError, Adam
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[1],[1],[0]])
model = Sequential(
Linear(2,8),
ReLU(),
Linear(8,1)
)
loss_fn = MeanSquaredError()
optimizer = Adam(model.parameters(), lr=0.05)
for epoch in range(5000):
y_pred = model(X)
loss = loss_fn.forward(y_pred, y)
grad = loss_fn.backward()
model.backward(grad)
optimizer.step()
model.zero_grad()
Example Project
Train a neural network to learn the XOR problem.
See:
examples/xor_example.py
Project Motivation
Most deep learning users rely on frameworks like PyTorch or TensorFlow without understanding how they work internally.
This project recreates the core components of a deep learning framework from scratch using only NumPy.
GitHub
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file knoxtinytorch-0.1.1.tar.gz.
File metadata
- Download URL: knoxtinytorch-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6cf26c4a085f3e0f5f34b928519b4c6af58dad028d4e12f923d88d5b6e76d21
|
|
| MD5 |
1f72d2ddd072878812f81eaf1f935aeb
|
|
| BLAKE2b-256 |
d46f9a87d73f858ee19685b099aded41114d52afb4e380d0c9e77158c1f009b2
|
File details
Details for the file knoxtinytorch-0.1.1-py3-none-any.whl.
File metadata
- Download URL: knoxtinytorch-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b25a6fac228f920d5b1c01c3d79efbe28a95c3ccc55e743970e972c8ac9767c
|
|
| MD5 |
b9dc9b5efb8715338f1ba6df6634635a
|
|
| BLAKE2b-256 |
25b3d92022fda1d5ec7d51d6cd86c3bb19d34f8baeb3a565061949bb80715561
|