|
2 | 2 |
|
3 | 3 | This React App demonstrates ML Inference in the Browser using
|
4 | 4 |
|
5 |
| -- [Cloudflare Pages](https://pages.cloudflare.com/) to deliver this app and model via worldwide Content Delivery Network (CDN) |
6 |
| -- [ONNX Runtime Web](https://onnxruntime.ai/) for Model Inference in the Browser |
7 |
| -- [Huggingface](https://huggingface.co/bergum/xtremedistil-emotion) for NLP model hosting and training api |
8 |
| -- [Google Colab](https://colab.research.google.com/) for performing model training |
| 5 | +- [Cloudflare Pages](https://pages.cloudflare.com/) to deliver the React app and model via worldwide Content Delivery Network (CDN) |
| 6 | +- [ONNX Runtime Web](https://onnxruntime.ai/) for model inference in the Browser |
| 7 | +- [Huggingface](https://huggingface.co/bergum/xtremedistil-l6-h384-go-emotion) for NLP model hosting and training API (Transformer library) |
| 8 | +- [Google Colab](https://colab.research.google.com/) for model training using GPU instances |
9 | 9 |
|
10 |
| -Live demo at [https://aiserv.cloud/](https://aiserv.cloud/). See also my [blog post](https://bergum.medium.com/moving-ml-inference-from-the-cloud-to-the-edge-d6f98dbdb2e3?source=friends_link&sk=e8183a3a8c10077110952b213ba5bef4). |
| 10 | +Live demo at [https://aiserv.cloud/](https://aiserv.cloud/) |
11 | 11 |
|
12 |
| -The model is a fine-tuned version of [microsoft/xtremedistil-l6-h256-uncased](https://huggingface.co/microsoft/xtremedistil-l6-h256-uncased) on the [emotion dataset](https://huggingface.co/datasets/emotion). |
| 12 | +<p align="center"> |
| 13 | + <img src="go-emotion.png" /> |
| 14 | +</p> |
13 | 15 |
|
14 |
| -Emotion is a dataset of English Twitter messages with six basic emotions: anger, fear, joy, love, sadness, and surprise. |
15 |
| -The dataset has 16,000 labeled examples which the model was trained on. |
| 16 | +See 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&sk=e8183a3a8c10077110952b213ba5bef4). |
16 | 17 |
|
17 |
| -The model achieves the following results on the Emotion evaluation set: |
18 |
| -- Accuracy: 92.65% (float32) version (49MB) |
19 |
| -- Accuracy: 81.95% (Quantized int8) version (13MB) |
| 18 | +The emotion prediction model is a fine-tuned version of the pre-trained language model |
| 19 | +[microsoft/xtremedistil-l6-h256-uncased](https://huggingface.co/microsoft/xtremedistil-l6-h256-uncased). |
| 20 | +The model has been fine-tuned on the [GoEmotions dataset](https://ai.googleblog.com/2021/10/goemotions-dataset-for-fine-grained.html) which is a multi-label |
| 21 | +text categorization problem. |
20 | 22 |
|
21 |
| -The model is hosted on [Huggingface:bergum/xtremedistil-emotion](https://huggingface.co/bergum/xtremedistil-emotion). |
22 | 23 |
|
23 |
| -See [TrainEmotions.ipynb Notebook](TrainEmotions.ipynb) for Training routine and accuracy evaluation using PyTorch |
24 |
| -and ONNX-Runtime with both float32 and int8 weights. |
25 |
| -[](https://colab.research.google.com/github/jobergum/emotion/blob/main/TrainEmotions.ipynb) |
| 24 | +>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. |
26 | 25 |
|
27 |
| -Since Cloudflare page limit static asset files to maxium 25MB the deployed model version uses int8 weights. |
| 26 | +Paper [GoEmotions: A Dataset of Fine-Grained Emotions](https://arxiv.org/pdf/2005.00547.pdf) |
28 | 27 |
|
29 |
| -See [ONNX Runtime Web Examples](https://microsoft.github.io/onnxruntime-web-demo/#/) for more examples |
30 |
| -of in-Browser model inference. See also [ONNX Runtime Web—running your machine learning model in browser](https://cloudblogs.microsoft.com/opensource/2021/09/02/onnx-runtime-web-running-your-machine-learning-model-in-browser/). |
| 28 | +- The fine-tuned model is hosted on [Huggingface:bergum/xtremedistil-l6-h384-go-emotion](https://huggingface.co/bergum/xtremedistil-l6-h384-go-emotion). |
| 29 | +- The dataset is available on [Huggingface dataset hub](https://huggingface.co/datasets/go_emotions). |
31 | 30 |
|
32 |
| -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). |
| 31 | +See [TrainGoEmotions.ipynb](TrainGoEmotions.ipynb ) for how to train a model on the dataset and export the fine-tuned model to ONNX. |
| 32 | +[](https://colab.research.google.com/github/jobergum/emotion/blob/main/TrainGoEmotions.ipynb) |
33 | 33 |
|
34 |
| -## Code Navigation |
| 34 | +## ONNX-Runtime-web |
| 35 | +The model is quantized to int8 weights and has 22M trainable parameters and is 22MB large. Inference is multi-threaded. To use |
| 36 | +multiple inference threads, specific http headers must be presented by the CDN, see |
| 37 | +[Making your website "cross-origin isolated" using COOP and COEP](https://web.dev/coop-coep/). Three threads are used for inference. |
| 38 | + |
| 39 | +For development, the [src/setupProxy.js](src/setupProxy) adds the required headers. |
| 40 | +See [react issue 10210](https://github.com/facebook/create-react-app/issues/10210) |
35 | 41 |
|
| 42 | +## Code Navigation |
36 | 43 | - The App frontend logic is in [src/App.js](src/App.js)
|
37 | 44 | - The model inference logic is in [src/inference.js](src/inference.js)
|
38 | 45 | - 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)
|
| 46 | +- Cloudflare header override for cross-origin coop policy to enable multi threaded inference [public/_header](public/_headers). |
39 | 47 |
|
40 |
| -## Language Model Bias |
| 48 | +## Model and Language Biases |
41 | 49 | The pre-trained language model was trained on text with biases,
|
42 |
| -see [On the Dangers of Stochastic Parrots: Can Language Models Be Too Big?](https://dl.acm.org/doi/10.1145/3442188.3445922) for a study on the dangers of pre-trained language models and transfer learning. The fine-tuned model |
43 |
| -was tuned on a rather small dataset of 16,000 labeled examples and the bias in the pre-trained model is inherited by |
44 |
| -the fine tuned model. |
| 50 | +see [On the Dangers of Stochastic Parrots: Can Language Models Be Too Big?](https://dl.acm.org/doi/10.1145/3442188.3445922) |
| 51 | +for a study on the dangers of pre-trained language models and transfer learning. |
| 52 | + |
| 53 | +From dataset paper [GoEmotions: A Dataset of Fine-Grained Emotions](https://arxiv.org/pdf/2005.00547.pdf): |
| 54 | +>Data Disclaimer: We are aware that the dataset |
| 55 | +contains biases and is not representative of global |
| 56 | +diversity. We are aware that the dataset contains |
| 57 | +potentially problematic content. Potential biases in |
| 58 | +the data include: Inherent biases in Reddit and user |
| 59 | +base biases, the offensive/vulgar word lists used |
| 60 | +for data filtering, inherent or unconscious bias in |
| 61 | +assessment of offensive identity labels, annotators |
| 62 | +were all native English speakers from India. All |
| 63 | +these likely affect labeling, precision, and recall |
| 64 | +for a trained model. The emotion pilot model used |
| 65 | +for sentiment labeling, was trained on examples |
| 66 | +reviewed by the research team. Anyone using this |
| 67 | +dataset should be aware of these limitations of the |
| 68 | +dataset. |
45 | 69 |
|
46 | 70 | ## Running this app
|
47 | 71 | Install Node.js/npm, see [Installing Node.js](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)
|
|
0 commit comments