Mistral-portuguese-luana-7b-Mathematics

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.

!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


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. 
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.
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

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 and on the πŸš€ Open Portuguese 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: [email protected]

Downloads last month
19
Safetensors
Model size
7.24B params
Tensor type
BF16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for rhaymison/Mistral-portuguese-luana-7b-Mathematics

Finetuned
(7)
this model
Quantizations
2 models

Dataset used to train rhaymison/Mistral-portuguese-luana-7b-Mathematics

Space using rhaymison/Mistral-portuguese-luana-7b-Mathematics 1

Evaluation results