THE WORLD'S LARGEST WEB DEVELOPER SITE

Artificial Intelligence

AI in the Browser

Artificial Intelligence in the browser means:

  • AI with JavaScript
  • Machine Learning (ML) with JavaScript
  • Deep Learning (DL) with JavaScript
  • AI for Everyone on the Web

Neural Networks (NN)

Traditional algorithms cannot solve mathematical problems like medical diagnosis, face detection, and voice recognition.

Only Neural Networks can solve these problems.

Neural Networks is the essence of Deep Learning.


Neural Networks with JavaScript

Building a Neural Network with brain.js.

Brain.js is a JavaScript library that makes it easy to understand Neural Networks because it hides the complexity of the mathematics.

The example below, demonstrates how to program a Neural Network:

Example:

// Create a Neural Network
const network = new brain.NeuralNetwork();

// Train the Network with 4 input objects
network.train([
 {input:[0,0], output:{zero:1}},
 {input:[0,1], output:{one:1}},
 {input:[1,0], output:{one:1},
 {input:[1,1], output:{zero:1},
]);

// What is the expected output of [1,0]?
result = network.run([1,0]);

// Display the probability for "zero" and "one"
... result["one"] + " " + result["zero"];
Try it Yourself »

Example Explained:

A Neural Network is created with: new brain.NeuralNetwork()

The network is trained with network.train([examples])

The examples represent 4 input values a corresponding output value.

With network.run([1,0]), you ask "What is the likely output of [0,1]?"

The answer from the network is:

  • one: 93% (close to 1)
  • zero: 6% (close to 0)

How to Predict a Contrast

With CSS, colors can be set by RGB:

Example

Color RGB
BlackRGB(0,0,0)
YellowRGB(255,255,0)
RedRGB(255,0,0)
WhiteRGB(255,255,255)
Light GrayRGB(192,192,192)
Dark GrayRGB(65,65,65)
Try it Yourself »

The example below demonstrates how to predict the darkness of a color:

Example:

// Create a Neural Network
const net = new brain.NeuralNetwork();

// Train the Network with 4 input objects
net.train([
// White RGB(255, 255, 255)
{input:[255/255, 255/255, 255/255], output:{light:1}},
// Light grey (192,192,192)
{input:[192/255, 192/255, 192/255], output:{light:1}},
// Darkgrey (64, 64, 64)
{ input:[65/255, 65/255, 65/255], output:{dark:1}},
// Black (0, 0, 0)
{ input:[0, 0, 0], output:{dark:1}},
]);

// What is the expected output of Dark Blue (0, 0, 128)?
let result = net.run([0, 0, 128/255]);

// Display the probability of "dark" and "light"
... result["dark"] + " " + result["light"];
Try it Yourself »

Example Explained:

A Neural Network is created with: new brain.NeuralNetwork()

The network is trained with network.train([examples])

The examples represent 4 input values a corresponding output value.

With network.run([0,0,128/255]), you ask "What is the likely output of dark blue?"

The answer from the network is:

  • Dark: 95%
  • Light: 4%

Why not edit the example to test the likely output of yellow or red?


Introduction to ml5.js

ml5.js is trying to make machine learning more accessible to a wider audience.

The ml5 team is working to wrap machine learning functionality in friendlier ways.

The example below uses only three lines of code to classify an image:

<img id="image" src="pic1.jpg" width="100%">

<script>
const classifier = ml5.imageClassifier('MobileNet');
classifier.classify(document.getElementById("image"), gotResult);
function gotResult(error, results) { ... }
</script>
Try it Yourself »

Try substitute "pic1.jpg" with "pic2.jpg" and "pic3.jpg".


TensorFlow Playground

TensorFlow Playground is a web application written in d3.js.

With TensorFlow Playground you can learn about Neural Networks (NN) without math.

In your own Web Browser you can create a Neural Network and see the result.


Tom Mitchell

Tom Michael Mitchell (born 1951) is an American computer scientist and University Professor at the Carnegie Mellon University (CMU).

He is a former Chair of the Machine Learning Department at CMU.

"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E."

Tom Mitchell (1999)

E: Experience (the number of times).
T: The Task (driving a car).
P: The Performance (good or bad).