Views
No views yet
| Split | Examples |
|---|---|
| Training | 399 |
| Validation | 100 |
| Test | 125 |
| Total | 624 |
| Model | Accuracy | Macro F1 |
|---|---|---|
| Base FinBERT-PT-BR | 0.336 | 0.325 |
| Fine-tuned Ensemble | 0.784 | 0.783 |
subfolder:1from transformers import AutoTokenizer, BertForSequenceClassification
2import torch
3
4model_id = "lucasalmda/pt-br-financial-sentimental-analysis"
5seed = "seed-789" # also available: "seed-123" and "seed-456"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id, subfolder=seed)
8model = BertForSequenceClassification.from_pretrained(model_id, subfolder=seed)
9model.eval()
10
11id2label = {
12 0: "POSITIVE",
13 1: "NEGATIVE",
14 2: "NEUTRAL",
15}
16
17text = "Ibovespa fecha em alta com expectativa de corte na taxa Selic"
18
19inputs = tokenizer(
20 text,
21 return_tensors="pt",
22 truncation=True,
23 max_length=512,
24)
25
26with torch.no_grad():
27 logits = model(**inputs).logits
28 prediction = logits.argmax(dim=-1).item()
29
30print(id2label[prediction])argmax:1from transformers import AutoTokenizer, BertForSequenceClassification
2import torch
3
4model_id = "lucasalmda/pt-br-financial-sentimental-analysis"
5seeds = ["seed-789", "seed-123", "seed-456"]
6text = "Ibovespa fecha em alta com expectativa de corte na taxa Selic"
7
8all_logits = []
9for seed in seeds:
10 tokenizer = AutoTokenizer.from_pretrained(model_id, subfolder=seed)
11 model = BertForSequenceClassification.from_pretrained(model_id, subfolder=seed)
12 model.eval()
13
14 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
15 with torch.no_grad():
16 all_logits.append(model(**inputs).logits)
17
18ensemble_logits = torch.stack(all_logits).mean(dim=0)
19prediction = ensemble_logits.argmax(dim=-1).item()
20
21print({0: "POSITIVE", 1: "NEGATIVE", 2: "NEUTRAL"}[prediction])