{"id":23135459,"url":"https://github.com/mlh-fellowship/0.1.2-sentiment-analysis-visualization","last_synced_at":"2025-08-17T10:31:30.741Z","repository":{"id":39727452,"uuid":"268891961","full_name":"MLH-Fellowship/0.1.2-sentiment-analysis-visualization","owner":"MLH-Fellowship","description":"Machine Learning Web Application. Helps to visualize a character-by-character breakdown of how sentiment analysis classifies text","archived":false,"fork":false,"pushed_at":"2023-03-25T00:24:39.000Z","size":45250,"stargazers_count":5,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-01T15:34:02.633Z","etag":null,"topics":["bentoml","keras","keras-neural-networks","lstm","lstm-sentiment-analysis","machine-learning","machine-learning-algorithms","sentiment-analysis-visualization","visualizations"],"latest_commit_sha":null,"homepage":"https://mlh-fellowship.github.io/0.1.2-sentiment-analysis-visualization/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MLH-Fellowship.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":"2020-06-02T19:37:21.000Z","updated_at":"2023-09-28T11:16:12.000Z","dependencies_parsed_at":"2023-01-22T04:46:37.755Z","dependency_job_id":null,"html_url":"https://github.com/MLH-Fellowship/0.1.2-sentiment-analysis-visualization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2F0.1.2-sentiment-analysis-visualization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2F0.1.2-sentiment-analysis-visualization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2F0.1.2-sentiment-analysis-visualization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MLH-Fellowship%2F0.1.2-sentiment-analysis-visualization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MLH-Fellowship","download_url":"https://codeload.github.com/MLH-Fellowship/0.1.2-sentiment-analysis-visualization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230113644,"owners_count":18175221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["bentoml","keras","keras-neural-networks","lstm","lstm-sentiment-analysis","machine-learning","machine-learning-algorithms","sentiment-analysis-visualization","visualizations"],"created_at":"2024-12-17T12:15:30.872Z","updated_at":"2024-12-17T12:15:31.779Z","avatar_url":"https://github.com/MLH-Fellowship.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentiment Analysis Visualization\n  \n[![Status](https://img.shields.io/badge/status-active-success.svg)]()\n[![GitHub Issues](https://img.shields.io/github/issues/MLH-Fellowship/0.1.2-sentiment-analysis-visualization.svg)](https://github.com/MLH-Fellowship/0.1.2-sentiment-analysis-visualization/issues)\n[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/MLH-Fellowship/0.1.2-sentiment-analysis-visualization.svg)](https://github.com/MLH-Fellowship/0.1.2-sentiment-analysis-visualization/pulls)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\n-------\n\n## Pod 0.1.2\nA web-app that helps to visualize a word-by-word breakdown of how sentiment analysis classifies text\n\n![Frontend View](https://user-images.githubusercontent.com/23178940/83907584-858fbf00-a71a-11ea-8476-7445c0e16ffe.png)\n\n-------\n\n## Major goals\n- [x] Research and decide on a machine learning model/architecture\n- [x] Pick out 2-3 datasets we can use to train\n- [x] Build a training pipeline\n- [x] Train and implement the model\n- [x] Serve the model using BentoML as an API\n- [x] Create a web app to take in input and visualize the output\n\n-------\n\n## Calling the api\nOur endpoint is at https://sentiment-classifier-gy7t3p45oq-uc.a.run.app/\nOur prediction endpoint can be accessed through making a `POST` request to `https://sentiment-classifier-gy7t3p45oq-uc.a.run.app/predict`.\n\n```bash\n# e.g. \ncurl -X POST \"https://sentiment-classifier-gy7t3p45oq-uc.a.run.app/predict\" \\\n     -H \"accept: */*\" -H \"Content-Type: application/json\" \\\n     -d \"{\\\"text\\\":\\\"Some example text.\\\"}\"\n```\n\nBasically, make sure to set the content type to JSON and send a JSON in the format\n```json\n{\n  \"text\": \"content\"\n}\n```\n\nIf successful, you should get a `200 OK` status and a body with something along the lines of `[[0.8614905476570129], [0.7018478512763977], [0.617088258266449]]` where each entry represents the sentiment from 0 (negative) to 1 (positive) of each word.\n\n\n-------\n\n## Training a new model\nCurrently, we have only implemented a training pipeline for the IMDB dataset but this is subject to change in the future. You can train a new classifier on the dataset by doing \n\n```bash\npython train.py\n```\nThis will replace the current model in `/model`. `model.json` stores the model architecture, `weights.h5` stores trained weights, and `tokenizer.json` stores word indices.\n\n\n-------\n\n## Packaging it with bentoML\nBentoML helps us to easily serve our Keras model through an API. You can package a new API by running \n\n```python\npython bento_service_packager.py\n\u003e ...\n\u003e [0.07744759]\n\u003e [0.1166597 ]\n\u003e [0.18447165]\n\u003e [0.20329727]\n\u003e [0.24308157]\n\u003e [0.25030023]]\n\u003e _____\n\u003e saved model path: /Users/jzhao/bentoml/repository/SentimentClassifierService/20200604214004_F641D2\n```\nIf you'd like to save the packaged API, just copy the contents into `/bento_deploy`\n\n```bash\ncp -r /Users/jzhao/bentoml/repository/SentimentClassifierService/20200604214004_F641D2/* bento_deploy\n# or whatever the autogenerated URI is\n```\n\nThere are a few dependency nuances to be aware of before building the actual Docker image. To make sure the build doesn't error out, edit `bento_deploy/requirements.txt` is\n\n```pip\ntensorflow==2.1.0\nsklearn\nbentoml==0.7.8\n```\n\nThen, we can build and push and run the image as follows\n\n```bash\ndocker build -t bento-classifier:latest .\ndocker run -p 5000:5000 bento-classifier:latest\n```\n\nThen, visit `localhost:5000` to see the BentoML server!\n\n\n-------\n\n## Simple deep LSTM architecture\n```python\n\u003e model.summary()\n_________________________________________________________________\nLayer (type)                 Output Shape              Param #\n=================================================================\nembedding (Embedding)        (None, 100, 64)           320000\n_________________________________________________________________\nlstm (LSTM)                  (None, 100, 64)           33024\n_________________________________________________________________\ndropout (Dropout)            (None, 100, 64)           0\n_________________________________________________________________\nlstm_1 (LSTM)                (None, 64)                33024\n_________________________________________________________________\nFC1 (Dense)                  (None, 256)               16640\n_________________________________________________________________\ndropout_1 (Dropout)          (None, 256)               0\n_________________________________________________________________\nout_layer (Dense)            (None, 1)                 257\n_________________________________________________________________\nactivation (Activation)      (None, 1)                 0\n=================================================================\nTotal params: 402,945\nTrainable params: 402,945\nNon-trainable params: 0\n_________________________________________________________________\n```\n\n-------\n\n## Data and training process\n* 85% / 15% train-test split\n* dataset is balanced (25k positive, 25k negative)\n* RMSProp with 1e-3 Learning Rate and early stopping with patience of 2 epochs\n* preprocessing\n  * to lowercase\n  * removed punctuation\n  * removed `\u003cbr /\u003e` tags\n  * tokenized with vocab size of 5k\n  * max sequence length of 100\n* achieved 82.2% accuracy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlh-fellowship%2F0.1.2-sentiment-analysis-visualization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlh-fellowship%2F0.1.2-sentiment-analysis-visualization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlh-fellowship%2F0.1.2-sentiment-analysis-visualization/lists"}