File size: 1,634 Bytes
1fc1d3c
5bc8ba7
 
ca1e333
1ea8d08
5bc8ba7
 
e598c92
5bc8ba7
a89ffdc
3d1835a
dd94905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9b1cb7
 
78a8594
 
 
 
 
 
 
 
202ecf5
78a8594
c9b1cb7
 
 
 
 
 
 
 
 
 
 
 
 
78a8594
 
dac415d
d49689e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ea8d08
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
language:
- pt
license: mit
library_name: transformers
metrics:
- accuracy
- f1
pipeline_tag: text-classification
---

I trained this model just to learn, using a dataset of product reviews

## HYPERPAREMETERS

lr = 1e-3
batch_size = 4
num_epochs = 5
weight_decay = 0.01
LoraConfig:
r=4
lora_alpha=32
lora_dropout=0.01
target_modules = ['q_lin']

## F1_SCORE = 0.914643


## HOW TO USE

```python
from transformers import (
    AutoTokenizer,
    AutoConfig,
    AutoModelForSequenceClassification,
)

from peft import PeftModel, PeftConfig, get_peft_model

model_repo = "igoramf/lora-pt-sentiment-analysis"

config = PeftConfig.from_pretrained(model_repo)
model = AutoModelForSequenceClassification.from_pretrained(
    config.base_model_name_or_path,
    num_labels=3
)

tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
tokenizer.pad_token = tokenizer.eos_token

model = PeftModel.from_pretrained(model, model_repo)

```

## RESULTS
```python
id2c = {0: 'neg', 1:'neutral', 2: 'pos'}


text_list = ["Não gostei da programação da TV hoje, o programa BBB foi muito ruim!!", "Gostei muito do jogo do corinthians hoje", "Que prova dificil", "Baptista é um professor muito legal"]


for text in text_list:
  inputs = tokenizer.encode(text, return_tensors="pt")
  logits = model(inputs).logits


  predictions = torch.argmax(logits)
  print(text + " - " + id2c[predictions.tolist()])
  ## RESULTS:
  Não gostei da programação da TV hoje, o programa BBB foi muito ruim!! - neg
  Gostei muito do jogo do corinthians hoje - pos
  Que prova dificil - neg
  Baptista é um professor muito legal - pos
  
```