Fixed code snippet to use apply_chat_template
Browse files
README.md
CHANGED
|
@@ -68,13 +68,20 @@ model, tokenizer = FastLanguageModel.from_pretrained(
|
|
| 68 |
)
|
| 69 |
FastLanguageModel.for_inference(model)
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
inputs = tokenizer(
|
| 72 |
-
[
|
| 73 |
return_tensors = "pt"
|
| 74 |
).to("cuda")
|
| 75 |
|
| 76 |
outputs = model.generate(**inputs, max_new_tokens = 256)
|
| 77 |
-
|
|
|
|
| 78 |
```
|
| 79 |
|
| 80 |
### Using Standard Transformers
|
|
|
|
| 68 |
)
|
| 69 |
FastLanguageModel.for_inference(model)
|
| 70 |
|
| 71 |
+
messages = [
|
| 72 |
+
{"role": "system", "content": "You are Chat2Find-CPT, a helpful assistant."},
|
| 73 |
+
{"role": "user", "content": "ශ්රී ලංකාව ගැන කෙටි විස්තරයක්:"}
|
| 74 |
+
]
|
| 75 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 76 |
+
|
| 77 |
inputs = tokenizer(
|
| 78 |
+
text=[prompt],
|
| 79 |
return_tensors = "pt"
|
| 80 |
).to("cuda")
|
| 81 |
|
| 82 |
outputs = model.generate(**inputs, max_new_tokens = 256)
|
| 83 |
+
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 84 |
+
print(response)
|
| 85 |
```
|
| 86 |
|
| 87 |
### Using Standard Transformers
|