Views
No views yet
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4# Load model and tokenizer
5device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6model_name = "agentlans/deberta-v3-xsmall-zyda-2-sentiment"
7model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=1).to(device)
8tokenizer = AutoTokenizer.from_pretrained(model_name)
9
10# Function to perform inference
11def predict_score(text):
12 inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True).to(device)
13 with torch.no_grad():
14 logits = model(**inputs).logits
15 return logits.item()
16
17# Example usage
18input_text = "I accidentally the whole thing. Is that bad?"
19score = predict_score(input_text)
20print(f"Predicted score: {score}")| Text | Sentiment |
|---|---|
| Nothing seems to go right, and I'm constantly frustrated. | -2.25 |
| Everything is falling apart, and I can't see any way out. | -2.02 |
| I feel completely overwhelmed by the challenges I face. | -1.62 |
| There are some minor improvements, but overall, things are still tough. | -0.81 |
| I can see a glimmer of hope amidst the difficulties I encounter. | 1.03 |
| Things are starting to look up, and I'm cautiously optimistic. | 2.06 |
| There are many good things happening, and I appreciate them. | 2.23 |
| I'm feeling more positive about my situation than I have in a while. | 2.39 |
| Every day brings new joy and possibilities; I feel truly blessed. | 2.54 |
| Life is full of opportunities, and I'm excited about the future. | 2.56 |
| Training Loss | Epoch | Step | Validation Loss | MSE |
|---|---|---|---|---|
| 0.0792 | 1.0 | 2011 | 0.0871 | 0.0871 |
| 0.0541 | 2.0 | 4022 | 0.0691 | 0.0691 |
| 0.0411 | 3.0 | 6033 | 0.0656 | 0.0656 |