{"id":20358005,"url":"https://github.com/arnabd64/zero-shot-text-classification","last_synced_at":"2026-05-04T18:32:21.886Z","repository":{"id":249202980,"uuid":"830025811","full_name":"arnabd64/Zero-Shot-Text-Classification","owner":"arnabd64","description":"An sample webapplication that showcases the capabilites of a Zero Shot Text Classification model.","archived":false,"fork":false,"pushed_at":"2024-07-20T02:08:50.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-15T01:42:01.043Z","etag":null,"topics":["docker","fastapi","gradio","text-classification","transformer","zero-shot-classification"],"latest_commit_sha":null,"homepage":"https://huggingface.co/spaces/arnabdhar/Zero-Shot-Classification-DeBERTa-Quantized","language":"Jupyter Notebook","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/arnabd64.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-17T13:03:20.000Z","updated_at":"2024-07-20T02:08:53.000Z","dependencies_parsed_at":"2024-07-19T08:27:06.001Z","dependency_job_id":"358a33ff-59ae-4c3a-abe2-e81df9a132d7","html_url":"https://github.com/arnabd64/Zero-Shot-Text-Classification","commit_stats":null,"previous_names":["arnabd64/zero-shot-text-classification"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FZero-Shot-Text-Classification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FZero-Shot-Text-Classification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FZero-Shot-Text-Classification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arnabd64%2FZero-Shot-Text-Classification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arnabd64","download_url":"https://codeload.github.com/arnabd64/Zero-Shot-Text-Classification/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241895291,"owners_count":20038511,"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":["docker","fastapi","gradio","text-classification","transformer","zero-shot-classification"],"created_at":"2024-11-14T23:24:56.100Z","updated_at":"2026-05-04T18:32:21.839Z","avatar_url":"https://github.com/arnabd64.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zero Shot Text Classification\n\nThis is the source code for my Huggingface Space deployment. You can checkout the deployed application on [Huggingface Spaces](https://huggingface.co/spaces/arnabdhar/Zero-Shot-Classification-DeBERTa-Quantized). The task of Zero Shot Classification is a Natutal Language Processing technique where a model can __classify text into categories it has not seen during training__. This is acheived by training a model like DeBERTa on a variety of NLP tasks allowing the model to generalize and predict the most relevant class for a given text input based on the context provided by candidate labels.\n\nI have used a [DeBERTa](https://arxiv.org/pdf/2006.03654) model architecture that excels at Zero Shot Tasks very well. I have quantized a finetuned model, [sileod/deberta-v3-base-tasksource-nli](https://huggingface.co/sileod/deberta-v3-base-tasksource-nli) provided by [Damien Sileo](https://huggingface.co/sileod) to further improve the inference latency. The model has been quantized using Huggingface Optimum for ONNX. You can see the [quantize.ipynb](./quantize.ipynb) for the source code for quantization.\n\n## Gradio WebUI\n\nYou can access the Gradio App directly on Huggingface Spaces by following this [Link](https://huggingface.co/spaces/arnabdhar/Zero-Shot-Classification-DeBERTa-Quantized). You can embed this application as an iframe using the following HTML code:\n\n```html\n\u003ciframe\n\tsrc=\"https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space\"\n\tframeborder=\"0\"\n\twidth=\"850\"\n\theight=\"450\"\n\u003e\u003c/iframe\u003e\n```\n\nThe Direct URL is: `https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space`\n\n## API endpoint\n\n1. `cURL` command\n\n```bash\ncurl -X 'POST' \\\n  'https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space/predict' \\\n  -H 'accept: application/json' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"text\": \"I am loving it\",\n  \"labels\": [\"positive\", \"negative\"]\n}'\n```\n\n2. Postman\n\n__Base URL__: https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space\n\n__Method__: `POST`\n\n__URL__: `/predict`\n\n__Body__:\n\n```json\n{\n  \"text\": \"I am loving it\",\n  \"labels\": [\"positive\", \"negative\"]\n}\n```\n\n3. Python\n\n```python\nimport requests\nimport json\n\n# Define the URL\nurl = 'https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space/predict'\n\n# Define the headers\nheaders = {\n    'accept': 'application/json',\n    'Content-Type': 'application/json'\n}\n\n# Define the payload\ndata = {\n    \"text\": \"I am loving it\",\n    \"labels\": [\"positive\", \"negative\"]\n}\n\n# Make the POST request\nresponse = requests.post(url, headers=headers, data=json.dumps(data))\n\n# Print the response\nprint(response.json())\n```\n\n4. Javascript\n\n```javascript\n// Define the URL\nconst url = 'https://arnabdhar-zero-shot-classification-deberta-quantized.hf.space/predict';\n\n// Define the headers\nconst headers = {\n  'accept': 'application/json',\n  'Content-Type': 'application/json'\n};\n\n// Define the payload\nconst data = {\n  text: 'I am loving it',\n  labels: ['positive', 'negative']\n};\n\n// Make the POST request\nfetch(url, {\n  method: 'POST',\n  headers: headers,\n  body: JSON.stringify(data)\n})\n.then(response =\u003e response.json())\n.then(data =\u003e console.log(data))\n.catch(error =\u003e console.error('Error:', error));\n\n```\n\n\n\n\n## Running the Application\n\nTo run the application, I highly recommend using Docker but there are also other ways to get started. But first you have to clone the repository onto your local machine.\n\n```bash\n$ git clone https://github.com/arnabd64/Zero-Shot-Text-Classification.git\n$ cd Zero-Shot-Text-Classification\n```\n\n### Using Docker\n\n1. Build the Docker Image:\n\n```bash\n$ docker build -t zero-shot-text-classification:latest .\n```\n\n2. Run the following docker command:\n\n```bash\n$ docker run -itd \\\n-p 8000:8000  \\\n-e HF_MODEL=pitangent-ds/deberta-v3-nli-onnx-quantized \\\n-e PORT=8000 \\\n-e WORKERS=2 \\\nzero-shot-text-classification:latest\n```\n\nAfter running the docker container wait for a few minutes for the model to download and load into the memory.\n\n### Using Docker Compose (Recommended)\n\n\n```bash\n$ docker compose up -d --build\n```\nAfter running the docker compose wait for a few minutes for the model to download and load into the memory.\n\n### Using python\n\n__Note:__ Use python 3.11 or later (Python 3.10 should work but I have not yet tested it)\n\n1. Create a virtual environment and install dependencies\n\n```bash\n# create a virtual environment\n$ python -m venv .venv\n\n# activate the environment\n$ .venv/bin/activate # on linux and macOS\n$ .venv/Scripts/Activate.ps1 # on Windows\n\n# install dependencies\n$ pip install -e .\n```\n\n2. Set the following Environment Variables\n\n```bash\nHF_MODEL=pitangent-ds/deberta-v3-nli-onnx-quantized\nPORT=8000\nWORKERS=2\n```\n\n3. Run the application\n\n```bash\n$ python main.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnabd64%2Fzero-shot-text-classification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farnabd64%2Fzero-shot-text-classification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farnabd64%2Fzero-shot-text-classification/lists"}