File size: 7,903 Bytes
5068a63
 
 
4dc8fd2
5068a63
4dc8fd2
 
 
 
 
 
5068a63
 
4dc8fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5068a63
 
 
 
 
 
 
 
61e1a2b
 
7ab9c40
61e1a2b
 
 
 
 
 
 
c241f68
61e1a2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e66ebf3
 
4dc8fd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
---
language:
- pt
license: llama2
library_name: transformers
tags:
- text-generation
- pytorch
- LLM
- Portuguese
- Llama 2
datasets:
- dominguesm/CC-MAIN-2023-23
inference: false
pipeline_tag: text-generation
model-index:
- name: Canarim-7B-Instruct
  results:
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: ENEM Challenge (No Images)
      type: eduagarcia/enem_challenge
      split: train
      args:
        num_few_shot: 3
    metrics:
    - type: acc
      value: 27.5
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: BLUEX (No Images)
      type: eduagarcia-temp/BLUEX_without_images
      split: train
      args:
        num_few_shot: 3
    metrics:
    - type: acc
      value: 26.15
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: OAB Exams
      type: eduagarcia/oab_exams
      split: train
      args:
        num_few_shot: 3
    metrics:
    - type: acc
      value: 29.93
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: Assin2 RTE
      type: assin2
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: f1_macro
      value: 75.74
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: Assin2 STS
      type: eduagarcia/portuguese_benchmark
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: pearson
      value: 12.08
      name: pearson
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: FaQuAD NLI
      type: ruanchaves/faquad-nli
      split: test
      args:
        num_few_shot: 15
    metrics:
    - type: f1_macro
      value: 43.92
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: HateBR Binary
      type: ruanchaves/hatebr
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 79.57
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: PT Hate Speech Binary
      type: hate_speech_portuguese
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 64.01
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: tweetSentBR
      type: eduagarcia-temp/tweetsentbr
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 66.0
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=dominguesm/Canarim-7B-Instruct
      name: Open Portuguese LLM Leaderboard
---

<p align="center">
  <img width="250" alt="Camarim Logo" src="https://raw.githubusercontent.com/DominguesM/Canarim-Instruct-PTBR/main/assets/canarim.png">
</p>

<hr>

# Canarim-7B-Instruct

Canarim-7B-Instruct is a 7 billion parameter language model, initialized from the [Canarim-7B](https://huggingface.co/dominguesm/canarim-7b) model and trained on a variety of publicly available instruction datasets.

## Usage

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

model_id = "dominguesm/Canarim-7B-Instruct"

tokenizer = AutoTokenizer.from_pretrained(model_id)
pipe = pipeline(
    "text-generation",
    model=model_id,
    torch_dtype=torch.float16,
    device_map="auto",
)


def make_prompt(instruction, input=None):
    if input:
        return f"""Abaixo está uma instrução que descreve uma tarefa, emparelhada com uma entrada que fornece mais contexto. Escreva uma resposta que conclua adequadamente a solicitação.

### Instruções:
{instruction}

### Entrada:
{input}

### Resposta:"""
    else:
        return f"""Abaixo está uma instrução que descreve uma tarefa. Escreva uma resposta que conclua adequadamente a solicitação.

### Instruções:
{instruction}

### Resposta:"""

instruction = "Faça um resumo conciso do seguinte texto."
context = """
No início da obra, o narrador Bentinho explica como escolheu o título para o seu livro. Assim, ele conta que conheceu um poeta em uma viagem de trem. O jovem recitou alguns versos, mas Bentinho, já velho, fechou os olhos algumas vezes. O poeta, então, achou que ele estava cochilando e, ofendido, lhe chamou de Dom Casmurro.

Em seguida, o narrador inicia a narrativa de suas memórias, que começa quando ele tem 15 anos. Nessa época, Capitu, uma jovem de 14 anos, é sua vizinha. Os adolescentes têm uma forte amizade, o que incomoda o agregado da família, o amante de superlativos José Dias.

Desconfiado da relação entre os jovens, ele sugere à D. Glória, mãe de Bentinho, que já é hora de enviar o rapaz para o seminário. Isso porque, quando o menino nasceu, sua mãe fez uma promessa de que ele seria padre. Dessa forma, se apresenta um obstáculo ao amor do jovem casal, o que, enganosamente, faz parecer que o livro é um romance romântico.
"""

prompt = make_prompt(question)

sequences = pipe(
   prompt,
   do_sample=True,
   num_return_sequences=1,
   eos_token_id=tokenizer.eos_token_id,
   max_length=2048,
   temperature=0.9,
   top_p=0.6,
   repetition_penalty=1.15
)
```

### Model Result

```
O trabalho retrata as memórias de Bentinho, um jovem de 15 anos. Ele conta 
sobre sua infância na casa de seus pais, onde vive com sua mãe, a dona 
Glória, e sua governanta, a governanta Josefa. No entanto, no outono de 
1860, sua vida mudará drasticamente. Durante essa temporada, ele conhece 
Capitu, uma moça de 14 anos, que se tornará sua companheira por muitos anos.
```

**NOTE**: README under construction
# [Open Portuguese LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard)
Detailed results can be found [here](https://huggingface.co/datasets/eduagarcia-temp/llm_pt_leaderboard_raw_results/tree/main/dominguesm/Canarim-7B-Instruct)

|          Metric          |  Value  |
|--------------------------|---------|
|Average                   |**47.21**|
|ENEM Challenge (No Images)|    27.50|
|BLUEX (No Images)         |    26.15|
|OAB Exams                 |    29.93|
|Assin2 RTE                |    75.74|
|Assin2 STS                |    12.08|
|FaQuAD NLI                |    43.92|
|HateBR Binary             |    79.57|
|PT Hate Speech Binary     |    64.01|
|tweetSentBR               |       66|