Giter Site home page Giter Site logo

anselmwang / browser-ml-inference Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jobergum/browser-ml-inference

0.0 1.0 0.0 75.78 MB

Edge Inference in Browser with Transformer NLP model

Home Page: https://aiserv.cloud/

License: Apache License 2.0

HTML 0.32% CSS 0.40% JavaScript 3.49% TypeScript 3.53% Jupyter Notebook 92.26%

browser-ml-inference's Introduction

Text Emotion Prediction in Browser

This React App demonstrates ML Inference in the Browser using

  • Cloudflare Pages to deliver the React app and model via worldwide Content Delivery Network (CDN)
  • ONNX Runtime Web for model inference in the Browser
  • Huggingface for NLP model hosting and training API (Transformer library)
  • Google Colab for model training using GPU instances

Live demo at https://aiserv.cloud/

See also my blog post Moving ML Inference from the Cloud to the Edge.

The emotion prediction model is a fine-tuned version of the pre-trained language model microsoft/xtremedistil-l6-h384-uncased. The model has been fine-tuned on the GoEmotions dataset which is a multi-label text categorization problem.

GoEmotions, a human-annotated dataset of 58k Reddit comments extracted from popular English-language subreddits and labeled with 27 emotion categories . As the largest fully annotated English language fine-grained emotion dataset to date. In contrast to the basic six emotions, which include only one positive emotion (joy), the taxonomy includes 12 positive, 11 negative, 4 ambiguous emotion categories and 1 “neutral”, making it widely suitable for conversation understanding tasks that require a subtle differentiation between emotion expressions.

Paper GoEmotions: A Dataset of Fine-Grained Emotions

See TrainGoEmotions.ipynb for how to train a model on the dataset and export the fine-tuned model to ONNX. Open In Colab

ONNX-Runtime-web

The model is quantized to int8 weights and has 22M trainable parameters and is 22MB large. Inference is multi-threaded. To use multiple inference threads, specific http headers must be presented by the CDN, see Making your website "cross-origin isolated" using COOP and COEP. Three threads are used for inference.

For development, the src/setupProxy.js adds the required headers. See react issue 10210

Code Navigation

Model and Language Biases

The pre-trained language model was trained on text with biases, see On the Dangers of Stochastic Parrots: Can Language Models Be Too Big? for a study on the dangers of pre-trained language models and transfer learning.

From dataset paper GoEmotions: A Dataset of Fine-Grained Emotions:

Data Disclaimer: We are aware that the dataset contains biases and is not representative of global diversity. We are aware that the dataset contains potentially problematic content. Potential biases in the data include: Inherent biases in Reddit and user base biases, the offensive/vulgar word lists used for data filtering, inherent or unconscious bias in assessment of offensive identity labels, annotators were all native English speakers from India. All these likely affect labeling, precision, and recall for a trained model. The emotion pilot model used for sentiment labeling, was trained on examples reviewed by the research team. Anyone using this dataset should be aware of these limitations of the dataset.

Running this app

Install Node.js/npm, see Installing Node.js

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in your browser.

The page will reload when you make changes.
You may also see any lint errors in the console.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

Deploying app

Clone this repo and use Cloudflare Pages.

TODO

  • Fix build to copy wasm files from node_modules to build to avoid having wasm files under source control.
  • PR and feedback welcome - create an issue to get in contact.

browser-ml-inference's People

Contributors

mrm8488 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.