File size: 4,888 Bytes
bf7ce5b |
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 |
---
datasets:
- Local
license: bigscience-bloom-rail-1.0
language:
- id
pipeline_tag: text-generation
duplicated_from: yodi/karina
---
# Table of Contents
1. [Model Summary](#model-summary)
2. [Use](#use)
4. [Training](#training)
# Model Summary
> We present KARINA, finetuned from BLOOMZ bigscience/bloomz-3b, a family of models capable of following human instructions in dozens of languages zero-shot. We finetune BLOOMZ pretrained multilingual language models on our crosslingual task mixture (xP3) and find the resulting models capable of crosslingual generalization to unseen tasks & languages.
# Use
## Intended use
We recommend using the model to perform tasks expressed in natural language. For example, given the prompt "*prompt = f"Given the question:\n{{ siapa kamu? }}\n---\nAnswer:\n"*", the model will most likely answer "*Saya Karina. Ada yang bisa saya bantu?*".
## How to use
### CPU
<details>
<summary> Click to expand </summary>
```python
# pip install -q transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL_NAME = "yodi/karina"
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
inputs = tokenizer.encode("Given the question:\n{{ siapa kamu? }}\n---\nAnswer:\n", return_tensors="pt")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
```
</details>
### GPU in 4 bit
<details>
<summary> Click to expand </summary>
```python
# pip install -q transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import pipeline
MODEL_NAME = "yodi/karina"
model_4bit = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="cuda:1", load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
prompt = f"Given the question:\n{{ siapa kamu? }}\n---\nAnswer:\n"
generator = pipeline('text-generation',
model=model_4bit,
tokenizer=tokenizer,
do_sample=False)
result = generator(prompt, max_length=256)
print(result)
```
</details>
### GPU in 8bit
<details>
<summary> Click to expand </summary>
```python
# pip install -q transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import pipeline
MODEL_NAME = "yodi/karina"
model_4bit = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="cuda:1", load_in_8bit=True)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
prompt = f"Given the question:\n{{ siapa kamu? }}\n---\nAnswer:\n"
generator = pipeline('text-generation',
model=model_4bit,
tokenizer=tokenizer,
do_sample=False)
result = generator(prompt, max_length=256)
print(result)
```
</details>
```
[{'generated_text': 'Given the question:\n{ siapa kamu? }\n---\nAnswer:\nSaya Karina, asisten virtual siap membantu seputar estimasi harga atau pertanyaan lain'}]
```
### Infer in Local with Gradio
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import pipeline
import re
import gradio as gr
MODEL_NAME = "yodi/karina"
model_4bit = AutoModelForCausalLM.from_pretrained(MODEL_NAME, device_map="cuda:1", load_in_4bit=True)
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
prompt = f"Given the question:\n{{ siapa kamu? }}\n---\nAnswer:\n"
generator = pipeline('text-generation',
model=model_4bit,
tokenizer=tokenizer,
do_sample=False)
def preprocess(text):
return f"Given the question:\n{{ {text} }}\n---\nAnswer:\n"
def generate(text):
preprocess_result = preprocess(text)
result = generator(preprocess_result, max_length=256)
output = re.split(r'\Given the question:|Answer:|Answer #|Title:',result[0]['generated_text'])[2]
return output
with gr.Blocks() as demo:
input_text = gr.Textbox(label="Input", lines=1)
button = gr.Button("Submit")
output_text = gr.Textbox(lines=6, label="Output")
button.click(generate, inputs=[input_text], outputs=output_text)
demo.launch(enable_queue=True, debug=True)
```
And open the gradio url from browser.
## Training procedure
The following `bitsandbytes` quantization config was used during training:
- load_in_8bit: False
- load_in_4bit: True
- llm_int8_threshold: 6.0
- llm_int8_skip_modules: None
- llm_int8_enable_fp32_cpu_offload: False
- llm_int8_has_fp16_weight: False
- bnb_4bit_quant_type: nf4
- bnb_4bit_use_double_quant: True
- bnb_4bit_compute_dtype: float16
### Framework versions
- PEFT 0.5.0.dev0
<!-- Necessary for whitespace -->
###
# Limitations
**Prompt Engineering:** The performance may vary depending on the prompt and its following BLOOMZ models.
# Training
## Model
- **Architecture:** Same as [bloom](https://huggingface.co/bigscience/bloom), also refer to the `config.json` file
|