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