Update README.md
Browse files
README.md
CHANGED
|
@@ -25,6 +25,47 @@ SnakModel comes as an instruction-tuned, and a base version. In addition, each m
|
|
| 25 |
|
| 26 |
Text only, with instructions following the `[INST] {instruction} [/INST]` template.
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
**Output**
|
| 29 |
|
| 30 |
Text only.
|
|
|
|
| 25 |
|
| 26 |
Text only, with instructions following the `[INST] {instruction} [/INST]` template.
|
| 27 |
|
| 28 |
+
Quickstart:
|
| 29 |
+
|
| 30 |
+
Here is a code snippet with apply_chat_template to show you how to load the tokenizer and model and how to generate contents.
|
| 31 |
+
|
| 32 |
+
```
|
| 33 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 34 |
+
|
| 35 |
+
model_name = "NLPnorth/snakmodel-7b-instruct"
|
| 36 |
+
|
| 37 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 38 |
+
model_name,
|
| 39 |
+
torch_dtype="auto",
|
| 40 |
+
device_map="auto"
|
| 41 |
+
)
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 43 |
+
|
| 44 |
+
prompt = "Hvor ligger IT Universitet?"
|
| 45 |
+
messages = [
|
| 46 |
+
{"role": "system", "content": "Du er Snakmodel, skabt af IT-Universitetet i København. Du er en hjælpsom assistent."},
|
| 47 |
+
{"role": "user", "content": prompt}
|
| 48 |
+
]
|
| 49 |
+
text = tokenizer.apply_chat_template(
|
| 50 |
+
messages,
|
| 51 |
+
tokenize=False,
|
| 52 |
+
add_generation_prompt=True
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 56 |
+
|
| 57 |
+
generated_ids = model.generate(
|
| 58 |
+
**model_inputs,
|
| 59 |
+
max_new_tokens=20
|
| 60 |
+
)
|
| 61 |
+
generated_ids = [
|
| 62 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 66 |
+
print(response)
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
**Output**
|
| 70 |
|
| 71 |
Text only.
|