README.md 1.38 KB
Newer Older
GmailB's avatar
GmailB committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
---
language: it
tags:
- sentiment
- Italian
license: MIT
widget:
- text: 'Giuseppe Rossi  un ottimo politico'
---

# 馃 + polibert_SA - POLItic BERT based Sentiment Analysis
  
## Model description  
  
GmailB's avatar
GmailB committed
15
This model performs sentiment analysis on Italian political twitter sentences. It was trained starting from an instance of "bert-base-italian-uncased-xxl" and fine-tuned on an Italian dataset of tweets. You can try it out at https://www.unideeplearning.com/twitter_sa/ (in italian!)
GmailB's avatar
GmailB committed
16
17
18
19
20
21
  
#### Hands-on  
  
```python
import torch
from torch import nn 
GmailB's avatar
GmailB committed
22
from transformers import AutoTokenizer, AutoModelForSequenceClassification
GmailB's avatar
GmailB committed
23

GmailB's avatar
GmailB committed
24
25
26
27
28
29
30
tokenizer = AutoTokenizer.from_pretrained("unideeplearning/polibert_sa")
model = AutoModelForSequenceClassification.from_pretrained("unideeplearning/polibert_sa")
			



text = "Giuseppe Rossi 猫 un pessimo politico"
GmailB's avatar
GmailB committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
input_ids = tokenizer.encode(text, add_special_tokens=True, return_tensors= 'pt')

logits, = model(input_ids)
logits = logits.squeeze(0)

prob = nn.functional.softmax(logits, dim=0)

# 0 Negative, 1 Neutral, 2 Positive 
print(prob.argmax().tolist())
```  
  
#### Hyperparameters

- Optimizer: **AdamW** with learning rate of **2e-5**, epsilon of **1e-8**
- Max epochs: **2**
- Batch size: **16**

## Acknowledgments

Thanks to the support from: 
GmailB's avatar
GmailB committed
51
52
53
the [Hugging Face](https://huggingface.co/), https://www.unioneprofessionisti.com

https://www.unideeplearning.com/