Code Monkey home page Code Monkey logo

neural-networks-and-optimizers-from-scratch's Introduction

Neural Networks and optimizers from scratch

Motivation

The aim of this project is to consolidate my understanding about neural networks, and to refine my internal representation of neural networks as a computation graph.

I wanted to gain intuition about how and why different optimizers converge / behave. Therefore, I implemented a number of optimizers from scratch based on the papers they were published in.

Project

In this ipython notebook, I wrote a neural network with an object-oriented approach and tested it on the MNIST dataset. The optimisers are contained in this script.

For the tests, the network architecture used was 2 linear layers with relu activation followed by an output layer to a softmax function. The Layer and Model objects created can handle an arbitrary number of layers with different units.

Optimizers

The optimizers I have implemented in this notebook includes (so far):

  1. Minibatch Gradient Descent (Vanilla)
  2. SGD with Momentum
  3. Nesterov Momentum (or Nesterov Accelerated Gradient)
  4. Adagrad
  5. RMSprop
  6. Adam
  7. Nadam
  8. Adadelta
  9. Adamax
  10. QHAdam

Decaying Momentum (Demon) can be applied to any optimizer that inherits from the Adam subclass and the SGDM subclass, and Decoupled Weight decay can be applied to any optimizer that inheritis from the Adam subclass. This can result in optimizers such as DemonQHAdamW or DemonNesterov.

The graph below shows training loss over epochs for a few select optimizers: img

This one shows validation accuracy over epochs: img

QHAdamW performed the best in training loss, while Nesterov performed the best in validation accuracy in this task.

It is noted that SGD with momentum / Nesterov momentum may be 'simpler' gradient descent algorithms, but they perform quite well over in convergence over epochs.

With knowledge from my previous tests, these momentum optimizers are quite sensitive to the learning rate, as opposed to an algorithm from the "Adam's family".

To-do

  • Perhaps convert optimizers to separate objects for easier handling of arguments / optional parameters
  • Convolutional layer and pooling from scratch, to test with CIFAR10 dataset

neural-networks-and-optimizers-from-scratch's People

Contributors

timvvvht avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 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.