A minimal deep learning library using numpy.
Project description
torchling
A minimal neural network library. torchling is a work in progress.
Installation
pip install torchling
Example: Boston Housing Regression
import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
from torchling.models import Sequential
from torchling.layers import Linear, Tanh
from torchling.losses import MSE
from torchling.optimisers import SGD
def load_dataset():
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data"
df = pd.read_csv(url, sep=r'\s+')
X = df.iloc[:, :-1].values.astype(np.float64)
Y = df.iloc[:, -1].values.astype(np.float64)
return X, Y
def normalize(X, Y):
scaler_X = StandardScaler()
scaler_Y = StandardScaler()
X_norm = scaler_X.fit_transform(X)
Y_norm = scaler_Y.fit_transform(Y.reshape(-1, 1)).flatten()
return X_norm, Y_norm, scaler_X, scaler_Y
def denormalize(scaler, arr):
return scaler.inverse_transform(np.array(arr).reshape(-1, 1)).flatten()
X, Y = load_dataset()
X, Y, _, Y_metadata = normalize(X, Y)
X_TRAIN, Y_TRAIN = X[1:], Y[1:]
X_TEST, Y_TEST = X[:1], Y[0]
epochs = 3000
lr = 0.6
input_size = X_TRAIN.shape[1]
model = Sequential(
Linear(50, input_size=input_size),
Tanh(),
Linear(50),
Tanh(),
Linear(1),
)
optimizer = SGD(alpha=lr)
loss = MSE()
model.train(X_TRAIN, Y_TRAIN, optimizer, loss, epochs=epochs, print_every=250)
pred = model.predict(X_TEST)
print(f"Prediction - {denormalize(Y_metadata, pred)} | Actual - {denormalize(Y_metadata, [Y_TEST])}")
License
MIT
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 torchling-0.1.12.tar.gz.
File metadata
- Download URL: torchling-0.1.12.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e769237e746f552afbd5ab7429b102bd1ff671737034c68b3d07d758af9d973
|
|
| MD5 |
fe27b26b6e0716e6d2bbc89443f9e12f
|
|
| BLAKE2b-256 |
f8fe644557b468f80b4e6ecc6fc03230a3f2c5ceb029a16fbed6fefdb15e5145
|
Provenance
The following attestation bundles were made for torchling-0.1.12.tar.gz:
Publisher:
release.yaml on pbrut/torchling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchling-0.1.12.tar.gz -
Subject digest:
0e769237e746f552afbd5ab7429b102bd1ff671737034c68b3d07d758af9d973 - Sigstore transparency entry: 435559569
- Sigstore integration time:
-
Permalink:
pbrut/torchling@545e923a3ecc3941a6204526bcc7208a91c92dec -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pbrut
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@545e923a3ecc3941a6204526bcc7208a91c92dec -
Trigger Event:
push
-
Statement type:
File details
Details for the file torchling-0.1.12-py3-none-any.whl.
File metadata
- Download URL: torchling-0.1.12-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34dacdfb7575085313db95c9b33b7faf2c161c6df2e4f910e2f358ac1e6d378c
|
|
| MD5 |
39f26cbed766c49fffbf77ef6b6a77fe
|
|
| BLAKE2b-256 |
5301eda5c8ba574a32c0fa76bcbc4c596d4326b37e6af131a8908553d8aedf63
|
Provenance
The following attestation bundles were made for torchling-0.1.12-py3-none-any.whl:
Publisher:
release.yaml on pbrut/torchling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchling-0.1.12-py3-none-any.whl -
Subject digest:
34dacdfb7575085313db95c9b33b7faf2c161c6df2e4f910e2f358ac1e6d378c - Sigstore transparency entry: 435559598
- Sigstore integration time:
-
Permalink:
pbrut/torchling@545e923a3ecc3941a6204526bcc7208a91c92dec -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pbrut
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@545e923a3ecc3941a6204526bcc7208a91c92dec -
Trigger Event:
push
-
Statement type: