Close Menu
techwavedispatch.com

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Cost attribution and controls for AI developer and productivity tools on Amazon Bedrock

    November 13, 2026

    Export-banned Nvidia chips are behind China’s most powerful AI models—uh oh, Jensen!

    November 13, 2026

    Deploy LLMs with Hugging Face Inference Endpoints

    November 13, 2026
    Facebook X (Twitter) Instagram
    Trending
    • Cost attribution and controls for AI developer and productivity tools on Amazon Bedrock
    • Export-banned Nvidia chips are behind China’s most powerful AI models—uh oh, Jensen!
    • Deploy LLMs with Hugging Face Inference Endpoints
    • Adaptive Variance Reduction for Robust Federated Learning under Limited Client Participation
    • Making ML-powered web games with Transformers.js
    • EASTAR: Event-Anchored Semantic and Task-Adaptive Region Representation Learning
    • Build a Robot Pick-and-Place Simulation with SimReady Assets
    • [2509.21172] Inverse Reinforcement Learning with Just Classification and a Few Regressions
    Facebook X (Twitter) Instagram
    techwavedispatch.com
    Subscribe
    Friday, November 13
    • Home
    • AI Tools & Software
    • Machine Learning
    • Generative AI
    • Robotics & Automation
    • Future Tech & Hardware
    • AI in Business
    • Ethics & Regulations
    • More
      • Gadgets & Smart Devices
      • Cybersecurity & AI
      • Tech Breakthroughs
    techwavedispatch.com
    Home»AI Tools & Software»Making ML-powered web games with Transformers.js
    AI Tools & Software

    Making ML-powered web games with Transformers.js

    adminBy adminNovember 13, 2026No Comments7 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Making ML-powered web games with Transformers.js
    Share
    Facebook Twitter LinkedIn Pinterest Email

    In this blog post, I’ll show you how I made Doodle Dash, a real-time ML-powered web game that runs completely in your browser (thanks to Transformers.js). The goal of this tutorial is to show you how easy it is to make your own ML-powered web game… just in time for the upcoming Open Source AI Game Jam (7-9 July 2023). Join the game jam if you haven’t already!

    Video: Doodle Dash demo video



    Quick links



    Overview

    Before we start, let’s talk about what we’ll be creating. The game is inspired by Google’s Quick, Draw! game, where you’re given a word and a neural network has 20 seconds to guess what you’re drawing (repeated 6 times). In fact, we’ll be using their training data to train our own sketch detection model! Don’t you just love open source? 😍

    In our version, you’ll have one minute to draw as many items as you can, one prompt at a time. If the model predicts the correct label, the canvas will be cleared and you’ll be given a new word. Keep doing this until the timer runs out! Since the game runs locally in your browser, we don’t have to worry about server latency at all. The model is able to make real-time predictions as you draw, to the tune of over 60 predictions a second… 🤯 WOW!

    This tutorial is split into 3 sections:

    1. Training the neural network
    2. Running in the browser with Transformers.js
    3. Game Design



    1. Training the neural network



    Training data

    We’ll be training our model using a subset of Google’s Quick, Draw! dataset, which contains over 5 million drawings across 345 categories. Here are some samples from the dataset:

    Quick, Draw! dataset



    Model architecture

    We’ll be finetuning apple/mobilevit-small, a lightweight and mobile-friendly Vision Transformer that has been pre-trained on ImageNet-1k. It has only 5.6M parameters (~20 MB file size), a perfect candidate for running in-browser! For more information, check out the MobileViT paper and the model architecture below.

    MobileViT archtecture



    Finetuning


    Open In Colab

    To keep the blog post (relatively) short, we’ve prepared a Colab notebook which will show you the exact steps we took to finetune apple/mobilevit-small on our dataset. At a high level, this involves:

    1. Loading the “Quick, Draw!” dataset.

    2. Transforming the dataset using a MobileViTImageProcessor.

    3. Defining our collate function and evaluation metric.

    4. Loading the pre-trained MobileVIT model using MobileViTForImageClassification.from_pretrained.

    5. Training the model using the Trainer and TrainingArguments helper classes.

    6. Evaluating the model using 🤗 Evaluate.

    NOTE: You can find our finetuned model here on the Hugging Face Hub.



    2. Running in the browser with Transformers.js



    What is Transformers.js?

    Transformers.js is a JavaScript library that allows you to run 🤗 Transformers directly in your browser (no need for a server)! It’s designed to be functionally equivalent to the Python library, meaning you can run the same pre-trained models using a very similar API.

    Behind the scenes, Transformers.js uses ONNX Runtime, so we need to convert our finetuned PyTorch model to ONNX.



    Converting our model to ONNX

    Fortunately, the 🤗 Optimum library makes it super simple to convert your finetuned model to ONNX! The easiest (and recommended way) is to:

    1. Clone the Transformers.js repository and install the necessary dependencies:

      git clone https://github.com/xenova/transformers.js.git
      cd transformers.js
      pip install -r scripts/requirements.txt
      
    2. Run the conversion script (it uses Optimum under the hood):

      python -m scripts.convert --model_id 
      

      where is the name of the model you want to convert (e.g. Xenova/quickdraw-mobilevit-small).



    Setting up our project

    Let’s start by scaffolding a simple React app using Vite:

    npm create vite@latest doodle-dash -- --template react
    

    Next, enter the project directory and install the necessary dependencies:

    cd doodle-dash
    npm install
    npm install @xenova/transformers
    

    You can then start the development server by running:

    npm run dev
    



    Running the model in the browser

    Running machine learning models is computationally intensive, so it’s important to perform inference in a separate thread. This way we won’t block the main thread, which is used for rendering the UI and reacting to your drawing gestures 😉. The Web Workers API makes this super simple!

    Create a new file (e.g., worker.js) in the src directory and add the following code:

    import { pipeline, RawImage } from "@xenova/transformers";
    
    const classifier = await pipeline("image-classification", 'Xenova/quickdraw-mobilevit-small', { quantized: false });
    
    const image = await RawImage.read('https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/ml-web-games/skateboard.png');
    
    const output = await classifier(image.grayscale());
    console.log(output);
    

    We can now use this worker in our App.jsx file by adding the following code to the App component:

    import { useState, useEffect, useRef } from 'react'
    
    
    function App() {
        
        const worker = useRef(null);
    
        
        useEffect(() => {
            if (!worker.current) {
                
                worker.current = new Worker(new URL('./worker.js', import.meta.url), {
                    type: 'module'
                });
            }
    
            
            const onMessageReceived = (e) => {  };
    
            
            worker.current.addEventListener('message', onMessageReceived);
    
            
            return () => worker.current.removeEventListener('message', onMessageReceived);
        });
    
        
    }
    

    You can test that everything is working by running the development server (with npm run dev), visiting the local website (usually http://localhost:5173/), and opening the browser console. You should see the output of the model being logged to the console.

    [{ label: "skateboard", score: 0.9980043172836304 }]
    

    Woohoo! 🥳 Although the above code is just a small part of the final product, it shows how simple the machine-learning side of it is! The rest is just making it look nice and adding some game logic.



    3. Game Design

    In this section, I’ll briefly discuss the game design process. As a reminder, you can find the full source code for the project on GitHub, so I won’t be going into detail about the code itself.



    Taking advantage of real-time performance

    One of the main advantages of performing in-browser inference is that we can make predictions in real time (over 60 times a second). In the original Quick, Draw! game, the model only makes a new prediction every couple of seconds. We could do the same in our game, but then we wouldn’t be taking advantage of its real-time performance! So, I decided to redesign the main game loop:

    • Instead of six 20-second rounds (where each round corresponds to a new word), our version tasks the player with correctly drawing as many doodles as they can in 60 seconds (one prompt at a time).
    • If you come across a word you are unable to draw, you can skip it (but this will cost you 3 seconds of your remaining time).
    • In the original game, since the model would make a guess every few seconds, it could slowly cross labels off the list until it eventually guessed correctly. In our version, we instead decrease the model’s scores for the first n incorrect labels, with n increasing over time as the user continues drawing.



    Quality of life improvements

    The original dataset contains 345 different classes, and since our model is relatively small (~20MB), it sometimes is unable to correctly guess some of the classes. To solve this problem, we removed some words which are either:

    • Too similar to other labels (e.g., “barn” vs. “house”)
    • Too difficult to understand (e.g., “animal migration”)
    • Too difficult to draw in sufficient detail (e.g., “brain”)
    • Ambiguous (e.g., “bat”)

    After filtering, we were still left with over 300 different classes!



    BONUS: Coming up with the name

    In the spirit of open-source development, I decided to ask Hugging Chat for some game name ideas… and needless to say, it did not disappoint!

    Game name suggestions by Hugging Chat

    I liked the alliteration of “Doodle Dash” (suggestion #4), so I decided to go with that. Thanks Hugging Chat! 🤗


    I hope you enjoyed building this game with me! If you have any questions or suggestions, you can find me on Twitter, GitHub, or the 🤗 Hub. Also, if you want to improve the game (game modes? power-ups? animations? sound effects?), feel free to fork the project and submit a pull request! I’d love to see what you come up with!

    PS: Don’t forget to join the Open Source AI Game Jam! Hopefully this blog post inspires you to build your own web game with Transformers.js! 😉 See you at the Game Jam! 🚀

    Games Making MLpowered Transformers.js web
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    admin
    • Website

    Related Posts

    Deploy LLMs with Hugging Face Inference Endpoints

    November 13, 2026

    Build a Robot Pick-and-Place Simulation with SimReady Assets

    November 13, 2026

    Banks bar Chinese and Hong Kong investors from Anthropic IPO over US export controls

    November 13, 2026
    Leave A Reply Cancel Reply

    Top Posts

    NVIDIA Is Investigating Reports That CEO Jensen Huang Was The Target Of Chinese Spy Efforts

    November 8, 202619 Views

    ADIndex: Layer-Adaptive Sparse Attention Indexing via Group-Level Distillation

    November 11, 20265 Views

    Anthropic releases new Mythos and Fable models amid RSI concerns

    November 9, 20265 Views

    Anthropic says AI is eroding Nvidia’s CUDA lead, cutting an AMD chip switch from months to three days

    November 11, 20264 Views
    Don't Miss
    Machine Learning

    Cost attribution and controls for AI developer and productivity tools on Amazon Bedrock

    By adminNovember 13, 20260

    Amazon Bedrock provides built-in, zero-instrumentation cost attribution that traces every inference call back to the…

    Export-banned Nvidia chips are behind China’s most powerful AI models—uh oh, Jensen!

    November 13, 2026

    Deploy LLMs with Hugging Face Inference Endpoints

    November 13, 2026

    Adaptive Variance Reduction for Robust Federated Learning under Limited Client Participation

    November 13, 2026
    About Us

    Welcome to TechWave Dispatch

    At TechWave Dispatch, we bring you the latest news, insights, and developments from the ever-evolving world of technology. Our mission is to keep readers informed about the innovations shaping our digital future.

    From artificial intelligence and machine learning to cybersecurity, robotics, smart devices, and groundbreaking technologies, we cover the topics that matter in today's fast-moving tech landscape.

    Our Picks

    Cost attribution and controls for AI developer and productivity tools on Amazon Bedrock

    November 13, 2026

    Export-banned Nvidia chips are behind China’s most powerful AI models—uh oh, Jensen!

    November 13, 2026

    Deploy LLMs with Hugging Face Inference Endpoints

    November 13, 2026
    Most Popular

    Who Controls Scientific Discovery? – O’Reilly

    November 6, 20260 Views

    After blocking Muse, Amazon now lets users text Alexa to help them shop

    November 6, 20260 Views

    A controlled world for robot learning and evaluation

    November 6, 20260 Views
    Facebook X (Twitter) Instagram Pinterest
    • Terms and Conditions
    • Privacy Policy
    • Contact Us
    • About Us
    © 2026 TechWave Dispatch. All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.