{"id":15353319,"url":"https://github.com/yong-asial/huggingface","last_synced_at":"2026-04-11T02:57:29.968Z","repository":{"id":223239766,"uuid":"759683700","full_name":"yong-asial/huggingface","owner":"yong-asial","description":"Run huggingFace model locally","archived":false,"fork":false,"pushed_at":"2024-11-29T04:55:56.000Z","size":78,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-11T13:36:23.935Z","etag":null,"topics":["docker","huggingface","nlp","pipeline","pytorch","sentiment-analysis","tensorflow","transformer"],"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/yong-asial.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-02-19T06:13:41.000Z","updated_at":"2025-01-28T15:24:17.000Z","dependencies_parsed_at":"2025-07-11T12:35:00.965Z","dependency_job_id":"8dde1db7-9c90-4a38-8bf4-d32b0a54ffd4","html_url":"https://github.com/yong-asial/huggingface","commit_stats":null,"previous_names":["yong-asial/huggingface"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yong-asial/huggingface","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yong-asial%2Fhuggingface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yong-asial%2Fhuggingface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yong-asial%2Fhuggingface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yong-asial%2Fhuggingface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yong-asial","download_url":"https://codeload.github.com/yong-asial/huggingface/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yong-asial%2Fhuggingface/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31667034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T17:19:37.612Z","status":"online","status_checked_at":"2026-04-11T02:00:05.776Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["docker","huggingface","nlp","pipeline","pytorch","sentiment-analysis","tensorflow","transformer"],"created_at":"2024-10-01T12:13:43.721Z","updated_at":"2026-04-11T02:57:29.954Z","avatar_url":"https://github.com/yong-asial.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentiment Analysis Application\n\nThis application uses a Hugging Face model to perform sentiment analysis on a sentence provided as a command line argument.\n\n## Project Structure\n\n- `apps/`: Contains the Python script for the application.\n- `apps/model`: Contains the saved model locally.\n- `docker-compose.yml`: Docker Compose configuration file.\n- `Dockerfile`: Dockerfile for building the Docker image. It might takes around 9GB.\n- `requirements.txt`: Contains Python dependencies for the application.\n  - Pytorch: install `torchvision` and `torchaudio` for using Vision and Audio models.\n  - Tensorflow: install `tensorflow` for using tensorflow models.\n\n## Setup\n\n### Build\n\n```bash\ndocker-compose build\n```\n\n### Run\n\n```bash\ndocker-compose up -d\n```\n\n### Stop\n\n```bash\ndocker-compose down\n```\n\n## Usage\n\nRun the application with a sentence as command line arguments:\n\n```bash\ndocker exec -it python-server bash\npython3 index.py \"task_name\" \"model_name\" \"sentence\"\n```\n\n## Pytorch vs. Tensorflow vs. Default\n\nFor a model (for example, nlptown/bert-base-multilingual-uncased-sentiment), there are many model binaries, pytorch, tensorflow, jax, etc. We can choose to use which model binary by using specific Tokenizer and Model class.\n\n### Pytorch\n\n```python\nfrom transformers import AutoTokenizer, AutoModelForSequenceClassification\n\n# load pytorch model from hugginFace\nmodel_name = \"nlptown/bert-base-multilingual-uncased-sentiment\"\nmodel = AutoModelForSequenceClassification.from_pretrained(model_name)\ntokenizer = AutoTokenizer.from_pretrained(model_name)\n\n# save model\nsave_directory = \"./directory\"\ntokenizer.save_pretrained(save_directory)\nmodel.save_pretrained(save_directory)\n\n# load model from local\ntokenizer = AutoTokenizer.from_pretrained(save_directory)\nmodel = AutoModelForSequenceClassification.from_pretrained(save_directory)\n\n# use model\nclassifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer)\nclassifier(\"I like huggingFace.\")\n```\n\n### Tensorflow\n\nNote: to use following code, you need to install `tensorflow` to this docker.\n\n```python\nfrom transformers import AutoTokenizer, TFAutoModelForSequenceClassification\n\n# load tensorflow model from hugginFace\nmodel_name = \"nlptown/bert-base-multilingual-uncased-sentiment\"\nmodel = TFAutoModelForSequenceClassification.from_pretrained(model_name)\ntokenizer = AutoTokenizer.from_pretrained(model_name)\n\n# save tensorflow model\nsave_directory = \"./directory\"\ntokenizer.save_pretrained(save_directory)\nmodel.save_pretrained(save_directory)\n\n# load model from local\ntokenizer = AutoTokenizer.from_pretrained(save_directory)\ntf_model = TFAutoModelForSequenceClassification.from_pretrained(save_directory)\n\n# use model\nclassifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer)\nclassifier(\"I like huggingFace.\")\n```\n\n### Default\n\nOtherwise, we just use `pipeline` function to import default Tokenizer/Model for specified model_name.\nWe don't need to import Tokenizer and Model class.\n\n```python\nfrom transformers import pipeline\n\n# load default model from huggingFace\nmodel_name = \"nlptown/bert-base-multilingual-uncased-sentiment\"\nclassifier = pipeline(\"sentiment-analysis\", model=model_name)\n\n# save model\nsave_directory = \"./directory\"\nclassifier.model.save_pretrained(save_directory)\nclassifier.tokenizer.save_pretrained(save_directory)\n\n# Load the pipeline with the saved model\nclassifier = pipeline(\"sentiment-analysis\", model=save_directory)\nclassifier(\"I like huggingFace.\")\n```\n\n## Installed Packages\n\nThese are required for translation model.\n\n```txt\nsentencepiece\nsacremoses\n```\n\n## Use it with Javascript\n\nIf the model has onnx (model.onnx) then we can use transformer.js to load and infer the model.\n\n```javascript\nimport { pipeline } from '@xenova/transformers';\nconst pipe = await pipeline('sentiment-analysis', 'Xenova/distilbert-base-uncased-finetuned-sst-2-english');\nconst out = await pipe('I love transformers!');\n```\n\nOtherwise, if the model doesn't have onnx, we first need to convert it to onnx using onnx-converter\n\n```bash\ncd onnx-converter\ndocker-compose build\ndocker-compose up -d\ndocker exec -it python-server bash\npython convert.py --quantize --model_id google-bert/bert-base-uncased\n```\n\nThen you can copy the onnx model to somewhere and load it\n\n```javascript\nimport { pipeline, env } from '@xenova/transformers';\n\nenv.localModelPath = './models/';\nenv.allowRemoteModels = false;\nconst pipe = await pipeline('fill-mask', 'google-bert/bert-base-uncased');\nconst out = await pipe(\"Hello I'm a [MASK] model.\");\n```\n\n## Resources\n\n- [Google Colab](https://colab.research.google.com/drive/1sWXmi8xaBUw6-ZYi3y76ODw50jM1jxJb)\n- [Transformer.js](https://huggingface.co/docs/transformers.js/index)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyong-asial%2Fhuggingface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyong-asial%2Fhuggingface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyong-asial%2Fhuggingface/lists"}