Skip to main content

A comprehensive deep learning framework built from scratch in Python with PyTorch-like API

Project description

Mayini Framework

PyPI Python 3.8+ Build Status Test Coverage License MIT

Mayini is a comprehensive, from-scratch Deep Learning and Machine Learning framework built in pure Python. Designed with a clean, PyTorch-like API, it aims to demystify underlying AI mechanics while providing robust, high-performance features for deep neural networks, classical ML models, evolutionary algorithms, and multimodal data preprocessing.

Whether you're researching new topologies, learning the mathematics of backpropagation, or deploying classical models, Mayini has you covered.


📦 Installation

Install Mayini directly from PyPI via pip:

pip install mayini-framework==0.9.0

If you wish to edit the source code and contribute:

git clone https://github.com/907-bot-collab/mayini.git
cd mayini
pip install -e .[dev]

🚀 Key Modules & Architecture

The framework is divided into five highly independent yet composable pillars:

1. 🧠 mayini.tensor (The Autograd Engine)

A custom multidimensional array computing engine built on top of NumPy. It features a complete define-by-run Automatic Differentiation (Autograd) computational graph, ensuring mathematically guaranteed gradients for neural network backpropagation.

  • Precision preserved elegantly across massive operations (float64 strict type preservation).
  • Full broadcasting semantics for operations (add, matmul, pow, sum).
  • Topologically sorted backwards passes.

2. 🔌 mayini.nn (Deep Learning)

A rich PyTorch-like Neural Network library mapping seamlessly to the Tensor backend.

  • Layers: Linear, Conv2D, RNN
  • Activations: ReLU, Sigmoid, Tanh, Softmax
  • Optimizers: Adam, RMSprop, SGD (with momentum)
  • Losses: MSELoss, CrossEntropyLoss, BCELoss
  • Structure: Standardized Module inheritance blocks with recursive parameter registration.

3. 🤖 mayini.ml (Classical Machine Learning)

Robust statistical and classical machine learning algorithms, optimized for clarity and speed.

  • Supervised: Support Vector Machines (SVM), K-Nearest Neighbors (KNN), Decision Trees, Naive Bayes, Linear & Logistic Regression.
  • Unsupervised: K-Means Clustering, PCA (Principal Component Analysis), Isolation Forests (Anomaly Detection).
  • Ensembles: Bagging, Boosting (AdaBoost/Gradient style), Voting implementations.

4. 🧬 mayini.neat (NeuroEvolution of Augmenting Topologies)

A custom, fully-featured implementation of NEAT. Instead of relying on gradient descent, NEAT evolves both the topological structure and weights of artificial neural networks using genetic algorithms.

  • Dynamically mutate network structures (add nodes, add connections).
  • Speciation to protect topological innovations from being wiped out early.
  • Custom activation registries and highly-configurable fitness evaluators.

5. 🛠️ mayini.preprocessing (Multimodal Pipelines & Gradio Widget)

An enterprise-grade multimodal data preprocessor spanning Text, Image, Audio, and Video.

  • No-Code Interactive Widget: Launch a Gradio-powered UI to visualize and build your preprocessing pipelines instantly! Run cleaning, transformations, and feature extractions directly from your browser.
  • Text: TF-IDF, Stemming, Tokenization, Text Normalization.
  • Image: Bilinear Resizing, Sobel Edge Detection, Datagen Augmentations.
  • Audio: STFT Spectrograms, MFCC feature extraction, Pitch Shifting.

💻 Code Examples & Quick Start

Example 1: Basic Autograd Calculus

from mayini.tensor import Tensor

# Define variables with gradient tracking
x = Tensor([2.0], requires_grad=True)
y = Tensor([3.0], requires_grad=True)

# Build a computational graph
z = (x ** 2) + (x * y)

# Compute gradients
z.backward()

print(f"z = {z.data}")         # z = 10.0
print(f"dz/dx = {x.grad}")     # 2x + y = 7.0 
print(f"dz/dy = {y.grad}")     # x = 2.0

Example 2: Training a Multilayer Perceptron (MLP)

from mayini.tensor import Tensor
import mayini.nn as nn
import mayini.optim as optim

# 1. Define Model Architecture
class MLP(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc1 = nn.Linear(2, 16)
        self.fc2 = nn.Linear(16, 1)
        self.relu = nn.ReLU()
        self.sigmoid = nn.Sigmoid()

    def forward(self, x):
        out = self.relu(self.fc1(x))
        return self.sigmoid(self.fc2(out))

model = MLP()

# 2. Setup Optimizer & Loss Metric
optimizer = optim.Adam(model.parameters(), lr=0.01)
criterion = nn.BCELoss()

# 3. Create Dataset (XOR problem)
X = Tensor([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = Tensor([[0], [1], [1], [0]])

# 4. Training Loop
for epoch in range(200):
    optimizer.zero_grad()
    predictions = model(X)
    loss = criterion(predictions, Y)
    loss.backward()
    optimizer.step()

print(f"Final Model Loss: {loss.data}")

Example 3: Training an SVM (Classical ML)

import numpy as np
from mayini.ml.supervised.svm import SVM

# Generate random dummy data
X = np.array([[1, 2], [1, 3], [5, 6], [6, 5]])
y = np.array([1, 1, -1, -1])

# Initialize Support Vector Machine
model = SVM(learning_rate=0.001, lambda_param=0.01, n_iters=1000)
model.fit(X, y)

# Predict
predictions = model.predict(np.array([[2, 2], [5, 5]]))
print(f"Predictions: {predictions}")

Example 4: Launching the Gradio Preprocessor UI

Tired of formatting complex data arrays blindly? Use the built-in Gradio widget to instantly mock your pipelines:

from mayini.preprocessing.widget import launch_widget

# Automatically opens the local server at http://localhost:7860
launch_widget()

🛠️ Testing & Stability

Mayini relies on rigorous regression testing to ensure robust deployments.

  • The framework guarantees 100% test suite stability.
  • The mayini.tensor operations are validated against scipy.optimize finite difference algorithms to ensure mathematically flawless differentiation boundaries.

Run the test suite locally:

pytest -v test/

🤝 Contributing

Contributions are always welcome. To get started:

  1. Fork the codebase and branch off main.
  2. Ensure you add robust unittests (pytest) for any mathematical algorithm updates.
  3. Submit a Pull Request.

📄 License

This project is licensed under the MIT License. See the LICENSE file for the full legal layout.

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

mayini_framework-0.9.1.tar.gz (190.6 kB view details)

Uploaded Source

Built Distribution

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

mayini_framework-0.9.1-py3-none-any.whl (210.8 kB view details)

Uploaded Python 3

File details

Details for the file mayini_framework-0.9.1.tar.gz.

File metadata

  • Download URL: mayini_framework-0.9.1.tar.gz
  • Upload date:
  • Size: 190.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for mayini_framework-0.9.1.tar.gz
Algorithm Hash digest
SHA256 985d3f0b91d6a4dfaef6432bc0570b1b87d021f3cbc381cf6f631e2500e5232b
MD5 b676e5b23026eeae25fdd3b4e88c555e
BLAKE2b-256 feafe4ad4cd670217696c3c85cd373793ac1d158246c4d4c46665402702a0230

See more details on using hashes here.

File details

Details for the file mayini_framework-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mayini_framework-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0b2a16aa99e7204d2d9317428f806ecf2cc13d7766c7e033e8d067b8ae08f7b
MD5 8fb0a06e9917aef2c5e7bd8e39f7322e
BLAKE2b-256 ab98fcd14cae874777721c270e0f0a0fab0a7b5736afe48cf1cccca1b039748d

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