Skip to main content

A lightweight deep learning framework built on NumPy. Low-level customizability and high-level usability in one.

Project description

Vulpex

A lightweight deep learning framework built on NumPy. Low-level customizability and high-level usability in one.

Quick Start

Install Vulpex and build your first model in minutes.

import numpy as np
import vulpex as vpx

# Create a simple classifier
model = vpx.Model(
  vpx.Sequential(
    vpx.Linear(784, 128),
    vpx.ReLU(),
    vpx.Linear(128, 10),
    vpx.Softmax()
  )
)

# Generate some data
X_train = np.random.randn(1000, 784)
y_train = np.eye(10)[np.random.randint(0, 10, 1000)]

# Train — one line, sklearn-style
history = model.fit(
  X_train, y_train,
  epochs=20,
  batch_size=32,
  optimizer=vpx.Adam(lr=0.001),
  loss=vpx.CrossEntropy()
)

# Predict
predictions = model.predict(X_train[:5])

Two Ways to Train

High-Level (sklearn-style)

For when you want simplicity:

model = vpx.Model(
  vpx.Sequential(
    vpx.Linear(4, 16), vpx.ReLU(),
    vpx.Linear(16, 3), vpx.Softmax()
  )
)

history = model.fit(
  X_train, y_train,
  epochs=50,
  batch_size=32,
  optimizer=vpx.Adam(lr=0.001),
  loss=vpx.CrossEntropy(),
  validation_data=(X_val, y_val),
  scheduler=vpx.ReduceOnPlateau(optimizer, patience=5),
  early_stopping=vpx.EarlyStopping(patience=10)
)

Low-Level (PyTorch-style)

For when you want full control:

model = vpx.Model(
  vpx.Sequential(
    vpx.Linear(4, 16), vpx.ReLU(),
    vpx.Linear(16, 3), vpx.Softmax()
  )
)

optimizer = vpx.Adam(lr=0.001)
loss_fn = vpx.CrossEntropy()
loader = vpx.DataLoader(X_train, y_train, batch_size=32, shuffle=True)

for epoch in range(50):
  for X_batch, y_batch in loader:
    model.zero_grad()
    pred = model.forward(X_batch)
    loss = loss_fn.forward(y_batch, pred)
    grad = loss_fn.backward()
    model.backward(grad)
    optimizer.step(model.parameters())

CNN Example

model = vpx.Model(
  vpx.Sequential(
    vpx.Conv2D(1, 16, kernel_size=3, padding=1),
    vpx.BatchNorm2D(16),
    vpx.ReLU(),
    vpx.MaxPool2D(2),

    vpx.Conv2D(16, 32, kernel_size=3, padding=1),
    vpx.BatchNorm2D(32),
    vpx.ReLU(),
    vpx.MaxPool2D(2),

    vpx.Flatten(),
    vpx.Linear(32 * 7 * 7, 128),
    vpx.ReLU(),
    vpx.Dropout(0.5),
    vpx.Linear(128, 10),
    vpx.Softmax()
  )
)

model.summary((1, 28, 28))

Features

Layers

Linear, Conv1D, Conv2D, Conv3D, MaxPool1D, MaxPool2D, MaxPool3D, AvgPool1D, AvgPool2D, AvgPool3D, AdaptiveAvgPool1D, AdaptiveAvgPool2D, AdaptiveAvgPool3D, BatchNorm1D, BatchNorm2D, BatchNorm3D, LayerNorm, Dropout, Flatten, Embedding, ZeroPad1D, ZeroPad2D, ZeroPad3D, Sequential

Activations

ReLU, LeakyReLU, PReLU, ELU, SELU, GeLU, SiLU, Sigmoid, Tanh, Softmax, LogSoftmax

Loss Functions

MSE, MAE, BCE, BCEWithLogits, CrossEntropy, CrossEntropyWithLogits, NLLLoss, HuberLoss, HingeLoss, KLDivergence, CosineEmbeddingLoss, SmoothL1Loss

All loss functions support reduction='mean', 'sum', or 'none'. CrossEntropy and CrossEntropyWithLogits support class weights for imbalanced datasets.

Optimizers

Adam, AdamW, SGD, MomentumSGD, RMSProp

Training Utilities

DataLoader, train_test_val_split, StepLR, ReduceOnPlateau, EarlyStopping, clip_grad_norm, clip_grad_value

Weight Initialization

xavier_uniform, xavier_normal, he_uniform, he_normal, zeros, ones

Model Tools

# Architecture overview
model.summary((784,))

# Total trainable parameters
model.count_params()

# Save and load
model.save("my_model.vpx")
model.load("my_model.vpx")

# Train and evaluate
history = model.fit(X_train, y_train, epochs=20, batch_size=32, optimizer=optimizer, loss=loss_fn)
loss = model.evaluate(X_test, y_test, loss_fn)
preds = model.predict(X_test)

Data Utilities

# Split with optional validation set and stratified splitting
X_train, X_test, y_train, y_test = vpx.train_test_val_split(X, y, test_size=0.2, seed=42)

X_train, X_test, X_val, y_train, y_test, y_val = vpx.train_test_val_split(
  X, y, test_size=0.2, val_size=0.1, stratify=True, seed=42
)

# DataLoader for batching and shuffling
loader = vpx.DataLoader(X_train, y_train, batch_size=32, shuffle=True, drop_last=True, seed=42)

Training with Callbacks

optimizer = vpx.Adam(lr=0.01)

history = model.fit(
  X_train, y_train,
  epochs=100,
  batch_size=32,
  optimizer=optimizer,
  loss=vpx.CrossEntropy(),
  validation_data=(X_val, y_val),
  scheduler=vpx.StepLR(optimizer, step_size=20, gamma=0.1),
  early_stopping=vpx.EarlyStopping(patience=10, min_delta=0.001)
)

# Access training history
print(history["loss"])      # training loss per epoch
print(history["val_loss"])  # validation loss per epoch

Gradient Clipping

for X_batch, y_batch in loader:
  model.zero_grad()
  pred = model.forward(X_batch)
  loss = loss_fn.forward(y_batch, pred)
  grad = loss_fn.backward()
  model.backward(grad)

  vpx.clip_grad_norm(model.parameters(), max_norm=1.0)
  # or
  vpx.clip_grad_value(model.parameters(), clip_value=0.5)

  optimizer.step(model.parameters())

Custom Weight Initialization

layer = vpx.Linear(784, 256)
layer.weights.data = vpx.xavier_uniform((784, 256))

Requirements

  • Python 3.8+
  • NumPy

License

BSD-3-Clause

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vulpex-0.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vulpex-0.1.0-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file vulpex-0.1.0.tar.gz.

File metadata

  • Download URL: vulpex-0.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for vulpex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49616ff85c78e345aa0b978d7beaf444f453561b1c7d6c09390733109ed1a507
MD5 279c6485073a2207053178d5c733a7f1
BLAKE2b-256 44c1cc419ddd4c6735c6a16cb0813074648e9ae9ecd07ccdaf1bce36aef7aa04

See more details on using hashes here.

File details

Details for the file vulpex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vulpex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for vulpex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44d810d2b20d981b426ae30865c75c2c5b35854b155c7b5b95a1d0c766744567
MD5 0af5ecff31b00fe3e4fa48dcee5dccce
BLAKE2b-256 9e4e316dba25a0140397fcba152cda2fe483e68eba94374d8f37a342753a9f61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page