picograd
A lightweight machine learning framework
Description • Features • Examples • References • License
Description
A PyTorch-like lightweight deep learning framework written from scratch in Python.
The library has a built-in auto-differentiation engine that dynamically builds a computational graph. The framework is built with basic features to train neural nets: optimizers, training API, data utilities, metrics and loss functions. Additional tools are developed to visualize forward computational graph.
Features
- PyTorch-like auto-differentiation engine (dynamically constructed computational graph)
- Keras-like simple training API
- Neural networks API
- Activations: ReLU, Sigmoid, tanh
- Optimizers: SGD, Adam
- Loss: Mean squared error
- Accuracy: Binary accuracy
- Data utilities
- Computational graph visualizer
Examples
The demo notebook showcases what picograd is all about.
Example Usage
from picograd.engine import Var
from picograd.graph_viz import ForwardGraphViz
graph_builder = ForwardGraphViz()
x = Var(1.0, label='x')
y = (x * 2 + 1).relu();
y.label = 'y'
y.backward()
graph_builder.create_graph(y)
Output:
Training MLP
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.datasets import make_moons
from picograd.nn import MLP
from picograd.engine import Var
from picograd.data import BatchIterator
from picograd.trainer import Trainer
from picograd.optim import SGD, Adam
from picograd.metrics import binary_accuracy, mean_squared_error
# Generate moon-shaped, non-linearly separable data
x_train, y_train = make_moons(n_samples=200, noise=0.10, random_state=0)
model = MLP(in_features=2, layers=[16, 16, 1], activations=['relu', 'relu', 'linear']) # 2 hidden layers
print(model)
print(f"Number of parameters: {len(model.parameters())}")
optimizer = SGD(model.parameters(), lr=0.05)
data_iterator = BatchIterator(x_train, list(map(Var, y_train)))
trainer = Trainer(model, optimizer, loss=mean_squared_error, acc_metric=binary_accuracy)
history = trainer.fit(data_iterator, num_epochs=70, verbose=True)
Decision boundary:
References
- Andrej Karpathy's micrograd library and intro explanation on training neural nets, which is the foundation of picograd's autograd engine.
- Baptiste Pesquet's pyfit library, from which training API was borrowed.
License
MIT
Metadata
Release files for picograd 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| picograd-1.0.5.tar.gz | 111.3 kB | Without provenance | Details for picograd-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| picograd-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for picograd-1.0.5-py3-none-any.whl |
Total release size: 217.1 kB
Release files / picograd-1.0.5.tar.gz
| Download URL | picograd-1.0.5.tar.gz |
|---|---|
| Size | 111.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64a154c48bb7f00818626f41a4f2a6643b03b1c445117145112408c6af8d952c
|
|
BLAKE2b-256 checksum How to use checksums |
73894f3390c0877841c63a45afad34c90dc5f4d13d9f47551a8b9b7cc4072fe2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Release files / picograd-1.0.5-py3-none-any.whl
| Download URL | picograd-1.0.5-py3-none-any.whl |
|---|---|
| Size | 105.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92258a99f474ee543515f685dff7efc159d33bbaa0d1aa06717cee5daa26c7ab
|
|
BLAKE2b-256 checksum How to use checksums |
96e62890d2d5340a3ba4ee2fdfd58c5efcbf8ccd5f86abdbdf86cc2cd5fad4db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.14
|
Security for picograd 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.