Update README.md
Browse files
README.md
CHANGED
@@ -39,7 +39,32 @@ base_model: TinyLlama/TinyLlama-1.1B-Chat-v0.6
|
|
39 |
|
40 |
### Direct Use
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
[More Information Needed]
|
45 |
|
|
|
39 |
|
40 |
### Direct Use
|
41 |
|
42 |
+
# Install transformers from source - only needed for versions <= v4.34
|
43 |
+
# pip install git+https://github.com/huggingface/transformers.git
|
44 |
+
# pip install accelerate
|
45 |
+
|
46 |
+
import torch
|
47 |
+
from transformers import pipeline
|
48 |
+
|
49 |
+
pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.bfloat16, device_map="auto")
|
50 |
+
|
51 |
+
# We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
|
52 |
+
messages = [
|
53 |
+
{
|
54 |
+
"role": "system",
|
55 |
+
"content": "You are a friendly chatbot who always responds in the style of a pirate",
|
56 |
+
},
|
57 |
+
{"role": "user", "content": "How many helicopters can a human eat in one sitting?"},
|
58 |
+
]
|
59 |
+
prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
60 |
+
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
61 |
+
print(outputs[0]["generated_text"])
|
62 |
+
# <|system|>
|
63 |
+
# You are a friendly chatbot who always responds in the style of a pirate.</s>
|
64 |
+
# <|user|>
|
65 |
+
# How many helicopters can a human eat in one sitting?</s>
|
66 |
+
# <|assistant|>
|
67 |
+
# ...
|
68 |
|
69 |
[More Information Needed]
|
70 |
|