File size: 10,977 Bytes
46004f1
fd7dee4
 
095ccee
 
fd7dee4
 
 
 
 
095ccee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46004f1
 
fd7dee4
46004f1
fd7dee4
8f9e9c8
fd7dee4
46004f1
 
fd7dee4
e8f8fc9
46004f1
 
fd7dee4
46004f1
fd7dee4
 
 
46004f1
fd7dee4
 
 
 
46004f1
fd7dee4
 
 
 
46004f1
fd7dee4
46004f1
fd7dee4
 
46004f1
fd7dee4
 
 
46004f1
fd7dee4
46004f1
fd7dee4
 
46004f1
52e94d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd7dee4
46004f1
52e94d6
fd7dee4
52e94d6
 
 
 
 
 
 
 
46004f1
 
52e94d6
 
 
 
 
 
 
fd7dee4
46004f1
8704641
 
 
 
fd7dee4
46004f1
fd7dee4
 
 
 
 
 
 
 
 
46004f1
fd7dee4
 
 
 
 
46004f1
fd7dee4
46004f1
095ccee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dadca9
 
 
 
 
 
 
 
 
 
 
 
 
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
---
language:
- pt
license: apache-2.0
library_name: transformers
tags:
- portuguese
- math
- mathematics
- matematica
base_model: rhaymison/Mistral-portuguese-luana-7b
datasets:
- rhaymison/orca-math-portuguese-64k
pipeline_tag: text-generation
model-index:
- name: Mistral-portuguese-luana-7b-Mathematics
  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: 56.68
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 45.9
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 37.9
      name: accuracy
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 89.36
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 74.78
      name: pearson
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 74.87
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 76.39
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      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: 67.46
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      name: Open Portuguese LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: tweetSentBR
      type: eduagarcia/tweetsentbr_fewshot
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: f1_macro
      value: 49.03
      name: f1-macro
    source:
      url: https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard?query=rhaymison/Mistral-portuguese-luana-7b-Mathematics
      name: Open Portuguese LLM Leaderboard
---

# Mistral-portuguese-luana-7b-Mathematics

<p align="center">
  <img src="https://raw.githubusercontent.com/rhaymisonbetini/huggphotos/main/luana-math.webp"  width="50%" style="margin-left:'auto' margin-right:'auto' display:'block'"/>
</p>


Luana Mathematics is a tuned model of the Luana-7b based on the Mistral 7b architecture.
This Model has been fine-tuned with 64k math problems and solutions derived from Microsoft's Orca-Math.


# How to use

You can use the model in its normal form up to 4-bit quantization. Below we will use both approaches.
Remember that verbs are important in your prompt. Tell your model how to act or behave so that you can guide them along the path of their response. 
Important points like these help models (even smaller models like 7b) to perform much better.

```python
!pip install -q -U transformers
!pip install -q -U accelerate
!pip install -q -U bitsandbytes

from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
model = AutoModelForCausalLM.from_pretrained("rhaymison/Mistral-portuguese-luana-7b-Mathematics", device_map= {"": 0})
tokenizer = AutoTokenizer.from_pretrained("rhaymison/Mistral-portuguese-luana-7b-Mathematics")
model.eval()

```

You can use with Pipeline but in this example i will use such as Streaming
```python

inputs = tokenizer([f"""<s>[INST] Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
### instrução: Se eu emprestei 100 reais para o meu irmão para que ele me pague em 3 vezes. O juros do empréstimo é 5% do valor do emprestimo por mes. Quanto meu irmão terá que me pagar no total?
[/INST]"""], return_tensors="pt")

inputs.to(model.device)

streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
_ = model.generate(**inputs, streamer=streamer, max_new_tokens=200)


#Para calcular o valor total que seu irmão terá que pagar, precisamos primeiro calcular o interesse do empréstimo e depois adicioná -lo ao valor principal.
#O interesse do empréstimo é de 5% do valor do empréstimo por mês.Então, para cada mês, o interesse será:
#5% de 100 reais = 0,05 * 100 = 5 reais
#Como o empréstimo é devolvido em 3 vezes, o interesse total será:
#5 reais/mês * 3 meses = 15 reais
#Agora, adicionamos o interesse ao valor principal para encontrar o valor total que seu irmão terá que pagar:
#100 reais (valor principal) + 15 reais (juros) = 115 reais
#Portanto, seu irmão terá que pagar 115 reais no total. 
```
```python
inputs = tokenizer([f"""<s>[INST] Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
### instrução: João Esta pilotando sua bicicleta a uma velocidade de 20 km por hora. Se João esta fazendo uma Viagem da cidade de Venda nova a cidade de Independencia que possuem a distancia entre si de 320km.
Quanto tempo João vai demorar para ir de uma cidade a outra?
[/INST]"""], return_tensors="pt")

inputs.to(model.device)

streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
_ = model.generate(**inputs, streamer=streamer, max_new_tokens=200)


#Para descobrir quanto tempo levará João para viajar da cidade de venda nova para a cidade de Independência, precisamos dividir a distância total que ele precisa percorrer pela velocidade em que ele está andando.
#Distância total = 320 km
#Velocidade de João = 20 km/h
#Tempo = distância / velocidade
#Tempo = 320 km / 20 km / h
#Tempo = 16 horas
#Então, levará João 16 horas para viajar da cidade de venda nova para a cidade de Independência.
```


```python
inputs = tokenizer([f"""<s>[INST] Abaixo está uma instrução que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que complete adequadamente o pedido.
### instrução: Qual a area de um triangulo equilatero de 4 cm de base por 2 de altura ?
[/INST]"""], return_tensors="pt")

inputs.to(model.device)

streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
_ = model.generate(**inputs, streamer=streamer, max_new_tokens=200)


#A área de um triângulo equilátero é dada pela fórmula:
#Área = (1/2) * base * altura
#Dado que a base é de 4 cm e a altura é de 2 cm, podemos conectar esses valores à fórmula:
#Área = (1/2) * 4 cm * 2 cm
#Área = (1/2) * 8 cm²
#Área = 4 cm²
#Portanto, a área do triângulo equilátero é de 4 centímetros quadrados.
```

If you are having a memory problem such as "CUDA Out of memory", you should use 4-bit or 8-bit quantization.
For the complete model in colab you will need the A100.
If you want to use 4bits or 8bits, T4 or L4 will already solve the problem.

# 4bits

```python
from transformers import BitsAndBytesConfig
import torch
nb_4bit_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_use_double_quant=True
)

model = AutoModelForCausalLM.from_pretrained(
    base_model,
    quantization_config=bnb_config,
    device_map={"": 0}
)

```

# Open Portuguese LLM Leaderboard Evaluation Results  

Detailed results can be found [here](https://huggingface.co/datasets/eduagarcia-temp/llm_pt_leaderboard_raw_results/tree/main/rhaymison/Mistral-portuguese-luana-7b-Mathematics) and on the [🚀 Open Portuguese LLM Leaderboard](https://huggingface.co/spaces/eduagarcia/open_pt_llm_leaderboard)

|          Metric          | Value  |
|--------------------------|--------|
|Average                   |**63.6**|
|ENEM Challenge (No Images)|   56.68|
|BLUEX (No Images)         |   45.90|
|OAB Exams                 |   37.90|
|Assin2 RTE                |   89.36|
|Assin2 STS                |   74.78|
|FaQuAD NLI                |   74.87|
|HateBR Binary             |   76.39|
|PT Hate Speech Binary     |   67.46|
|tweetSentBR               |   49.03|

### Comments

Any idea, help or report will always be welcome.

email: rhaymisoncristian@gmail.com

 <div style="display:flex; flex-direction:row; justify-content:left">
    <a href="https://www.linkedin.com/in/heleno-betini-2b3016175/" target="_blank">
    <img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white">
  </a>
  <a href="https://github.com/rhaymisonbetini" target="_blank">
    <img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white">
  </a>