{"id":28428669,"url":"https://github.com/jobergum/browser-ml-inference","last_synced_at":"2026-03-04T06:03:02.173Z","repository":{"id":40615041,"uuid":"440948712","full_name":"jobergum/browser-ml-inference","owner":"jobergum","description":"Edge Inference in Browser with Transformer NLP model","archived":false,"fork":false,"pushed_at":"2022-09-27T06:14:04.000Z","size":81257,"stargazers_count":316,"open_issues_count":1,"forks_count":57,"subscribers_count":9,"default_branch":"main","last_synced_at":"2026-02-09T06:49:57.477Z","etag":null,"topics":["cloudflare-pages","edge-computing","huggingface","nlp","onnx","onnx-runtime","react","transformers"],"latest_commit_sha":null,"homepage":"https://aiserv.cloud/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jobergum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-22T18:23:23.000Z","updated_at":"2026-01-24T12:36:56.000Z","dependencies_parsed_at":"2023-01-17T19:00:53.845Z","dependency_job_id":null,"html_url":"https://github.com/jobergum/browser-ml-inference","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jobergum/browser-ml-inference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobergum%2Fbrowser-ml-inference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobergum%2Fbrowser-ml-inference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobergum%2Fbrowser-ml-inference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobergum%2Fbrowser-ml-inference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jobergum","download_url":"https://codeload.github.com/jobergum/browser-ml-inference/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jobergum%2Fbrowser-ml-inference/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30073688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T05:31:57.858Z","status":"ssl_error","status_checked_at":"2026-03-04T05:31:38.462Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare-pages","edge-computing","huggingface","nlp","onnx","onnx-runtime","react","transformers"],"created_at":"2025-06-05T12:38:53.107Z","updated_at":"2026-03-04T06:03:02.168Z","avatar_url":"https://github.com/jobergum.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text Emotion Prediction in Browser\n\nThis React App demonstrates ML Inference in the Browser using\n\n- [Cloudflare Pages](https://pages.cloudflare.com/) to deliver the React app and model via worldwide Content Delivery Network (CDN)\n- [ONNX Runtime Web](https://onnxruntime.ai/) for model inference in the Browser\n- [Huggingface](https://huggingface.co/bergum/xtremedistil-l6-h384-go-emotion) for NLP model hosting and training API (Transformer library) \n- [Google Colab](https://colab.research.google.com/) for model training using GPU instances \n\nLive demo at [https://aiserv.cloud/](https://aiserv.cloud/). \n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"GoEmotions.gif\" /\u003e\n\u003c/p\u003e\n\nSee also my blog post [Moving ML Inference from the Cloud to the Edge](https://bergum.medium.com/moving-ml-inference-from-the-cloud-to-the-edge-d6f98dbdb2e3?source=friends_link\u0026sk=e8183a3a8c10077110952b213ba5bef4) and [Deploy Transformer Models in the Browser with #ONNXRuntime on YouTube](https://www.youtube.com/watch?v=W_lUGPMW_Eg). \n\nThe emotion prediction model is a fine-tuned version of the pre-trained language model \n[microsoft/xtremedistil-l6-h384-uncased](https://huggingface.co/microsoft/xtremedistil-l6-h384-uncased). \nThe model has been fine-tuned on the \n[GoEmotions dataset](https://ai.googleblog.com/2021/10/goemotions-dataset-for-fine-grained.html) which is a multi-label \ntext categorization problem. \n\n\n\u003eGoEmotions, 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.\n\nPaper [GoEmotions: A Dataset of Fine-Grained Emotions](https://arxiv.org/pdf/2005.00547.pdf)\n\n- The fine-tuned model is hosted on [Huggingface:bergum/xtremedistil-l6-h384-go-emotion](https://huggingface.co/bergum/xtremedistil-l6-h384-go-emotion). \n- The `go_emotions` dataset is available on [Huggingface dataset hub](https://huggingface.co/datasets/go_emotions). \n\nSee [TrainGoEmotions.ipynb](TrainGoEmotions.ipynb ) for how to train a model on the dataset and export the fine-tuned model to ONNX. \n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/jobergum/emotion/blob/main/TrainGoEmotions.ipynb)\n\n## ONNX-Runtime-web\nThe model is quantized to `int8` weights and has 22M trainable parameters. \n\nInference is multi-threaded. To use\nmultiple inference threads, specific http headers must be presented by the CDN, see \n[Making your website \"cross-origin isolated\" using COOP and COEP](https://web.dev/coop-coep/). \n\nThree threads are used for inference. Due to this [bug](https://github.com/microsoft/onnxruntime/issues/11679) \nmulti-threading and COOP headers had to be disabled as the model would silently fail to initialize on IOS devices.\n\nFor development, the [src/setupProxy.js](src/setupProxy.js) adds the required headers. \nSee [react issue 10210](https://github.com/facebook/create-react-app/issues/10210)\n\n## Code Navigation\n- The App frontend logic is in [src/App.js](src/App.js)\n- The model inference logic is in [src/inference.js](src/inference.js)\n- The tokenizer is in [src/bert_tokenizer.js](src/bert_tokenizer.ts) which is a copy of [Google TFJS](https://raw.githubusercontent.com/tensorflow/tfjs-models/master/qna/src/bert_tokenizer.ts) (Apache 2.0)\n- Cloudflare header override for cross-origin coop policy to enable multi threaded inference [public/_header](public/_headers). \n\n## Model and Language Biases\nThe pre-trained language model was trained on text with biases, \nsee [On the Dangers of Stochastic Parrots: Can Language Models Be Too Big?](https://dl.acm.org/doi/10.1145/3442188.3445922) \nfor a study on the dangers of pre-trained language models and transfer learning. \n\nFrom dataset paper [GoEmotions: A Dataset of Fine-Grained Emotions](https://arxiv.org/pdf/2005.00547.pdf):\n\u003eData Disclaimer: We are aware that the dataset\ncontains biases and is not representative of global\ndiversity. We are aware that the dataset contains\npotentially problematic content. Potential biases in\nthe data include: Inherent biases in Reddit and user\nbase biases, the offensive/vulgar word lists used\nfor data filtering, inherent or unconscious bias in\nassessment of offensive identity labels, annotators\nwere all native English speakers from India. All\nthese likely affect labeling, precision, and recall\nfor a trained model. The emotion pilot model used\nfor sentiment labeling, was trained on examples\nreviewed by the research team. Anyone using this\ndataset should be aware of these limitations of the\ndataset.\n\n## Running this app \nInstall Node.js/npm, see [Installing Node.js](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)\n\nIn the project directory, you can run: \n\n### `npm start`\n\nRuns the app in the development mode.\\\nOpen [http://localhost:3000](http://localhost:3000) to view it in your browser.\n\nThe page will reload when you make changes.\\\nYou may also see any lint errors in the console.\n\n### `npm run build`\n\nBuilds the app for production to the `build` folder.\\\nIt correctly bundles React in production mode and optimizes the build for the best performance.\n\n### Deploying app\nClone this repo and use [Cloudflare Pages](https://pages.cloudflare.com/). \n\n## TODO \n- Fix build to copy wasm files from node_modules to build to avoid having wasm files under source control.  \n- PR and feedback welcome - create an issue to get in contact. \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjobergum%2Fbrowser-ml-inference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjobergum%2Fbrowser-ml-inference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjobergum%2Fbrowser-ml-inference/lists"}