Why TensorFlow.js?
Tags: javascript, deeplearning, tensorflow, tfjs
Published: 2021-12-04 18:00:50

In today's world almost everyone has come across the buzz around Artificial Intelligence (AI). We have come a long way in this domain of computer science and the amount of development happening in this field is tremendous. Several unsolved problems have been solved by harnessing the power of AI.
So, is AI _magic_?

Well, it isn't. It's just science, the science of getting computers to act without being explicitly programmed.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gn37mceak88tt9m6go37.png)
 

## **<u>The know how's and the basics.</u>**
Before we get deep into this dazzling world of predictions and learning, we need to have our basics strong. Phrases like AI, _machine learning_, _neural networks_, and _deep learning_ mean related but different things. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cim053xrrfyxw4nho1sj.jpg)

<u>**Artificial Intelligence**</u>
As the Venn diagram above depicts, AI is a broad field. It encompasses machine learning, neural networks, and deep learning, but it also includes many approaches distinct from machine learning. A crisp definition of the field would be: _the effort to automate intellectual tasks normally performed by humans_. 

**<u>Machine Learning</u>**
Machine Learning, as a subfield of AI distinct from symbolic AI arises from a question that _could a computer learn on its own without being explicitly programmed for a specific task?_ 

Machine Learning seeks to avoid the hard-coding way of doing things. But the question is how a machine would learn if it were not explicitly instructed on how to perform a task. A simple answer to this question is _from the examples in data._ 

This opened the doors to a new programming paradigm. 

In the _classical programming paradigm_, we input the data and the rules to get the answers. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ld9f3z5z1zqirvkb4p6.jpg)
Whereas, in the _machine learning paradigm_ we put in the data and the answers and get a set of rules which can be used on other similar data to get the answers. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wfs9lr7r7egda1sbwa90.jpg)

Let's take the example of identifying human faces in an image.

We, as humans can very well classify objects based on their characteristics and features. But how do we train a machine to do so? It is hard for any programmer, no matter how smart and experienced, to write an explicit set of rules in a programming language to accurately decide whether an image contains a human face.
 
The _hypothetical_ search space without any constraint is infinite and it's impossible to search for explicit rules to define a task in a limited amount of time.

Any _heuristic_ we produce is likely to fall short when facing the myriad variations that faces can present in real-life images, such as differences in size, shape, and details of the face; expression; hairstyle; color; the background of the image and many more.
 
There are two important phases in machine learning. 

The first is the _training phase_.
 
This phase takes the data and answers, together referred to as the training data. Each pair of input data (_instances_) and the desired answer (_labels_) is called an example. With the help of the examples, the training process produces the automatically discovered rules. 

Although the rules are discovered automatically, they are not discovered entirely from scratch. In other words, although the machine is intelligent, but not enough to produce the rules.

A human engineer provides a blueprint for the rules at the outset of training. The use of labeled data and human guidance in producing the rules is also known as _Supervised Learning_.
 
It's just like a child learning to walk and requires support in their initial stages.
 
The _blueprint_ is encapsulated in a model, which forms a hypothesis space for the rules the machine may possibly learn. Without this hypothesis space, there is a completely unconstrained and infinite space of rules to search in, which is not conducive to finding good rules in a limited amount of time.

In the second phase of the machine learning paradigm, we use these generated rules to perform inferences on new data. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mbn9mdp0ma7rtnvjaiai.jpg)

**<u>Neural Networks and deep learning</u>**
_Neural networks_ are a subfield of machine learning which is inspired by the neurons present in the human and animal brains. The idea here is to replicate the way a brain learns things as it perceives. We build a net of _interconnected neurons_ each responsible for memorizing certain aspects of a given task to perform. 

The data is passed through multiple separable stages also known as layers. These layers are usually stacked on top of each other, and these types of models are also known as _sequential models_. 

These neural networks apply a mathematical function over the input data to produce an output value. These neural networks are generally _stateful_, i.e. they hold internal memory. 

Each layer's memory is captured in its _weights._

## **<u> Why TensoFlow.js? </u>**
As it's known, JavaScript is scripting language traditionally devoted to creating the web pages and back-end business logic. 
Someone who primarily works with JavaScript may feel left out by the deep-learning revolution which seems to be an exclusive territory of languages such as Python, R, C++.  TensorFlow, is a primary tool for building deep-learning models.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8e62k2xmlz5gsfic9nhf.png)
 
1. TensorFlow.js is the product of _cross-pollination_ between JavaScript and the world of deep learning. 
It is suitable for folks who are good in JavaScript and want to explore the world of deep learning and for folks who have basic mathematical understanding of the deep learning world and are looking for a place to dive deep into this field.
With deep learning, JavaScript developers can make their web apps more intelligent. 
2. TensorFlow.js is created and maintained by _Google_, so it's worth noting that some of the best brains in the world have come together to make it happen.
3. _Provides a no-install experience_ in the world of machine learning. Generally, the AI in a website is locked in an AI and the performance varies with the bandwidth of the connection. TensorFlow.js provides us with the ability to run deep learning models directly in the browsers without any installation of other dependencies. 
4. JavaScript based applications can run anywhere. These codes can be added to progressive web-apps or React application and then these applications can run without being connected to the internet.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9457lav7w5xw9kdx3r8.png)
 
5. It also provides a great deal of privacy as the data never leaves a user's system.

6. It can also be used in IoT based devices such as RaspberryPi.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gifc30p8onoxrkwmkvq.png)
 

Conclusion, mastery of TensorFlow.js can help us in building cross platform intelligent application with great efficacy and security. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1duhzin02079iheui3x.png)
And a huge yes to the picture above XD 
Hope you enjoyed reading the blog!
Thank you :)