Git Product home page Git Product logo

neuneu's Introduction

Neuneu : a modest Deep Learning framework for Ruby

Ruby Build

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add neuneu

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install neuneu

Usage

Training a (very) basic model

The first step is to create a dataset to handle our training examples. Here, we use the Memory implementation which wraps an array of examples.

Each of the training examples is composed of a vector (i.e. an array) of inputs and a vector of outputs. Here, each example consists in a value of temperature in Celsius degrees as the input, and a value in Fahrenheit degrees as the output:

require "neuneu"

data = [
  [[-40.0], [-40.0]],
  [[-10.0], [14.0]],
  [[0.0], [32.0]],
  [[8.0], [46.4]],
  [[15.0], [59.0]],
  [[22.0], [71.6]],
  [[38.0], [100.4]]
]

We normalize the inputs and outputs so that their values are shifted to the 0-1 range. We also tell Neuneu to shuffle values at each training epoch so that there's no influence of the order of the examples on the training process:

dataset = Neuneu::Dataset::Memory.new(data, transpose: true)
                                 .normalize!
                                 .shuffle!

Now we create a single-layer, single-neuron perceptron model, and train it on all examples during 50 epochs. We use the mean squared error (MSE) loss function and "leaky" rectified linear unit (LeakyReLU) as the transfer function:

model = Neuneu::Model.new.append(:input, 1)
                         .append(:dense, 1, transfer: :leaky_relu)
model.fit(dataset, epochs: 50, loss: :mean_squared_error)

We can show the evolution of the training loss across epochs in the terminal:

model.plot(width: 100)

Now that our model is trained we can make a prediction on novel/unknown input:

model.predict([[100]])
# => 211.7616137915528

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jefmathiot/neuneu.

License

The gem is available as open source under the terms of the MIT License.

neuneu's People

Contributors

jefmathiot avatar

Stargazers

 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.