A minimal deep learning library built from scratch with just NumPy.
QuarkNet is a lightweight Deep learning library that's built entirely with NumPy and supports the essentials needed to train fully-connected feedforward neural networks.
- Fully Connected Linear Layers (
Linear) - Activation Functions:
Tanh,ReLU,Sigmoid - Loss Functions: Mean Squared Error (
MSE) - Optimizer: Stochastic Gradient Descent (
SGD) - Mini-batch Training with shuffling
- Layer Stacking API for building networks
- Prediction & Evaluation support
Create a virtual environment using uv
uv venv .venvActivate the virtual environment
source .venv/bin/activateInstall QuarkNet into your isolated .venv virtual environment
uv pip install quarknetpython3 -m venv .venv # Create a virtual environment
source .venv/bin/activate
pip install QuarkNet # Standard pip installThe XOR (exclusive OR) problem is a classic example in neural networks because it is non-linear and cannot be solved by a single linear layer.
import numpy as np
from quarknet.nn import NeuralNet
from quarknet.layers import Linear
from quarknet.activations import Tanh
from quarknet.loss import MSE
from quarknet.optim import SGD
# XOR inputs
inputs = np.array([
[0, 0],
[0, 1],
[1, 0],
[1, 1]
])
# XOR outputs
targets = np.array([
[0],
[1],
[1],
[0],
])
# Train the model
model.train(
inputs=inputs,
targets=targets,
loss=MSE(),
optimizer=SGD(),
epochs=5000,
batch_size=32,
shuffle=True
)
# Make predictions
predictions = model.predict(inputs)
print("Predictions:\n", np.round(predictions))Output
Predictions:
array(
[
[0.],
[1.],
[1.],
[0.],
]
)