Views
No views yet
Negative (0), Neutral (1), Positive (2)bert-base-uncased| Metric | Score |
|---|---|
| Accuracy | 0.98 |
| F1 | 0.99 |
| Precision | 0.99 |
| Recall | 0.97 |
| Label ID | Sentiment |
|---|---|
| 0 | Negative |
| 1 | Neutral |
| 2 | Positive |
1import pandas as pd
2from sklearn.model_selection import train_test_split
3from sklearn.preprocessing import LabelEncoder
4from sklearn.metrics import accuracy_score, precision_recall_fscore_support
5import torch
6from transformers import BertTokenizer, BertForSequenceClassification, Trainer, TrainingArguments
7from datasets import Dataset
8import torch.nn.functional as F
9
10# Load model and tokenizer
11model_name = "AventIQ-AI/Sentiment-Analysis-for-Contract-Sentiment"
12tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
13model = BertForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=3)
14model.eval()
15
16def tokenize_function(examples):
17 return tokenizer(examples['text'], padding='max_length', truncation=True)
18
19
20# Inference
21def predict_sentiment(user_text):
22 # Ensure input is a list for batch processing
23 if isinstance(user_text, str):
24 user_text = [user_text]
25
26 # Tokenize input text
27 inputs = tokenizer(user_text, return_tensors="pt", padding=True, truncation=True)
28
29 # Predict using the model
30 with torch.no_grad():
31 outputs = model(**inputs)
32 preds = torch.argmax(outputs.logits, dim=1)
33
34 # Decode predictions back to original sentiment labels
35 decoded_preds = label_encoder.inverse_transform(preds.numpy())
36
37 # Print each prediction
38 for text, sentiment in zip(user_text, decoded_preds):
39 print(f"Text: '{text}' => Sentiment: {sentiment}")
40
41
42# Example
43predict_sentiment("The delivery scheduled").
├── model/ # Quantized model files
├── tokenizer/ # Tokenizer config and vocabulary
├── model.safetensors/ # Fine-tuned full-precision model
├── README.md # Model documentation