GithubHelp home page GithubHelp logo

kgrad's Introduction

A simple Neural network framework written in Kotlin. This is largely a learning exercise for me, but I hope it can be useful to others as well, who would like a more in-depth understanding of how neural networks work.

Most of the code in the project is inspired from Torch, Micro-grad, TinyGrad and many other sources. It also serves as a companion to https://d2l.ai/ (Dive into Deep Learning) which is a great resource for learning about deep learning. Start at the Tensor class and work your way up from there.

In the code there are many references to the book eg: Here is the MLP implementation from the book in Kotlin https://d2l.ai/chapter_builders-guide/model-construction.html

 class MLP : Module() {
            private val weight = Tensor.rand(20, 20)
            private val linear = LazyLinear(20)

            override fun forward(input: Tensor): Tensor {
                var forward = linear.forward(input)
                forward = forward.mmul(weight)
                forward = forward.add(Tensor.ones(2, 20))
                var fw = forward.relu()
                fw = linear.forward(fw)
                while (fw.abs().sum().data.getDouble(0) > 1) {
                    fw = fw.div(Tensor.fillNum(2.0, *fw.data.shape()))
                }
                return fw.sum()
            }
        }

        val model = MLP()
        val tensor = model.forward(Tensor.rand(2, 20))
        println(tensor.data.getDouble(0))

kgrad's People

Contributors

winash 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.