File size: 1,611 Bytes
d83353e
 
 
 
 
 
 
 
 
ee6e30e
d83353e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ee6e30e
00b6946
 
d83353e
 
 
 
 
 
 
 
 
 
 
 
 
 
ee6e30e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

# Sentiment Analysis Longformer

This model is a fine-tuned version of the Longformer base model for sentiment analysis. It classifies text into 5 sentiment categories.

## Model Details
- Model Type: Longformer
- Task: Sentiment Analysis
- Training Data: 4000 customer support tickets (Approx 1000 for each class)
- Number of Parameters: 149M

## Performance
- Overall Accuracy: 74.84%

Classification Report:
```
              precision    recall  f1-score   support
           0       0.75      1.00      0.86        98
           1       0.67      0.55      0.60        87
           2       0.84      0.75      0.79       108
           3       0.83      0.43      0.57        79
           4       0.70      0.91      0.79       105

    accuracy                           0.75       477
   macro avg       0.76      0.73      0.72       477
weighted avg       0.76      0.75      0.73       477
```

## Usage

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

hf_model_name= 'Muddassar/longformer-base-sentiment-5-classes'
model = AutoModelForSequenceClassification.from_pretrained(hf_model_name)
tokenizer = AutoTokenizer.from_pretrained(hf_model_name)

text = "Your text here"
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=1500)
with torch.no_grad():
    outputs = model(**inputs)
    prediction = torch.argmax(outputs.logits, dim=1).item()

sentiment_map = {0: "Very Negative", 1: "Negative", 2: "Neutral", 3: "Positive", 4: "Very Positive"}
print(f"Predicted sentiment: {sentiment_map[prediction]}")
```



## License
MIT