Giter Club home page Giter Club logo

fakemllibrary's Introduction

The Fake ML library

About

Minimal Deep Learning library with limited feature set, assembled as a final project for the Artificial Intelligence course I've taken in my third year @FMI.

Took inspiration from the book neuralnetworksanddeeplearning, a blog series on neural networks, and my own experience with how pytorch NNs are implemented.

I called it "Fake" as a joke, knowing it can't be taken seriously when compared with libraries used as "industry standards" (like pytorch - which I'm going to reference here).

Features

What actually works ๐Ÿ™‚

  • Linear layer
  • activation functions
    • Sigmoid
    • ReLU (at least the math says so)
    • LeakyReLU
    • Tanh
  • Loss functions
    • MSE
  • optimizer
    • SGD
  • saving / loading models
  • MNIST dataloader

What kinda works?

  • cross entropy loss & softmax (I'm not really sure the math correct)

What I didn't manage to implement ๐Ÿ™

(yeah, it's quite a bit)
  • dropout layer
  • convolution layers
  • pooling layers
  • batch normalization layers
  • Adam optimizer
  • standardized dataloader (though it most likely works on that precise kaggle csv format)
  • preprocessing wrappers
  • multithreading
  • compatibility layer for loading external models

It would be an understatement to say that I underestimated the amount of work needed to, not only write, but also understand what I'm writing. In, the end I stuck with what I managed to understand and pushed to deliver a complete package that can be used for a proper demo.

Challenges? ๐Ÿชต๐Ÿช“

  1. Understanding backpropagation.
  2. Getting back propagation to work. There were a lot of issues with the matrix multiplications โŠน not aligning properly.
  3. Figuring out I'm getting bad results, due to not following standard practices (normalizing input data, normalizing initial weights and biases)
  4. Small issues, which are hard to debug due to the complex nature of such a system
  5. ReLU doesn't seem to perform too well (I hoped it would ๐Ÿ’”)

Performance ๐ŸŽญ vs Pytorch

Single 100 @ Sigmoid (fixed epochs)

Comparing with similar implementations in pytorch I noticed minimal computational overhead and negligible performance differences.

For a model with:

  • layers:
    • (784 x 100) @ Sigmoid
    • (100 x 10)
  • MSE loss
  • 50 epochs training
  • SGD optimizer with 0.1 learning rate
The Fake One The real deal
Time: 6m40s Time: 5m41s
Acc: 93.63% Acc: 97.36%
  • With a kaggle submission for this model I landed on the exact position of my birth year (which is totally intended).

submission


Single 100 @ ReLU

From my understanding a similar network using the ReLU activation should perform better, yet in my case it performed really poorly and caused me all sorts of issues (overflows, nan, etcetera) โš™๏ธ

The Fake One The real deal
Time: 29s Time: 20s
Acc: 84.21% Acc: 96.59%

Triple 100 @ Tanh (target performance)

I ran the following in order to assess how much time it would take for similar networks to achieve similar performance. The results speak for themselves.

We can observe a minimal computational overhead and a negligible performance difference between my Fake ML Library and pytorch.

For a model with:

  • layers:
    • (784 x 100) @ Tanh
    • (100 x 100) @ Tanh
    • (100 x 100) @ Tanh
    • (100 x 10) @ Tanh
  • SGD optimizer
The Fake One The real deal
MSE loss Cross Entropy Loss
0.001 learning rate 0.1 learning rate
Time: 9m40s Time: 30s
Acc: 94.07% Acc: 95.21%
50 epochs 5 epochs

Epoch 055 -> loss: 0.1524; acc: 0.9371 | val_loss: 0.1528; val_acc: 0.9407 | elasped time: 9m40s

vs

Epoch [5/5], Step [921/938], Loss: 0.8425 | Accuracy on the 10000 test images: 95.21 %

Resources | Inspiration | What I've read on the way ๐Ÿ“š

ashwins blog
covnetjs
3b1b nn playlist
nnadl
understandin back propagation
cross entropy & softmax
pytorch code for comparison

There might have been other resources I've missed. ๐Ÿฅฒ

Special acknowledgements ๐Ÿ™

Although the performance of the ReLu activation function in my tests was as bad as it gets, the real Relu compensated for it and helped me push through with this project.

relu relu

thanks Relu. i am forever grateful

fakemllibrary's People

Contributors

stefan-radu avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.