Upload README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
| 1 |
---
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
|
| 3 |
+
datasets:
|
| 4 |
+
- dominguesm/Canarim-Instruct-PTBR-Dataset
|
| 5 |
+
library_name: adapter-transformers
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
language:
|
| 8 |
+
- pt
|
| 9 |
+
- en
|
| 10 |
+
thumbnail: https://blog.cobasi.com.br/wp-content/uploads/2022/08/AdobeStock_461738919.webp
|
| 11 |
---
|
| 12 |
+
<!-- header start -->
|
| 13 |
+
<div style="width: 100%;">
|
| 14 |
+
<img src="https://blog.cobasi.com.br/wp-content/uploads/2022/08/AdobeStock_461738919.webp" alt="Caramelo" style="width: 100%; min-width: 400px; display: block; margin: auto;">
|
| 15 |
+
</div>
|
| 16 |
+
|
| 17 |
+
<!-- header end -->
|
| 18 |
+
|
| 19 |
+
# Caramelinho
|
| 20 |
+
|
| 21 |
+
## Adapter Description
|
| 22 |
+
This adapter was created with the [PEFT](https://github.com/huggingface/peft) library and allowed the base model **Falcon-7b** to be fine-tuned on the [Canarim](https://huggingface.co/datasets/dominguesm/Canarim-Instruct-PTBR-Dataset) by using the method **QLoRA**.
|
| 23 |
+
|
| 24 |
+
## Model description
|
| 25 |
+
|
| 26 |
+
[Falcon 7B](https://huggingface.co/tiiuae/falcon-7b)
|
| 27 |
+
|
| 28 |
+
## Intended uses & limitations
|
| 29 |
+
|
| 30 |
+
TBA
|
| 31 |
+
|
| 32 |
+
## Training and evaluation data
|
| 33 |
+
|
| 34 |
+
TBA
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
### Training results
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
### How to use
|
| 41 |
+
```py
|
| 42 |
+
import torch
|
| 43 |
+
from peft import PeftModel, PeftConfig
|
| 44 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, GenerationConfig
|
| 45 |
+
|
| 46 |
+
peft_model_id = "Bruno/Caramelinho"
|
| 47 |
+
|
| 48 |
+
config = PeftConfig.from_pretrained(peft_model_id)
|
| 49 |
+
bnb_config = BitsAndBytesConfig(
|
| 50 |
+
load_in_4bit=True,
|
| 51 |
+
bnb_4bit_quant_type="nf4",
|
| 52 |
+
bnb_4bit_compute_dtype=torch.float16,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
| 56 |
+
|
| 57 |
+
model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path,
|
| 58 |
+
return_dict=True,
|
| 59 |
+
quantization_config=bnb_config,
|
| 60 |
+
trust_remote_code=True,
|
| 61 |
+
device_map={"": 0})
|
| 62 |
+
prompt_input = "Abaixo está uma declaração que descreve uma tarefa, juntamente com uma entrada que fornece mais contexto. Escreva uma resposta que conclua corretamente a solicitação.\n\n ### Instrução:\n{instruction}\n\n### Entrada:\n{input}\n\n### Resposta:\n"
|
| 63 |
+
prompt_no_input = "Abaixo está uma instrução que descreve uma tarefa. Escreva uma resposta que conclua corretamente a solicitação.\n\n### Instrução:\n{instruction}\n\n### Resposta:\n"
|
| 64 |
+
|
| 65 |
+
def create_prompt(instruction, input=None):
|
| 66 |
+
if input:
|
| 67 |
+
return prompt_input.format(instruction=instruction, input=input)
|
| 68 |
+
else:
|
| 69 |
+
return prompt_no_input.format(instruction=instruction)
|
| 70 |
+
|
| 71 |
+
def generate(
|
| 72 |
+
instruction,
|
| 73 |
+
input=None,
|
| 74 |
+
max_new_tokens=128,
|
| 75 |
+
temperature=0.1,
|
| 76 |
+
top_p=0.75,
|
| 77 |
+
top_k=40,
|
| 78 |
+
num_beams=4,
|
| 79 |
+
repetition_penalty=1.7,
|
| 80 |
+
max_length=512
|
| 81 |
+
):
|
| 82 |
+
prompt = create_prompt(instruction, input)
|
| 83 |
+
inputs = tokenizer.encode_plus(prompt, return_tensors="pt", truncation=True, max_length=max_length, padding="longest")
|
| 84 |
+
input_ids = inputs["input_ids"].to("cuda")
|
| 85 |
+
attention_mask = inputs["attention_mask"].to("cuda")
|
| 86 |
+
|
| 87 |
+
generation_output = model.generate(
|
| 88 |
+
input_ids=input_ids,
|
| 89 |
+
attention_mask=attention_mask,
|
| 90 |
+
max_length=max_length,
|
| 91 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 92 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 93 |
+
temperature=temperature,
|
| 94 |
+
top_p=top_p,
|
| 95 |
+
top_k=top_k,
|
| 96 |
+
num_beams=num_beams,
|
| 97 |
+
repetition_penalty=repetition_penalty,
|
| 98 |
+
length_penalty=0.8,
|
| 99 |
+
early_stopping=True,
|
| 100 |
+
output_scores=True,
|
| 101 |
+
return_dict_in_generate=True
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
output = tokenizer.decode(generation_output.sequences[0], skip_special_tokens=True)
|
| 105 |
+
return output.split("### Resposta:")[1]
|
| 106 |
+
|
| 107 |
+
instruction = "Descrever como funcionam os computadores quânticos."
|
| 108 |
+
print("Instrução:", instruction)
|
| 109 |
+
print("Resposta:", generate(instruction))
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
### Saída
|
| 114 |
+
|
| 115 |
+
Instrução: Descrever como funcionam os computadores quânticos.
|
| 116 |
+
Resposta:
|
| 117 |
+
Os computadores quânticos são um tipo de computador cuja arquitetura é baseada na mecânica quântica. Os computadores quânticos são capazes de realizar operações matemáticas complexas em um curto espaço de tempo.
|
| 118 |
+
|
| 119 |
+
### Framework versions
|
| 120 |
+
|
| 121 |
+
- Transformers 4.30.0.dev0
|
| 122 |
+
- Pytorch 2.0.1+cu118
|
| 123 |
+
- Datasets 2.12.0
|
| 124 |
+
- Tokenizers 0.13.3
|