Streams

The Possibilities Around Streaming Data And TensorFlow.js In The Browser

We are exploring the possibilities with streaming data and TensorFlow, a WebGL accelerated, browser based JavaScript library for training and deploying ML models. The new project opens up a whole new world of machine learning, client-side in the browser, and we wanted to begin thinking more about how Server-Sent Events (SSE) can be used to feed rich data and content into machine learning models operating within the browser. The project is just getting started, so the working examples of what it does are just getting started also, but we would like to begin with profiling what TensorFlow.js does.

TensorFlow.js moves machine learning into the browser, allowing us to:

Develop ML in the Browser – Use flexible and intuitive APIs to build and train models from scratch using the low-level JavaScript linear algebra library or the high-level layers API
Run Existing Models – Use TensorFlow.js model converters to run pre-existing TensorFlow models right in the browser.
Retrain Existing Models – Retrain pre-existing ML models using sensor data connected to the browser, or other client-side data.

TensorFlow.js delivers an open source solution that provide the logic and scripts that combine two packages:

TensorFlow.js Core – a flexible low-level API, formerly known as deeplearn.js.
TensorFlow.js Layers – a high-level API which implements functionality similar to Keras.

Most of the working examples right now of TensorFlow.js are multimedia based, working with images, and delivering games, however the default example below shows how to take some sample data, then run the model using the data, then use the model to do inference on a data point the model hasn’t seen before.


<html>
<head>
<!-- Load TensorFlow.js -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@0.9.0"> </script>
<script>

// Define a model for linear regression.
const model = tf.sequential();
model.add(tf.layers.dense({units: 1, inputShape: [1]}));

// Prepare the model for training: Specify the loss and the optimizer.
model.compile({loss: 'meanSquaredError', optimizer: 'sgd'});

// Generate some synthetic data for training.
const xs = tf.tensor2d([1, 2, 3, 4], [4, 1]);
const ys = tf.tensor2d([1, 3, 5, 7], [4, 1]);

// Train the model using the data.
model.fit(xs, ys).then(() => {
// Use the model to do inference on a data point the model hasn't seen before:
// Open the browser devtools to see the output
model.predict(tf.tensor2d([5], [1, 1])).print();
});
</script>
</head>

<body>
</body>
</html>

Providing a prety interesting base for using real-time streams of data from existing APIs to train machine learning models in the browser, then conducting some predictions involving the data. We are going to explore the other machine learning models available by default, and begin applying it to some market, sports, blockchain, and other relevant data to see what kind of results we can get. There are a number of interesting APIs available for TensorFlow.js, as well as the possibilities opened up by being able to apply existing TensorFlow models, making it a pretty interesting world to play with looking for patterns, and making predictions using streaming data.

As the world of machine learning continues to evolve, and the event-driven architecture landscape continues to mature, we feel like there is a pretty compelling convergence of real-time data and machine learning. Allowing this convergence to happen in the browser, within the web applications and dashboards where the data is being delivered to users via streams, provides a perfect marriage of the powerful machine elements of this evolution with the human benefits, and participation that is required to ensure machine learning has the impact we all desire. We are pretty excited about the potential at the intersection of streaming data and machine learning in the browser, and will keep publishing stories as we learn more about this new frontier in artificial intelligence.

The Possibilities Around Streaming Data And TensorFlow.js In The Browser

**Original source: streamdata.io blog