Update README.md
Browse files
README.md
CHANGED
|
@@ -32,23 +32,20 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
| 32 |
import torch
|
| 33 |
|
| 34 |
# Load the model and tokenizer
|
| 35 |
-
model_path = "microsoft/
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 37 |
-
model = AutoModelForCausalLM.from_pretrained(model_path,
|
| 38 |
|
| 39 |
# Create a conversation
|
| 40 |
messages = [{"role": "system", "content": "You are a user who wants to implement a special type of sequence. The sequence sums up the two previous numbers in the sequence and adds 1 to the result. The first two numbers in the sequence are 1 and 1."}]
|
| 41 |
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
|
| 46 |
-
print(response) # This can output: “Create a sequence that always starts at 1, 1, and then sums the two previous numbers in the sequence, adds 1 to the result.”
|
| 47 |
-
|
| 48 |
-
# Example 2: Generate response while ignoring the <|endconversation|> token
|
| 49 |
|
| 50 |
end_conv_token = "<|endconversation|>"
|
| 51 |
end_conv_token_id = tokenizer.encode(end_conv_token, add_special_tokens=False)
|
|
|
|
| 52 |
outputs = model.generate(
|
| 53 |
input_ids=inputs,
|
| 54 |
do_sample=True,
|
|
|
|
| 32 |
import torch
|
| 33 |
|
| 34 |
# Load the model and tokenizer
|
| 35 |
+
model_path = "microsoft/userlm-8b"
|
| 36 |
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
| 37 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True).to("cuda")
|
| 38 |
|
| 39 |
# Create a conversation
|
| 40 |
messages = [{"role": "system", "content": "You are a user who wants to implement a special type of sequence. The sequence sums up the two previous numbers in the sequence and adds 1 to the result. The first two numbers in the sequence are 1 and 1."}]
|
| 41 |
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda")
|
| 42 |
|
| 43 |
+
end_token = "<|eot_id|>"
|
| 44 |
+
end_token_id = tokenizer.encode(end_token, add_special_tokens=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
end_conv_token = "<|endconversation|>"
|
| 47 |
end_conv_token_id = tokenizer.encode(end_conv_token, add_special_tokens=False)
|
| 48 |
+
|
| 49 |
outputs = model.generate(
|
| 50 |
input_ids=inputs,
|
| 51 |
do_sample=True,
|