Skip to main content

Yet another ML library!

Project description

rawML

rawML is a small hobby project where neural networks are implemented from scratch using pure Python and Numpy, with a class-based structure to define layers, optimizers, and loss functions. The goal is to implement how neural networks work at a low level, and create a (somewhat) modular custom code framework to implement ML algorithms, without relying on high-level deep learning frameworks like TensorFlow or PyTorch.

Overview of current implementations:

  • Linear Layers: Fully connected layers with He-initialization of weights.
  • Activation Functions: ReLU activation implemented using numpy.
  • Custom Tensor Class: jTensor, an extension of Numpy's ndarray, supports storing gradients in a .gd attribute.
  • Optimization: Gradient Descent Optimizer (GDOptimizer) is implemented with learning rate control.
  • Loss Function: Mean Squared Error (MSE) Loss is implemented to compute the loss during training.
  • Model Class: The CreateModel class stiches all layers together, providing methods for forward passes and training with backpropagation. I plan on making it more customizable.
  • Other basic functionality: General essential functions, like mean, min, max, std, rand, randn etc are implemented in the rawML library. All are powered by NumPy.

Requirements

just numpy :)

pip install numpy

Usage Instructions

Just clone this repository. In the cloned folder, create your python file, and start using away! (the rawML folder is essential. Copy it wherever you wish, and import from it)

Code Example

The demo.py file shows how one can define a rML model, define the loss function, optimzer and stich it together. Model training and inference examples are also shown.

import rawML as rML
from rawML.layers import relu, linear
from rawML.optimizers import GDOptimizer
from rawML.losses import MSELoss
from sklearn.model_selection import train_test_split as tts

LayerList = [
    linear(100,20),
    relu(),
    linear(20,40)
]

opt = GDOptimizer(lr = 1e-2)
loss = MSELoss()
model = rML.createModel(LayerList, opt, loss)

X = rML.rand((16, 100))
Y = rML.rand((16, 40))

##sklearn train-test-split works with jTensors
x_train, x_val, y_train, y_val = tts(X,Y,train_size=0.8)

#Training
model.train((x_train,y_train),(x_val,y_val),epochs=20,verbose_freq=5)

#Predicting
y = model(rML.randn([40,100]))
print(y.shape)
  • As jTensors inherit(and behave very similar to) from numpy arrays, they support operations like .shape, and they can also be fed into scikit-learn's train test split

Future Implementations

This project is at a very initial stage, and I aim to expand it further. I will add implementations of more Optimizers, Loss functions along with other layers like MaxPool2D, CNNs. There is no implementation of the concept of "batch size" which will be added very soon. An easier way to add more custom metrics will also be implemented into the model.train() method. Verbose control will be added Currently, the CreateModel class is restrictive to a sequential NN, which I plan on changing by implementing a more "functional" NN, to make more complex architectures like skip connections etc. The further aim to implement the famed UNet architecture using RawML. and etc...

(PS, there exists an rML.about())

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

rawml-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

rawML-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rawml-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for rawml-0.1.0.tar.gz
Algorithm Hash digest
SHA256 406ab8568081a1be19230f161fdbec66004b1b403e29596c8e4cba3082350e9d
MD5 08d4069a8285dbbb5fe83d8dca24ca30
BLAKE2b-256 1b8eaff7869091bb7baeb1f6b04a8b8ee0e183d1f56ea84d47845763e5afc211

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rawML-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for rawML-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a77759563063760e6440249cc5145f9f0db83469addfab399dedad131d1de1c1
MD5 be89daadf37aeb12d91bf47e135b8b84
BLAKE2b-256 bf61cabe0035246d6fb671460bca69f6e5b7b67e90c75354d48b6c8cfe521e5c

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