Skip to content

Latest commit

 

History

History
133 lines (92 loc) · 7.39 KB

introduction.md

File metadata and controls

133 lines (92 loc) · 7.39 KB

Quick Introduction




Training, algorithms, and models

In traditional programming, a programmer writes a set of instructions, that is executed by the computer.

In Machine Learning, we let the computer find the optimal decision by itself. We provide training data to an algorithm and we receive a trained model. The model can make decisions for us!

In this example, we train a model to recognise cats based on an existing set of cat drawings:

model1

When we have a model, we can check if any new drawing is a cat or not! We can even ask it to generate a new cat drawing for us!

model2





Machine Learning problems

pose

Depending on your data and your goal, you can use different approaches for your Javascript ML project.

Problem Approach Javascript example
Find patterns in a simple excel sheet Use K-Nearest-Neighbour to find patterns in arrays of numbers kNear, KNNClassifier
Find patterns in a complex excel sheet Use a basic Neural Network to find patterns in arrays of numbers brainJS, ML5 Neural Network, Tensorflow Basics
Understand meaning of text Use LSTM Neural Network or Word2Vec to find meaning in sentences BrainJS LSTM, Word2Vec
Understand sentiment in text Use existing sentiment model ML5 sentiment, TensorFlow sentiment, Detect Comment Toxicity
Recognise body poses Use an existing pre-trained body pose model Train a Pose Model with Teachable Machine ML5 PoseNet
Recognise objects in images Use an existing pre-trained image model, or train your own model using a Convolutional Neural Network Train a model with Teachable Machine, ML5 YOLO, Tensorflow Object Detection
Recognise hand written text Use the MNIST model Tensorflow MNIST
Recognise facial expressions Use an existing facial expression model Face-API
Generate text or images Use a Recurrent Neural Network ML5 Sketch RNN, BrainJS RNN



brain

Coding with Javascript

Javascript allows us to publish our projects online, and provides easy ways to visualise our results using html and css.

Brain.JS

BrainJS is a library that allows you to instantiate a Neural Network, train it and run a classification in just a few lines of code. This example learns if text on a RGB background should be white or black:

const net = new brain.NeuralNetwork()

net.train([
  { input: { r: 0.03, g: 0.7, b: 0.5 }, output: { black: 1 } },
  { input: { r: 0.16, g: 0.09, b: 0.2 }, output: { white: 1 } },
  { input: { r: 0.5, g: 0.5, b: 1.0 }, output: { white: 1 } },
])

const output = net.run({ r: 1, g: 0.4, b: 0 }) // { white: 0.99, black: 0.002 }

ML5.JS

ML5 supplies a simplified wrapper with clear documentation and examples for many existing Machine Learning libraries, such as TensorFlow and YOLO. In this example, we teach the machine what is left and what is right:

let nn = ml5.neuralNetwork({
  inputs: 1,
  outputs: 2,
  task: 'classification',
  debug: true
})

nn.addData( 100,  ['left'])
nn.addData( 600,  ['right'])
nn.addData( 150,  ['left'])
nn.addData( 800,  ['right'])

nn.normalizeData()
nn.train(finishedTraining)

function finishedTraining(){
  nn.classify([160], (err, result) => console.log(result)) // LEFT
}

Tensorflow JS

TensorFlow is Google's Neural Network library. TensorFlow is available for Javascript, Python and IoT devices. In TensorFlow you can build your own custom Neural Network to serve many different purposes.