AI in the browser is here

Clint Goodman
4 min readSep 8, 2024

--

Watch my 18 minute presentation of this topic with live demos here: https://youtu.be/6ic1-wtvYz4?si=SqXH9_IfNT7LAuR2.

This is what excites me about having AI run in the browser:

  1. Client-side privacy. Customers are worried that their data is being trained/embedded into AI models, which may later get surfaced through some type of prompt hacking. There are lots of ways to prevent this, including keeping data and AI on the browser, where inference can happen without ever leaving the user’s computer.
  2. Rich interaction. On every keystroke or click, you can run AI in the browser’s background to provide intelligent experiences.
  3. Distributed computation. If the user’s computer has good enough resources, then offloading some of the computation to their browser instead of handling all that load on the servers could be a saver for you.
  4. Accessibility. Javascript is easy to develop in, is the most popular programming language in the world, and when published on the web makes your AI experiences available for everyone.

AI can now be done in the browser, browser extensions, electron apps, and Node.js back-ends. Gone are the days where AI had to be written in Python.

Here are a few demos of different AI technologies that you can use directly on the front-end (and they’re available in Node.js for back-end development as well).

Tensorflow.JS

Official website: tensorflow.org

Notes

It can run in the browser using (in order from slowest to fastest):

  • CPU
  • WASM (web assembly)
  • WebGL (100 times faster)

When running in Node.js, it utilizes C libraries, hardware accelaration, and Cuda where available.

Also, you can convert Python models to JavaScript.

Demos

Web Speech API

Documentation: Using the Web Speech API

Notes

A machine-learning task that may seem so “mainstream” that it doesn’t feel like AI anymore is text to speech (TTS) and speech to text. This is supported now as a web API.

Demo

Transformers.JS

Official website: HuggingFace — Transformers.JS

Notes

Huggingface is THE hub right now for AI. They offer lots of things, including a Python and JavaScript library called “Transformers”, which uses models to accomplish a variety of tasks. The supported tasks at the moment are listed below:

Source: HuggingFace — Transformers.JS

You can use HuggingFace’s available models, or fine-tune a large language model, or convert any Python model to Javascript. Imagine a fine-tuned Llama-3 model running in your browser!

Transformers.JS downloads models to browser cache. Because it’s stored in local cache, it’s available on subsequent refreshes and offline.

Demos

LangChain.JS

Official website: LangChain.JS

Notes

I’m not yet on the LangChain craze that everyone else seems to be, but if you wanted to use it to interface with external large language models, this library is available in both Python and Javascript.

Gemini Nano Web API

Official website: Artificial Intelligence — Chrome for Developers

Notes

Google Chrome Canary, under a flag, downloads Gemini Nano embedded into Chrome itself. It’s only a matter of time before other browsers start shipping embedded large language models as well.

Demos

The Future

This article shows that AI is available in browsers now. Some models and tasks require heavy inference times. You can run these in web workers, or use other async tricks to make the lag seem ok. But, we’re going to want and expect more. That is why this web API proposal is interesting: WebGPU API. Additionally, AI models will continue to improve and quantization will help give us smaller models.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response