Skip to main content

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

https://github.com/KnoxCodes/TinyTorch

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

knoxtinytorch-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

knoxtinytorch-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

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

Hashes for knoxtinytorch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d6cf26c4a085f3e0f5f34b928519b4c6af58dad028d4e12f923d88d5b6e76d21
MD5 1f72d2ddd072878812f81eaf1f935aeb
BLAKE2b-256 d46f9a87d73f858ee19685b099aded41114d52afb4e380d0c9e77158c1f009b2

See more details on using hashes here.

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

Hashes for knoxtinytorch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b25a6fac228f920d5b1c01c3d79efbe28a95c3ccc55e743970e972c8ac9767c
MD5 b9dc9b5efb8715338f1ba6df6634635a
BLAKE2b-256 25b3d92022fda1d5ec7d51d6cd86c3bb19d34f8baeb3a565061949bb80715561

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