Now Hiring: Are you a driven and motivated 1st Line Big Data Engineer?

Logicreators IT Blog

Technologies

Using JavaScript for Machine Learning(ML): The Pros and Cons

Developers are being come to think that they are limited to use a select few programming languages to construct and train an ML model. Frequently, Python and Javascript top the list.

Python because of its simple structure: To shorten development time, the language has an array of out-the-box libraries. For example, PyBrain is a modular ML library that helps developers create algorithms, then test and compare solutions in pre-defined environments.

Java because of its longer maturities: Java has been around for decades, so when building and using algorithms it’s the de facto language of choice for bigger organizations like banks and financial institutions.

Whereas JavaScript is a language? Well, this was useful to many developers for nothing but the frontend.

Also in the context of machine learning, most thought JavaScript had data visualization applications only: take the D3.js library, for example — used exclusively for HTML, SVG, and CSS data visualization.

But times change — just as the ML engineering dynamics are. And the writing of machine learning functions using common web-scripting languages is becoming standard practice for developers.

These days, an algorithm can be designed and trained using whatever general-purpose programming language you like.

… And JavaScript contains that.

TensorFlow.js: The Machine Learning Javascript library in your browser

TensorFlow.js is a JavaScript library built inside the browser by Google as an open-source platform for training and the use of machine learning models. The system, in short, lets developers in JavaScript create and deploy ML models within client-side applications.

Developers swarmed to use TensorFlow.js because they could use it for both:

  • Build new machine learning models from scratch
  • Like running — or retraining — current pre-trained models

The language is also a sidekick to its namesake TensorFlow (the ML library used with Python), which means that any machine learning model built utilizing TensorFlow can be converted using TensorFlow.js to run in the browser.

Yet the question remains: Why do we need a learning library for Javascript machines?

Pros and cons of machine learning using JavaScript

The fact that TensorFlow.js is running inside the browser opens up several exciting possibilities for both businesses and developers alike.

As browsers, they are an interactive space: one that provides access to different sensors — including microphones and webcams— that can provide visuals and sounds as an input into any model of machine learning.

TensorFlow.js Pros

Popularity

First optimistic signal: TensorFlow.js is loved by developers who use it. And adulation usually leads to the utility so it’s fair to assume that the library provides a valuable contribution to the machine learning environment.

Also, there’s a low entry threshold given its a companion to the popular Python library — making it easier for developers to start using it.

Performance

The language itself performs strongly in computation. It is accelerated by hardware since it uses WebGL (a JavaScript graphics API). Therefore, if an end-user has a GPU in his setup, developers can exploit it to further boost performance

Security

Web scripting languages will theoretically open vulnerabilities. TensorFlow.js has, however, built a reputation for the safety of its execution environment, ensuring that devices remain protected from threats when running an application.

Range

In many instances, TensorFlow.js has already proven its utility on multiple platforms: in JavaScript, applications running in the browser; on servers running in a Node.js environment; on the desktop; and in mobile browsers running on Android platforms and iOS.

TensorFlow.js Cons

Limitations on data

Notwithstanding all the good features, in the client host environment, TensorFlow.js has no default access to the file system. This limits the data resources available and can restrict the file sizes.

Accelerated Hardware

Also, the framework has limited hardware acceleration support. That said, this situation is rapidly improving as the open-source language evolves beyond v1.0.

One-threaded

Single threads are synchronously downloaded in the JavaScript library which could throttle performance. Developers can solve this by giving away, say, the main thread to enhance a page’s responsiveness during training.

And in Node.js settings, developers can ensure timely handling of tasks that are in the queue in the event loop.

For Machine Learning and JavaScript what is possible?

A lot of developers have recently switched from managing ML on back-end servers to front-end applications.

And due to TensorFlow.js, teams can now build and run ML models in static HTML documents without ever setting up a server or even a database — hosted entirely on the client-side, allowing the following services.

  • Automatic Picture Manipulation: Auto-adjust pictures using a browser-based program based on a predefined set of rules — also create art using coevolutionary neural networks, as Google has done.
  • Offline Game Opponents: Play against an Automation-operated opponent, even if a computer game is offline-as you can do against built-in Trex opponent of Chrome.
  • Content Recommendation Engine: develop and train a browser-based ML algorithm, classify what users want to see, and surface more relevant content — just as Twitter has done to rank tweets.
  • Activity Monitoring: Download a client-side program that learns the patterns of usage on a local network or device — to track and report suspicious activities.
  • Object Detection: Using a client-side program to identify documents or objects in images — such as using Airbnb to send alerts to the existence of sensitive information when they upload a passport or photo of a driving license.

How to highlight your creativity using Tensorflow.js

Even so, a growing number of companies are going to experiment with machine learning applications running on the device of end-users. And as devices become more potent, the opportunity to experiment will only increase.

At DLabs, we used web-browser-based applications (with permission, of course) to perform early-stage data analysis from the computer of the client, gleaning valuable insights informing on future development decisions.

We have used the new APIs — including Node’s File System API — to access locally stored files on the computer of the user, as well as run multiple threads to help clients solve performance problems.

We’re thrilled by what we’ve all been able to achieve, let alone fascinated on what’s to come — safe to say, that’s a technology we’re going to pursue far into the future.

If you’re out there wondering whether Javascript is fad or fashion for machine learning, experience and success suggest its a trend that’s just set to expand.