Hands-On Machine Learning with TensorFlow.js
eBook - ePub

Hands-On Machine Learning with TensorFlow.js

A guide to building ML applications integrated with web technology using the TensorFlow.js library

  1. 296 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Hands-On Machine Learning with TensorFlow.js

A guide to building ML applications integrated with web technology using the TensorFlow.js library

About this book

Get hands-on with the browser-based JavaScript library for training and deploying machine learning models effectively

Key Features

  • Build, train and run machine learning models in the browser using TensorFlow.js
  • Create smart web applications from scratch with the help of useful examples
  • Use flexible and intuitive APIs from TensorFlow.js to understand how machine learning algorithms function

Book Description

TensorFlow.js is a framework that enables you to create performant machine learning (ML) applications that run smoothly in a web browser. With this book, you will learn how to use TensorFlow.js to implement various ML models through an example-based approach.

Starting with the basics, you'll understand how ML models can be built on the web. Moving on, you will get to grips with the TensorFlow.js ecosystem to develop applications more efficiently. The book will then guide you through implementing ML techniques and algorithms such as regression, clustering, fast Fourier transform (FFT), and dimensionality reduction. You will later cover the Bellman equation to solve Markov decision process (MDP) problems and understand how it is related to reinforcement learning. Finally, you will explore techniques for deploying ML-based web applications and training models with TensorFlow Core. Throughout this ML book, you'll discover useful tips and tricks that will build on your knowledge.

By the end of this book, you will be equipped with the skills you need to create your own web-based ML applications and fine-tune models to achieve high performance.

What you will learn

  • Use the t-SNE algorithm in TensorFlow.js to reduce dimensions in an input dataset
  • Deploy tfjs-converter to convert Keras models and load them into TensorFlow.js
  • Apply the Bellman equation to solve MDP problems
  • Use the k-means algorithm in TensorFlow.js to visualize prediction results
  • Create tf.js packages with Parcel, Webpack, and Rollup to deploy web apps
  • Implement tf.js backend frameworks to tune and accelerate app performance

Who this book is for

This book is for web developers who want to learn how to integrate machine learning techniques with web-based applications from scratch. This book will also appeal to data scientists, machine learning practitioners, and deep learning enthusiasts who are looking to perform accelerated, browser-based machine learning on Web using TensorFlow.js. Working knowledge of JavaScript programming language is all you need to get started.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weโ€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere โ€” even offline. Perfect for commutes or when youโ€™re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Hands-On Machine Learning with TensorFlow.js by Kai Sasaki in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over one million books available in our catalogue for you to explore.

Information

Section 1: The Rationale of Machine Learning and the Usage of TensorFlow.js

In this section, readers will explore how machine learning applications work on the web platform. They will also learn how to set up an environment to run TensorFlow.js. Furthermore, readers will learn how to import pretrained models from Keras into TensorFlow.js. This section will also cover the ecosystem around TensorFlow.js.
This section contains the following chapters:
  • Chapter 1, Machine Learning for the Web
  • Chapter 2, Importing Pretrained Models into TensorFlow.js
  • Chapter 3, TensorFlow.js Ecosystem

Machine Learning for the Web

In this book, we will learn how to use TensorFlow.js to create machine learning applications. You'll need to be familiar with the following in order to get started:
  • Web-based programming languages, such as JavaScript and TypeScript
  • Web platform technology stacks (only a basic knowledge is required)
  • The fundamentals of machine learning algorithms
In this chapter, we are going to clarify why machine learning on the web is crucial in modern machine learning use cases and when to use web technology so that you can run your applications. You will also be introduced to the basic APIs of TensorFlow.js so that you can construct machine learning models. These topics act as the basis for the chapters that follow.
In this chapter, we will cover the following topics:
  • Why machine learning on the web?
  • Operation graphs
  • What is TensorFlow.js?
  • Installing TensorFlow.js
  • The low-level API
  • The Layers API

Technical requirements

In this chapter, as a prerequisite, you need to prepare the following libraries or frameworks in your environment:
  • A web browser (Chrome is recommended): TensorFlow.js primarily runs on web browsers.
  • The Node.js environment, which contains a node package manager (npm): Node.js is necessary since it resolves dependencies so that we can run TensorFlow.js.
  • TypeScript compiler: TensorFlow.js and its application are often written in TypeScript.
  • Python (3.x is recommended): We need this so that we can run Python-dependent tools such as tfjs-converter and the TensorFlow Python API.
If you are unsure about how to build the environment, please look at the Further reading section, which can be found at the end of this chapter. You will find these resources useful while you set up these prerequisites.
The code we'll be using in this book can be found in this book's GitHub repository: https://github.com/PacktPublishing/Hands-On-Machine-Learning-with-TensorFlow.js.

Why machine learning on the web?

Machine learning technology was invented in the 1950s. Back then, there was no such period where machine learning was the exciting field in computer science that it currently is. However, thanks to breakthroughs in areas of deep learning and artificial intelligence, a huge amount of resources in terms of money and manpower have been devoted to help research it. For example, it isn't unusual to use an extensive amount of computing power that's leveraged by GPUs in laboratories in universities. Nowadays, industries and academics are cooperating to make progress in the computer science field. We are living in an era that's creating and facing large-scale data like never before. The importance of machine learning mainly comes from the demand for providing value by making use of this large-scale data. Machine learning technology gives us a chance to find innovative insights in a scalable and reproducible manner more than ever. For the last decade, intensive research has been done in the machine learning field. Deep learning is one such technology that has achieved accuracy that competes with human intelligence in relation to problems such as image recognition, audio generation, and machine translation. Many machine learning frameworks are emerging and being developed by both academics and industries in order to follow this trend. These technologies can contribute to making such use cases more abundant so that more research can take place.
However, creating a user-friendly application using machine learning is still a challenge. Most machine learning frameworks are designed and optimized to run in an environment that uses distributed systems that are running on thousands of machines and accelerators, such as GPUs. Generally, a machine learning model is used to predict something that's unknown to us after we've trained a model with a known dataset. Environments that contain GPUs and accelerators are exclusively used for the training phase. Although this allows us to train the machine learning model efficiently, it builds a wall between training the model and the inference of the model because it is necessary to make the trained model work on real data. We may need to fine-tune the model with a custom user dataset or convert the model into an executable format in the user's environment. This means that we need to deal with new challenges in terms of integrating between the machine learning model and the user-facing environment when we try to create applications that leverage machine learning technology. Porting machine learning models to platforms that users use often requires intensive work and skill because they're not compatible with the environment. It is common for data scientists who usually use Python as their primary language to struggle with building web applications with JavaScript.
In that sense, the web is the environment that's used the most by the end users of any kind of application. Machine learning applications are not an exception. More and more users are expected to use machine learning applications while they're on the web. Therefore, the web can be seen as the next frontier for machine learning applications because of its potential in terms of how many users use it. The technology that makes machine learning runnable on the web expands the possible use cases for machine learning in the real world. In this book, we are going to learn how to run machine learning on the web by using a modern framework known as TensorFlow.js. TensorFlow.js is a framework that is compatible with TensorFlow APIs so that users can create machine learning applications on the web. Apart from providing the flexibility of web-based machine learning applications, it also provides satisfactory performance since it uses an acceleration mechanism that's provided by modern web browsers.
This book is a practical guide to applying machine learning technologies to the web so that our users can quickly benefit and get value from our applications. It's assumed that you are a developer who wants to create a machine learning application with a rich user interface swiftly and efficiently.

Operation graphs

Before diving into TensorFlow.js itself, we need to be familiar with the idea of operation graphs, or calculation graphs, which are common constructs that we'll use to build machine learning models alongside modern frameworks such as TensorFlow. In these frameworks, the data is represented as a tensor. A tensor is a data structure that represents an arbitrary dimensional array. Those of you who have used the NumPy library in Python may already be familiar with this concept. In NumPy, ndarray is commonly used to display various kinds of data in machine learning, such as images and audio, regardless of whether it's structured or unstructured.
Modern machine learning frameworks, including TensorFlow, illustrates the fact that machine learning models are operation graphs of tensors. An operation graph is defined as a chain that's used for the manipulation or ...

Table of contents

  1. Title Page
  2. Copyright and Credits
  3. About Packt
  4. Contributors
  5. Preface
  6. Section 1: The Rationale of Machine Learning and the Usage of TensorFlow.js
  7. Machine Learning for the Web
  8. Importing Pretrained Models into TensorFlow.js
  9. TensorFlow.js Ecosystem
  10. Section 2: Real-World Applications of TensorFlow.js
  11. Polynomial Regression
  12. Classification with Logistic Regression
  13. Unsupervised Learning
  14. Sequential Data Analysis
  15. Dimensionality Reduction
  16. Solving the Markov Decision Process
  17. Section 3: Productionizing Machine Learning Applications with TensorFlow.js
  18. Deploying Machine Learning Applications
  19. Tuning Applications to Achieve High Performance
  20. Future Work Around TensorFlow.js
  21. Other Books You May Enjoy