This is a machine learning--more specifically deep learning--library from my independent study on deep learning. This library is both a result of my learning and a tool for AI development.
Project description
Deeplearning Package
Overview
This package is designed to be similar to the PyTorch system of a building block system, providing functions that can be mixed, matched, and customized for any given model. It implements core deep learning concepts including automatic differentiation, sequential modeling, various layer types (CNN, RNN, Attention), optimization algorithms, and utilities for model saving and loading.
Modules
This project contains several key modules:
autogradient.pysequence.pyoptimizer.pyneural_net.pycnn_layers.pyrnn_layers.pyattention.pysave_load_funcs.py
All of which are automatically part of the initial import of the package.
Detailed Module Descriptions
autogradient.py
This module forms the core of the automatic differentiation system. It introduces the Values class, which tracks computational history to compute gradients.
ValuesClass: Encapsulates numerical values (vals) and their corresponding gradients (grad). It supports a wide array of operations and tensor manipulations.- Broadcasting Support: Includes a sophisticated
_broadcast_gradstatic method that automatically handles gradient shape adjustments during backpropagation when operations involve broadcasted NumPy arrays (e.g., adding a bias vector to a matrix or operations with varying input dimensions). - Operations: Supports a comprehensive set of operations including arithmetic (
+,-,*,/,@,**), activation functions (relu,tanh,softmax,log,exp), and crucial tensor manipulations (reshape,transpose,pad,sum,mean,max,abs, and flexible slicing/indexing via__getitem__and__setitem__). It also provides direct access to the NumPyT(transpose) attribute.
rnn_layers.py
This module provides implementations for Recurrent Neural Networks, suitable for sequential data processing.
FullRNNLayer: Implements a standard RNN layer with configurable input, hidden, and output dimensions. It supports different activation functions (tanhby default) and handles input sequence transposition for flexible batching. The_rnn_cell_forwardmethod details the computation for a single time step, integrating input, previous hidden state, and biases to produce the current hidden state and output.
cnn_layers.py
Implements fundamental building blocks for Convolutional Neural Networks.
Reshape: Enables built in reshaping, usesnp.ndarray.reshape(...), and takes thesizeas the input. Backpropagation is enabled for it.Convo2D: Supports 2D convolution with configurablekernel_matrix,padding('valid' or 'same'), andstride. It automatically calculates output dimensions and applies padding. Gradients are computed for the kernel during backpropagation.- Pooling: Includes
MaxPoolingandAvgPoolingclasses, which perform spatial down-sampling operations with specifiedpool_sizeandstride.
neural_net.py
Defines high-level components for neural network construction, training, and regularization.
Layer: Represents a single fully connected layer with weights, biases, and a customizable activation function (e.g.,relu,softmax,tanh) dynamically accessed viagetattr.Dense: A multi-layered dense block, composed of multipleLayerinstances, allowing for easy creation of deep fully connected networks.Dropout: A regularization technique to prevent overfitting by randomly setting a fraction of input units to zero during training.Model: The central class for defining, training, and evaluating neural networks. It wraps aSequenceof blocks, manages anoptimizer, and handles the training loop, batching, and integration with variousloss_fn(e.g.,cross_entropy_loss,mse_loss) andpen_fn(e.g.,l1_reg,l2_reg).- Loss Functions:
cross_entropy_lossandmse_lossare provided for common supervised learning tasks. - Penalty Functions:
l1_reg(L1 regularization) andl2_reg(L2 regularization) are available to apply penalties to model weights during training, helping to prevent overfitting.
optimizer.py
Implements various parameter update algorithms to minimize the loss function during training.
Optimizer(Base Class): Defines the common interface for all optimizers.Optim_SGD: Stochastic Gradient Descent with an optional learning rate scheduler (finitters,fin_l_rate).Optim_SGD_Momentum: SGD with momentum to accelerate convergence and dampen oscillations.Optim_AdaGrad: Adaptive Gradient algorithm, which scales learning rates for each parameter individually.Optim_RMSPropclass: RMSProp optimizer, an adaptive learning rate method that divides the learning rate by an exponentially decaying average of squared gradients.Optim_Adam: Adaptive Moment Estimation, combining ideas from Momentum and RMSProp for efficient optimization.
sequence.py
Provides the Sequence container to stack layers and manage parameter retrieval and setting across the model. It allows for a straightforward, sequential construction of neural networks.
attention.py
This module implements mechanisms for attention, crucial for modern sequence models like Transformers.
Embedding: Converts discrete tokens (elements) into dense vector representations. It manages a vocabulary (encoder,decoder) and provides functionality toencodeelements to indices,decodeindices back to elements, and generate embeddings for input sequences. It supports both raw elements and pre-encoded indices as input.AttentionHead: The core component of self-attention. It projects input features into Query (Q), Key (K), and Value (V) representations, calculates attention scores (S) via dot product, normalizes them usingsoftmaxto getA(attention weights), and computes the weighted sum of Value vectors (Y).AttentionMultiHead: Combines multipleAttentionHeadinstances in parallel. It concatenates the outputs of individual heads and projects them through a final linear layer (w_0), allowing the model to jointly attend to information from different representation subspaces at different positions.
save_load_funcs.py
This module provides utility functions for saving and loading model parameters, enabling persistence of trained models.
getModelSave: Extracts the numerical values of all trainable parameters (weights and biases) from a given model and converts them into a list of standard Python lists (or NumPy arrays), suitable for serialization (e.g., to JSON, Pickle, or other formats).modelLoadParams: Takes a list of parameter matrices (either NumPy arrays orValuesobjects) and loads them back into aModelinstance, setting the model's weights and biases to the provided values. This allows for reloading previously saved model states.
Dependencies
The package relies heavily on numpy for numerical operations and gradient tracking.
Version 1.0.0 Notice
The addition of this updated description marks the end of the primary development of this package (and the end of my independent study course on this topic). Any 1.0.x will be simple bug fixes to this release. If I do continue to update this in the future they'll be under 1.x versions.
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 rb_deeplearning_lib-1.0.1.tar.gz.
File metadata
- Download URL: rb_deeplearning_lib-1.0.1.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8055b1d3bb15eb7a4a9af1888d8381eab69eba349cd9d888c402b41dee7907e2
|
|
| MD5 |
a0a6be29530121bc58caa6ed939604a0
|
|
| BLAKE2b-256 |
09c6f8f20037af88dbcd11daac5067e8f897f8b2f066ac25ecd58bfcfe84f248
|
File details
Details for the file rb_deeplearning_lib-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rb_deeplearning_lib-1.0.1-py3-none-any.whl
- Upload date:
- Size: 17.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c83026d213a2692d5b15ac66174616f4ecb9431bf47e0e622b4b5067a483d0ab
|
|
| MD5 |
6e8d839193e1d7ff73e1764575e45050
|
|
| BLAKE2b-256 |
7496ec72e8a0459af0ae2571ce4835d23076a5ba2d0456b3fa63cd68cb4262ca
|