Skip to main content

Tinkerbell is a lightweight, educational deep learning framework built entirely from scratch

Project description

Tinkerbell

Tinkerbell is a lightweight, educational deep learning framework built entirely from scratch using NumPy. It implements automatic differentiation with both forward-mode and reverse-mode autograd, modular layer architecture, optimizers, and loss functions to demonstrate the core concepts of neural networks.

Features

  • Automatic Differentiation:
    • Tensor: Reverse-mode autograd for efficient gradient computation.
    • ForwardTensor: Forward-mode autograd for educational purposes.
  • Modular Layers:
    • DenseLayer: Fully connected layer.
    • SigmoidLayer: Sigmoid activation layer.
    • SeqLayer: Sequential container for stacking layers.
  • Optimizers:
    • SGD: Stochastic Gradient Descent.
  • Loss Functions:
    • MSELoss: Mean Squared Error.
  • Additional Tools:
    • SimpleLinearRegression: Simplified linear regression implementation.
    • Progress tracking with tqdm.
    • Visualization with matplotlib.

🛠️ Installation

  1. Clone the repository:
    pip install tinkerbell
    

Quick Start

Using Tensors for Autograd

import numpy as np
from tinkerbell.tensor import Tensor

# Create tensors with gradient tracking
x = Tensor([1.0, 2.0, 3.0], requires_grad=True)
y = Tensor([4.0, 5.0, 6.0], requires_grad=True)

# Perform operations
z = x * y + Tensor([1.0, 1.0, 1.0])
z.grad = np.ones_like(z.data)  # Set gradient of z to ones
z.backward()  # Compute gradients

print(x.grad)  # Gradients w.r.t. x
print(y.grad)  # Gradients w.r.t. y

Building and Training a Neural Network

import numpy as np
from tinkerbell.tensor import Tensor
from tinkerbell.layers import DenseLayer, SigmoidLayer, SeqLayer
from tinkerbell.loss import MSELoss
from tinkerbell.optimizer import SGD

# Create dummy data
x = np.random.random((100, 3))
y = np.dot(x, np.array([[2.0], [3.0], [4.0]])) + 5.0

# Build the model
model = SeqLayer([
    DenseLayer(input_dim=3, output_dim=4),
    SigmoidLayer(),
    DenseLayer(input_dim=4, output_dim=1)
])

# Set up loss and optimizer
loss_fn = MSELoss()
optimizer = SGD(learning_rate=0.01)
model.trainer(loss=loss_fn, optimizer=optimizer)

# Train the model
model.fit(Tensor(x), Tensor(y), epochs=100, batch_size=10)

# Make predictions
predictions = model(Tensor(x))

Simple Linear Regression

from tinkerbell.simple_linear_regression import SimpleLinearRegression
import numpy as np

# Create data
x = np.random.random((100, 2))
y = np.dot(x, np.array([[2.0], [3.0]])) + 1.0

# Train model
model = SimpleLinearRegression()
model.fit(x, y, learning_rate=0.01, epochs=1000)

# Predict
predictions = model.forward(x)

Project Structure

src/
└── tinkerbell/
    ├── __init__.py
    ├── tensor.py          # Tensor classes (Tensor, ForwardTensor, Parameter)
    ├── functions.py       # Activation functions (Sigmoid)
    ├── layers.py          # Layer implementations (DenseLayer, SigmoidLayer, SeqLayer)
    ├── loss.py            # Loss functions (MSELoss)
    ├── optimizer.py       # Optimization algorithms (SGD)
    ├── simple_linear_regression.py  # Simplified linear regression
    └── legacy/            # Older implementations
        ├── __init__.py
        ├── core.py
        ├── functions.py
        ├── layers.py
        ├── loss.py
        ├── models.py
        └── optimizer.py
main.py                    # Entry point
pyproject.toml             # Project configuration
test.ipynb                 # Jupyter notebook for testing and examples
README.md                  # This file

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Authors

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

tinkerbell-0.2.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

tinkerbell-0.2.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file tinkerbell-0.2.0.tar.gz.

File metadata

  • Download URL: tinkerbell-0.2.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tinkerbell-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c4b9a2b5e0be9be85f1c4613ced61d8ee5eb62ea814ce1d19ec05ddd4dc0db46
MD5 b811264a7d87e7145e6f1e72c19327b6
BLAKE2b-256 403b789152af1bd8d7ace196414210e0f53f11d25dbaf20289f9ee094e10a116

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinkerbell-0.2.0.tar.gz:

Publisher: pypi-publish.yml on aaishwarymishra/tinkerbell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tinkerbell-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tinkerbell-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tinkerbell-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7258ab8a89e461a74bb30e2f92e374c2d46de368163967ae5334f84f5e2654d2
MD5 b2dbb9739deaba36a7d16c2a40140cc0
BLAKE2b-256 7e2b20c4a8b8a27a4f855f47b620701a61a9674d590efd6e117cce38aebd7acf

See more details on using hashes here.

Provenance

The following attestation bundles were made for tinkerbell-0.2.0-py3-none-any.whl:

Publisher: pypi-publish.yml on aaishwarymishra/tinkerbell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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