Try TensorFlow.js in your browser (Coding TensorFlow)
Key Takeaways
The video demonstrates how to use TensorFlow.js to build and train a simple machine learning model in the browser, using JavaScript and the TensorFlow.js library. The model is trained to predict a linear relationship between input data.
Full Transcript
[Music] [Applause] hi and welcome to coding tensorflow a show where we focus on coding machine learning and AI I'm Laurence Moroney a developer advocate for tensorflow and in this episode we're going to look at using JavaScript for machine learning in the browser this is achieved using tensorflow j/s a javascript library for training and deploying machine learn models in the browser and on no js' there's lots of great information about it on the jsr tensorflow dot org site including samples API Docs and frequently asked questions in this first episode I'll show you how easy it is to build and train a very simple model that executes entirely in the browser and in the next episodes we'll look at setting up a node environment and running more complex examples are you ready to go ok let's do this let's first create the simplest web page imaginable it's empty but for 1 div and we'll even leave that empty too the next thing of course is to add the tensorflow j/s libraries and these can be inserted using a script tag and I do that here always be sure to use the latest version which you can find at this URL be sure to put the script loader in your head tag as shown here great you now have your page set up for tensorflow so let's now show a simple but powerful example of how it can work the goal of machine learning is to train a model from input data this model can be then used to in fare or predict output data for future input values so for example take a look at this data now it's pretty obvious to the human eye that there's a linear relationship in this data these dots can be joined by a straight line thus even though I don't know what the Y value is when X is 5 I can infer that by looking at the line in machine learning we do this by training a model on the input data so let's take a look at the code for this first of all I'm going to create a new script block and within that I'll create an asynchronous function called learn linear it's asynchronous because the learning will take some time so it's good to get into the habit of waiting for the learning to finished now I'm going to add a model I'm using a TF dot sequential where the outputs of one layer are the inputs to the next it's a simple stack of layers with no branching or any kind of skipping I will then add a dense layer to this and dense means all of the nodes in each of the layers are connected to each other in this case it's a little redundant as I only have one layer and one node but it's the easiest way to define a simple neural network like this now that my model is defined it's time to compile it to do this I have to specify some parameters including the loss function and the optimizer I'm setting the loss function to be a mean squared error it's a pretty standard one particularly for linear equations and the optimizer is going to be said to SGD which stands for a stochastic gradient descent this simply defines a methodology for the learning there are a bunch of them supported including SGD and the popular atom you can learn more about these in the training optimizer section of the API and we'll put a link below for the next step I'll define my x and y values for the line remember that graph we showed earlier let's take a look at the points on that you can see that I've labeled them here with their x and y coordinates from a machine learning perspective we can consider the X values to be our inputs and our Y values to be our desired outputs thus in the future if we feed in a new x value would get a Y value back so to train a model to do this we can create two tensors for the training values one for the X's and one for the Y's let's take a look at this in code I'll create a tensor for the X's by using TF tensor 2d you'll see that the first element in this is my array of X values minus 1 0 1 etc the second parameter is the shape of this array 6 rows and 1 column I'll then do the same for my y's giving my Y values and the same shape six rows on one column now all I have to do is Rane my model now this can take some time for complex models but because this is really simple it's going to be really quick either way because it takes an indeterminate time you will await its execution which is why you made this function and a synchronous one to begin with so let's take a look at the code to train a model for a fixed number of iterations known as epochs you call the fit method here you can see I'm telling it my input values the X's my output values the Y's and then asking it to train for 250 iterations once the model is trained I can try to do a prediction from it so if you're good at math you'll see that the relationship here between x and y is y equals 2x minus 1 thus the value for X is 5 well then Y should be 9 you use the model to predict method to get a prediction so let's see that in action I'll refer to the div called output field that I created earlier and I'll load the results of the prediction into its inner text to do this I call model duck predict and I pass my input tensor which is a single value in a one by one array tensorflow will then give me back the value and you'll see that it predicted 38.5 which is pretty close to the correct value of 39 if i refresh the value changes to 38.3 because I've retrained the neural network I can impact the accuracy by training for more epochs giving the network more time to error correct so let's make it say 500 epochs and now when i refresh we'll see my value is 38.9 and another refresh keeps it there so let's see what it would predict for x equals 10 it gives us 18 point 9 7 where of course the correct value is 19 a refresh and retrain the network and now I get 18 point 9 8 we're pretty close and that's it you've just created a neural network using javascript in the browser and trained it to predict a linear relationship this was made possible by tensorflow Jas in the next episode of this series you'll learn a little about data science and this is the process of preparing data for machine learning and you'll do it by building a simple classifier for tensorflow which runs completely in the browser you can learn more about tensorflow das on tensorflow org and don't forget to hit that subscribe button for more great videos on this channel thank you [Music] [Applause] [Music]
Original Description
Machine Learning in the Browser? You betcha! In this video, Laurence Moroney (@lmoroney) shows you just how easy it is to get up and running with creating a machine learning model in JavaScript that executes right in the browser. It's the first part of a three-part series that gets you deeper into both training and executing machine learned models with TensorFlow.js, so be sure to hit that subscribe button for more!
Learn more at TensorFlow.js → http://bit.ly/2HN1wj5
Coding TensorFlow playlist → http://bit.ly/2zoZfvt
Subscribe to the TensorFlow channel → http://bit.ly/TensorFlow1
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from TensorFlow · TensorFlow · 54 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
▶
55
56
57
58
59
60
The TensorFlow YouTube Channel is Here!
TensorFlow
Answering Your TF Questions #AskTensorFlow
TensorFlow
Chatting With the TensorFlow Community (TensorFlow Meets)
TensorFlow
All About TensorFlow Code (Coding TensorFlow)
TensorFlow
TensorFlow: an ML platform for solving impactful and challenging problems
TensorFlow
Keynote (TensorFlow Dev Summit 2018)
TensorFlow
tf.data: Fast, flexible, and easy-to-use input pipelines (TensorFlow Dev Summit 2018)
TensorFlow
Eager Execution (TensorFlow Dev Summit 2018)
TensorFlow
Machine Learning in JavaScript (TensorFlow Dev Summit 2018)
TensorFlow
Training Performance: A user’s guide to converge faster (TensorFlow Dev Summit 2018)
TensorFlow
The Practitioner's Guide with TF High Level APIs (TensorFlow Dev Summit 2018)
TensorFlow
Distributed TensorFlow (TensorFlow Dev Summit 2018)
TensorFlow
Debugging TensorFlow with TensorBoard plugins (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Lite (TensorFlow Dev Summit 2018)
TensorFlow
Searching Over Ideas (TensorFlow Dev Summit 2018)
TensorFlow
Reconstructing Fusion Plasmas (TensorFlow Dev Summit 2018)
TensorFlow
Nucleus: TensorFlow toolkit for Genomics (TensorFlow Dev Summit 2018)
TensorFlow
Open Source Collaboration (TensorFlow Dev Summit 2018)
TensorFlow
Swift for TensorFlow - TFiwS (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Hub (TensorFlow Dev Summit 2018)
TensorFlow
Applied AI at The Coca-Cola Company (TensorFlow Dev Summit 2018)
TensorFlow
Real-World Robot Learning (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Extended (TFX) (TensorFlow Dev Summit 2018)
TensorFlow
Project Magenta (TensorFlow Dev Summit 2018)
TensorFlow
TensorFlow Dev Summit 2018 - Livestream
TensorFlow
Introducing TensorFlow Lite (Coding TensorFlow)
TensorFlow
TensorFlow Dev Summit 2018 Highlights
TensorFlow
Jeff Dean, Head of AI at Google discusses the impact of ML (TensorFlow Meets)
TensorFlow
TensorFlow Mobile vs. TF Lite and More! #AskTensorFlow
TensorFlow
Using TensorFlow to enable research & production across many fields (TensorFlow Meets)
TensorFlow
Teaching TensorFlow for Deep Learning at Stanford University (TensorFlow Meets)
TensorFlow
TensorFlow Lite for Android (Coding TensorFlow)
TensorFlow
Using the tf.data API to build input pipelines (TensorFlow Meets)
TensorFlow
Training Models in the Cloud & the Benefits of AI Toolkits #AskTensorFlow
TensorFlow
Execute operations immediately with TensorFlow's Eager Execution (TensorFlow Meets)
TensorFlow
TensorFlow Lite for iOS (Coding TensorFlow)
TensorFlow
Get started with TensorFlow's High-Level APIs (Google I/O '18)
TensorFlow
TensorFlow for JavaScript (Google I/O '18)
TensorFlow
TensorFlow in production: TF Extended, TF Hub, and TF Serving (Google I/O '18)
TensorFlow
Get started with TensorFlow's High-Level APIs in 5 mins | Google I/O 2018
TensorFlow
TensorFlow and deep reinforcement learning, without a PhD (Google I/O '18)
TensorFlow
TensorFlow Lite for mobile developers (Google I/O '18)
TensorFlow
Advances in machine learning and TensorFlow (Google I/O '18)
TensorFlow
Distributed TensorFlow training (Google I/O '18)
TensorFlow
Classification using neural networks & ML regression models #AskTensorFlow
TensorFlow
TensorFlow and Keras in R - Josh Gordon meets with J.J. Allaire (TensorFlow Meets)
TensorFlow
Focus on your experiment with TensorFlow Estimators (TensorFlow Meets)
TensorFlow
How to get started with AI/ML, retraining models, & more! #AskTensorFlow
TensorFlow
TensorFlow - the deep learning solution for mobile platforms (TensorFlow Meets)
TensorFlow
MiniGo: TensorFlow Meets Andrew Jackson (TensorFlow Meets)
TensorFlow
The growth of TensorFlow with added support for JS & Swift (TensorFlow Meets)
TensorFlow
At the intersection of TensorFlow & nuclear physics (TensorFlow Meets)
TensorFlow
NVidia TensorRT: high-performance deep learning inference accelerator (TensorFlow Meets)
TensorFlow
Try TensorFlow.js in your browser (Coding TensorFlow)
TensorFlow
TensorFlow Hub: reusing machine learning modules (TensorFlow Meets)
TensorFlow
How to use TensorFlow in PyCharm (TensorFlow Tip of the Week)
TensorFlow
Training models faster with TensorFlow Hub (TensorFlow Meets)
TensorFlow
Prepare your dataset for machine learning (Coding TensorFlow)
TensorFlow
Using ML to predict insulin use for Type 1 Diabetes (TensorFlow Meets)
TensorFlow
TFX: an end-to-end machine learning platform for TensorFlow (TensorFlow Meets)
TensorFlow
More on: ML Maths Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Mastering TypeScript — Understanding the TypeScript Compiler (tsc) from Scratch — Lesson 2
Medium · JavaScript
Stop Overfitting With Basically One Line of Code
Medium · AI
Stop Overfitting With Basically One Line of Code
Medium · Machine Learning
Stop Overfitting With Basically One Line of Code
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI