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
- 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
- Aaiswarya Mishra - aaishwarymishra@gmail.com
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4b9a2b5e0be9be85f1c4613ced61d8ee5eb62ea814ce1d19ec05ddd4dc0db46
|
|
| MD5 |
b811264a7d87e7145e6f1e72c19327b6
|
|
| BLAKE2b-256 |
403b789152af1bd8d7ace196414210e0f53f11d25dbaf20289f9ee094e10a116
|
Provenance
The following attestation bundles were made for tinkerbell-0.2.0.tar.gz:
Publisher:
pypi-publish.yml on aaishwarymishra/tinkerbell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinkerbell-0.2.0.tar.gz -
Subject digest:
c4b9a2b5e0be9be85f1c4613ced61d8ee5eb62ea814ce1d19ec05ddd4dc0db46 - Sigstore transparency entry: 863166426
- Sigstore integration time:
-
Permalink:
aaishwarymishra/tinkerbell@e96a7a17547442b12113659d0fc9fe6f2a21af89 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aaishwarymishra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@e96a7a17547442b12113659d0fc9fe6f2a21af89 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7258ab8a89e461a74bb30e2f92e374c2d46de368163967ae5334f84f5e2654d2
|
|
| MD5 |
b2dbb9739deaba36a7d16c2a40140cc0
|
|
| BLAKE2b-256 |
7e2b20c4a8b8a27a4f855f47b620701a61a9674d590efd6e117cce38aebd7acf
|
Provenance
The following attestation bundles were made for tinkerbell-0.2.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on aaishwarymishra/tinkerbell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tinkerbell-0.2.0-py3-none-any.whl -
Subject digest:
7258ab8a89e461a74bb30e2f92e374c2d46de368163967ae5334f84f5e2654d2 - Sigstore transparency entry: 863166453
- Sigstore integration time:
-
Permalink:
aaishwarymishra/tinkerbell@e96a7a17547442b12113659d0fc9fe6f2a21af89 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/aaishwarymishra
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@e96a7a17547442b12113659d0fc9fe6f2a21af89 -
Trigger Event:
push
-
Statement type: