Instructions to use zeroshot/sst2-distilbert-dense with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zeroshot/sst2-distilbert-dense with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="zeroshot/sst2-distilbert-dense")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("zeroshot/sst2-distilbert-dense") model = AutoModelForSequenceClassification.from_pretrained("zeroshot/sst2-distilbert-dense", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from zeroshot/sst2-distilbert-dense: direct link, hf CLI and curl.
- Browser
- Download file 711 Bytes
-
https://huggingface.co/zeroshot/sst2-distilbert-dense/resolve/main/handler.py
- Command line
-
hf download hf://zeroshot/sst2-distilbert-dense/handler.py
-
curl -L -o handler.py https://huggingface.co/zeroshot/sst2-distilbert-dense/resolve/main/handler.py
711 Bytes
| from typing import Dict, Any | |
| from deepsparse import Pipeline | |
| from time import perf_counter | |
| class EndpointHandler: | |
| def __init__(self, path=""): | |
| self.pipeline = Pipeline.create(task="text-classification", model_path=path) | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, str]: | |
| """ | |
| Args: | |
| data (:obj:): prediction input text | |
| """ | |
| inputs = data.pop("inputs", data) | |
| start = perf_counter() | |
| prediction = self.pipeline(inputs) | |
| end = perf_counter() | |
| latency = end - start | |
| return { | |
| "labels": prediction.labels, | |
| "scores": prediction.scores, | |
| "latency (secs.)": latency | |
| } |