File size: 1,384 Bytes
cf372de
 
3f45422
 
 
 
 
 
cf372de
af5915b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
language:
- en
metrics:
- accuracy
library_name: transformers
pipeline_tag: text-classification
---
This GPT-2 model was fine-tuned using +400k nuclear energy tweets from twitter/X. The classification accuracy is 95%.

The number of labels is 3: {0: Negative, 1: Neutral, 2: Positive}

This is an example to use it
```bash
from transformers import AutoTokenizer
from transformers import pipeline
from transformers import AutoModelForSequenceClassification
import torch

checkpoint = 'kumo24/gpt2-sentiment-nuclear'
tokenizer=AutoTokenizer.from_pretrained(checkpoint)
id2label = {0: "negative", 1: "neutral", 2: "positive"}
label2id = {"negative": 0, "neutral": 1, "positive": 2}
    

if tokenizer.pad_token is None:
    tokenizer.add_special_tokens({'pad_token': '[PAD]'})

model = AutoModelForSequenceClassification.from_pretrained(checkpoint, 
                                                       num_labels=3,
                                                       id2label=id2label, 
                                                       label2id=label2id)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)


sentiment_task = pipeline("sentiment-analysis", 
                          model=model, 
                          tokenizer=tokenizer)

print(sentiment_task("Michigan Wolverines are Champions, Go Blue!"))