Views
No views yet
bert-base-uncased by GoogleNegative (0), Neutral (1), Positive (2)bert-base-uncased| Metric | Score |
|---|---|
| Accuracy | 0.90 |
| F1 | 0.90 |
| Precision | 0.90 |
| Recall | 0.90 |
| Label ID | Sentiment |
|---|---|
| 0 | Negative |
| 1 | Neutral |
| 2 | Positive |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer, TrainingArguments
2from transformers import DataCollatorWithPadding
3import torch
4import torch.nn.functional as F
5
6# Load model and tokenizer
7model_name = "AventIQ-AI/Sentiment-Analysis-for-Product-Release-Sentiment"
8tokenizer = BertTokenizer.from_pretrained(model_name)
9model = BertForSequenceClassification.from_pretrained(model_name)
10model.eval()
11
12# Inference
13def predict_sentiment(text):
14 inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
15 inputs = {k: v.to(quantized_model.device) for k, v in inputs.items()}
16 with torch.no_grad():
17 logits = quantized_model(**inputs).logits
18 probs = F.softmax(logits, dim=1)
19
20 predicted_class_id = torch.argmax(probs, dim=1).item()
21 confidence = probs[0][predicted_class_id].item()
22
23 label_map = {0: "Negative", 1: "Positive"}
24 label = label_map[predicted_class_id]
25 confidence_str = f"confidence : {confidence * 100:.1f}%"
26
27 return label, confidence_str
28
29# Example
30print(predict_sentiment(
31"The service was excellent and the staff was friendly.")
32).
├── model/ # Quantized model files
├── tokenizer/ # Tokenizer config and vocabulary
├── model.safetensors/ # Fine-tuned full-precision model
├── README.md # Model documentation