Tiny NumPy-based tensors and neural-network building blocks for teaching and quick experiments.
Project description
hackwhiz
Tiny NumPy-based tensors, layers, and optimizers intended for teaching and quick experiments.
Features
- Lightweight
Tensorwrapper with handy creation helpers (rand,randn,zeros,ones,eye,arange) and NumPy interoperability. - Minimal neural network pieces:
Linear,Relu,CrossEntropy, and a simpleModuleinterface. - Straightforward SGD optimizer plus
DatasetandDataLoaderutilities for batching. - Pure Python on top of NumPy, so it runs anywhere NumPy does.
Installation
pip install hackwhiz
Quickstart
import hackwhiz as hw
from hackwhiz import nn, optim
hw.manual_seed(7)
class Model(nn.Module):
def __init__(self):
self.layers = [
nn.Linear(2, 4),
nn.Relu(),
nn.Linear(4, 2),
]
self.loss = nn.CrossEntropy()
def forward(self, x, targ):
for layer in self.layers:
x = layer(x)
return self.loss(x, targ)
def backward(self):
self.loss.backward()
for layer in reversed(self.layers):
layer.backward()
model = Model()
opt = optim.SGD(model.parameters(), lr=0.1)
x = hw.tensor([[1.0, 0.0], [0.0, 1.0], [1.0, 1.0], [0.0, 0.0]])
y = hw.tensor([0, 1, 0, 1])
for _ in range(50):
opt.zero_grad()
loss = model(x, y)
model.backward()
opt.step()
print(f"final loss: {loss.item():.4f}")
Development
- Create an environment and install in editable mode:
python -m venv .venv && source .venv/bin/activate && pip install -e .. - Run the example script above to sanity-check changes.
- Build a release:
pip install build twine && python -m buildthentwine check dist/*andtwine upload dist/*.
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
hackwhiz-0.1.1.tar.gz
(3.2 kB
view details)
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 hackwhiz-0.1.1.tar.gz.
File metadata
- Download URL: hackwhiz-0.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5c7eb6037b5d0cdb4b00e710b07ceffb1122f52c0e58168a81076a69f649c5c
|
|
| MD5 |
7aec116f3d503f2c4301bd32b835f495
|
|
| BLAKE2b-256 |
86edba8305d718c7f065e2211c593a1be6a69744a672c4c73c6cec8f2fb1a969
|
File details
Details for the file hackwhiz-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hackwhiz-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce1a33dcfa52fa4e258dc6cb774e31767e0e8d935e6b4613aa69b8a1a46016ec
|
|
| MD5 |
05ffaec13df98dc26b6e8f806513f252
|
|
| BLAKE2b-256 |
dad9329d86d789f3e539b36d6a85b384299220bcbafec8647319962d1208d7cb
|