-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
20 lines (16 loc) · 718 Bytes
/
app.py
File metadata and controls
20 lines (16 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from transformers import pipeline
import torch
# Specify the model and revision explicitly
model_name = "distilbert/distilbert-base-uncased-finetuned-sst-2-english"
# Check if MPS (Apple's Metal Performance Shaders) is available
if torch.backends.mps.is_available():
device = torch.device("mps")
print("Using MPS (Apple's Metal Performance Shaders) for computation.")
else:
device = torch.device("cpu")
print("MPS not available. Using CPU for computation.")
# Initialize the pipeline with the specified model and device
classifier = pipeline("sentiment-analysis", model=model_name, device=device)
# Test the classifier with a sample sentence
result = classifier("This is fantastic!")
print(result)