Views
No views yet
1from transformers import Qwen2ForCausalLM
2from transformers import LlamaTokenizerFast
3
4tokenizer = LlamaTokenizerFast.from_pretrained("wencan25/tinystories_qwen2")
5
6input_texts = ["Once upon a time"]
7
8inputs = tokenizer(
9 input_texts,
10 add_special_tokens=False,
11 truncation=False,
12 return_tensors="pt",
13)["input_ids"]
14
15model = Qwen2ForCausalLM.from_pretrained("wencan25/tinystories_qwen2")
16
17outputs = model.generate(
18 inputs, max_new_tokens=256, eos_token_id=0, do_sample=True, num_beams=5
19)
20
21output_texts = tokenizer.decode(outputs[0])
22
23print(output_texts)1Once upon a time, there was a little boy named Tim. Tim loved to play outside with his friends. They would run, jump, and laugh all day long.
2One day, Tim and his friends were playing in the park. They were having so much fun! But then, something unexpected happened. A big wind came and blew Tim's hat away. Tim was sad and didn't know what to do.
3Tim's mom saw him and said, "Don't worry, Tim. We will find your hat." They looked everywhere for the hat. Finally, they found it under a big tree. Tim was so happy and thanked his mom. From that day on, Tim and his friends played together every day, and they all became the best of friends.