Text Classification
Transformers
ONNX
English
distilbert
sparsity
pruning
compression
text-embeddings-inference
Instructions to use RedHatAI/sst2-distilbert-sparse-blog with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RedHatAI/sst2-distilbert-sparse-blog with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="RedHatAI/sst2-distilbert-sparse-blog")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("RedHatAI/sst2-distilbert-sparse-blog") model = AutoModelForSequenceClassification.from_pretrained("RedHatAI/sst2-distilbert-sparse-blog", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 729 Bytes
f3ad8a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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, scheduler="sync")
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
} |