Views
No views yet
| Training Loss | Epoch | Step | Validation Loss | Accuracy | F1 |
|---|---|---|---|---|---|
| No log | 1.0 | 291 | 0.1533 | 0.9467 | 0.9466 |
| 0.2224 | 2.0 | 582 | 0.2004 | 0.9467 | 0.9469 |
| 0.2224 | 3.0 | 873 | 0.2178 | 0.9553 | 0.9553 |
| 0.0393 | 4.0 | 1164 | 0.2400 | 0.9553 | 0.9552 |
| 0.0393 | 5.0 | 1455 | 0.2481 | 0.9519 | 0.9520 |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2model_path = "ehab215/egyptian_sentiment_analysis"
3tokenizer = AutoTokenizer.from_pretrained(model_path)
4model = AutoModelForSequenceClassification.from_pretrained(model_path)
5
6# Ensure model is on GPU if available
7device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8model.to(device)
9
10# Step 2: Prepare test examples
11examples = [
12 add any examples you would
13]
14
15# Tokenize the examples
16inputs = tokenizer(examples, truncation=True, padding=True, return_tensors="pt", max_length=256)
17inputs = {key: val.to(device) for key, val in inputs.items()}
18
19# Step 3: Make predictions
20with torch.no_grad():
21 outputs = model(**inputs)
22 logits = outputs.logits
23 predictions = torch.argmax(logits, dim=-1).cpu().numpy()
24
25# Step 4: Interpret results
26label_map = {0: "negative", 1: "neutral", 2: "positive"}
27predicted_labels = [label_map[p] for p in predictions]
28
29# Display results
30for text, label in zip(examples, predicted_labels):
31 print(f"Text: {text}")
32 print(f"Predicted Sentiment: {label}")
33 print("-" * 50)