Update README.md
Browse files
README.md
CHANGED
|
@@ -14,4 +14,40 @@ tags:
|
|
| 14 |
|
| 15 |
# Tiny Qwen2 Language Model on TinyStories
|
| 16 |
|
| 17 |
-
This project contains a pre-trained compact Qwen2-based language model on the [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) dataset. More details are provided by [TinyLM](https://github.com/wencan25/TinyLM).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Tiny Qwen2 Language Model on TinyStories
|
| 16 |
|
| 17 |
+
This project contains a pre-trained compact Qwen2-based language model on the [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) dataset. More details are provided by [TinyLM](https://github.com/wencan25/TinyLM).
|
| 18 |
+
|
| 19 |
+
## Example Usage
|
| 20 |
+
|
| 21 |
+
```python
|
| 22 |
+
from transformers import Qwen2ForCausalLM
|
| 23 |
+
from transformers import LlamaTokenizerFast
|
| 24 |
+
|
| 25 |
+
tokenizer = LlamaTokenizerFast.from_pretrained("wencan25/tinystories_qwen2")
|
| 26 |
+
|
| 27 |
+
input_texts = ["Once upon a time"]
|
| 28 |
+
|
| 29 |
+
inputs = tokenizer(
|
| 30 |
+
input_texts,
|
| 31 |
+
add_special_tokens=False,
|
| 32 |
+
truncation=False,
|
| 33 |
+
return_tensors="pt",
|
| 34 |
+
)["input_ids"]
|
| 35 |
+
|
| 36 |
+
model = Qwen2ForCausalLM.from_pretrained("wencan25/tinystories_qwen2")
|
| 37 |
+
|
| 38 |
+
outputs = model.generate(
|
| 39 |
+
inputs, max_new_tokens=256, eos_token_id=0, do_sample=True, num_beams=5
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
output_texts = tokenizer.decode(outputs[0])
|
| 43 |
+
|
| 44 |
+
print(output_texts)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
## Example Output
|
| 48 |
+
|
| 49 |
+
```text
|
| 50 |
+
Once 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.
|
| 51 |
+
One 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.
|
| 52 |
+
Tim'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.
|
| 53 |
+
```
|