{"id":13535156,"url":"https://github.com/lynnna-xu/bert_sa","last_synced_at":"2025-04-02T00:32:42.113Z","repository":{"id":193474328,"uuid":"160899871","full_name":"lynnna-xu/bert_sa","owner":"lynnna-xu","description":"bert sentiment analysis tensorflow serving with RESTful API","archived":false,"fork":false,"pushed_at":"2018-12-09T03:19:53.000Z","size":24,"stargazers_count":33,"open_issues_count":2,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-02T23:32:28.263Z","etag":null,"topics":["bert","rest-client","restful-api","sentiment-analysis","tensorflow-serving"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lynnna-xu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-12-08T03:22:35.000Z","updated_at":"2022-11-14T02:49:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"f4d4dc04-d49a-434b-9dd0-26d1c3ee212e","html_url":"https://github.com/lynnna-xu/bert_sa","commit_stats":null,"previous_names":["lynnna-xu/bert_sa"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lynnna-xu%2Fbert_sa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lynnna-xu%2Fbert_sa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lynnna-xu%2Fbert_sa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lynnna-xu%2Fbert_sa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lynnna-xu","download_url":"https://codeload.github.com/lynnna-xu/bert_sa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246735354,"owners_count":20825221,"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":["bert","rest-client","restful-api","sentiment-analysis","tensorflow-serving"],"created_at":"2024-08-01T08:00:50.499Z","updated_at":"2025-04-02T00:32:41.801Z","avatar_url":"https://github.com/lynnna-xu.png","language":"Python","funding_links":[],"categories":["BERT Sentiment Analysis"],"sub_categories":[],"readme":"# bert_sa (bert sentiment analysis tensorflow serving with RESTful API)\nbased on [bert](https://github.com/google-research/bert/blob/master/multilingual.md) including training, online predicting and serving with [REST](https://www.tensorflow.org/serving/api_rest) \n\n## Fine tune a sentiment analysis model based on [BERT](https://github.com/google-research/bert)\n1. Add a `SAProcessor` and include it within `main` function in run_classifier.py \n2. Prepare train, dev and test files; adapat `_create_examples` method in `SAProcessor` based on your own datasets (pandas may not be required)\n3. Specify `BERT_BASE_DIR`, `SA_DIR` and `output_dir` in run_sa.sh and run \n\n\n## Test\n1. For file based test, change `output_predict_file` in run_classifier.py, specify `TRAINED_CLASSIFIER` and `output_dir` path, run predict_sa.sh \n2. For online prediction, refer to run_classifier_predict_online (modified based on [bert_language_understanding](https://github.com/brightmart/bert_language_understanding))\n\n## Export your model\nRefer to sa_predict_saved_model.py\n\n**KIND NOTICE:** some graph definition and input placeholder is imported from run_classifier_predict_online.py\n\n## Serve the model with TensorFlow Serving\n1. See [TensorFlow Serving](https://www.tensorflow.org/serving/docker) for details about installing docker and pulling a serving image\n2. Running a serving image\n```Bash\ndocker run -p 8501:8501 --name 'bert_sa_serving' --mount type=bind,source=/data/notebooks/xff/bert/output/sa_output/saved_model,target=/models/bert_sa -e MODEL_NAME=bert_sa -t tensorflow/serving:latest-devel-gpu \u0026\n\ndocker exec -it bert_sa_serving bash\n\ntensorflow_model_server --port=8500 --rest_api_port=8501 \\\n  --model_name=bert_sa --model_base_path=/models/bert_sa\n ```\n\n3. Sample request\n```Python\nline=u'建立了完善的质量体系并持续有效运行'\n# preprocess is defined in run_classifier_predict_online.py\ndict_data = preprocess(line)\nresp = requests.post('http://172.17.0.1:8501/v1/models/bert_sa:predict', json=dict_data)\nprint(resp.json())\n```\nResults look like this:\n{'outputs': {'label_predict': 1, 'possibility': [0.00738544, 0.992615]}}\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flynnna-xu%2Fbert_sa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flynnna-xu%2Fbert_sa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flynnna-xu%2Fbert_sa/lists"}