A silly use-case of machine learning model. Watch ML ⚡ in action!
Implementation of simple arithmetic operations—multiplication, addition, and subtraction—on an array of natural numbers with a single-neuron deep learning network (basically linear regression!).
main
branch consists of manual implementation of the model with numpy.
pytorch
branch implements the above model using the pytorch library.
Visualise the gradient descent and linear regression happening right in front of you on your browser. Tune the hyperparamters as you watch your model learn live!
Install the anaconda package from here and run these commands on terminal:
conda init
conda create -n arithmetic-ml python=3.8
conda activate arithmetic-ml
git clone https://github.com/yashdeep01/arithmetic-ml-model.git
cd arithmetic-ml-model/
pip install -r requirements.txt
python main.py
Run with custom hyperparameters:
python main.py --operand 2 --lr 0.018 --epochs 20
Get full list of command-line arguments:
python main.py -h
A single neuron deep learning neural network with identity activation function; in other words, linear regression.
Input 1,2,3,...,n
Target c,2c,3c,...nc
, where c is a constant operand
Steps in each epoch:
-
Forward propagation ➡️
Computes the standard equationw*X + b
in forward propagation. Identity activation function. -
Loss computation
⚠️
Calculates Mean Squared Error (MSE) loss at the end of the forward propagation. -
Back propagation ⬅️
Gradient of loss function with respect to weightw
and biasb
obtained:dw
anddb
respectively. -
Gradient descent 📉
Updates weight and bias by stepping against the gradient direction in the magnitude of learning ratelr
.w' = w - lr*dw b' = b - lr*db
Since training dataset is small, batch size is the full training set.
Predicts targets for numbers in validation set using the final weight and bias, then reports validation loss.
Inspired from tutorial: https://github.com/python-engineer/pytorchTutorial