Update README.md with new model card content
Browse files
README.md
CHANGED
@@ -2,24 +2,164 @@
|
|
2 |
library_name: keras-hub
|
3 |
pipeline_tag: text-generation
|
4 |
---
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
*
|
13 |
-
*
|
14 |
-
*
|
15 |
-
*
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
library_name: keras-hub
|
3 |
pipeline_tag: text-generation
|
4 |
---
|
5 |
+
### Model Overview
|
6 |
+
# Model Summary
|
7 |
+
|
8 |
+
Qwen2.5 is the latest series of Qwen large language models. For Qwen2.5, the Qwen team released a number of base language models and instruction-tuned language models ranging from 0.5 to 72 billion parameters.
|
9 |
+
|
10 |
+
## Qwen2.5 brings the following improvements upon Qwen2:
|
11 |
+
|
12 |
+
* Significantly more knowledge and has greatly improved capabilities in coding and mathematics, thanks to our specialized expert models in these domains.
|
13 |
+
* Significant improvements in instruction following, generating long texts (over 8K tokens), understanding structured data (e.g, tables), and generating structured outputs especially JSON. More resilient to the diversity of system prompts, enhancing role-play implementation and condition-setting for chatbots.
|
14 |
+
* Long-context Support up to 128K tokens and can generate up to 8K tokens.
|
15 |
+
* Multilingual support for over 29 languages, including Chinese, English, French, Spanish, Portuguese, German, Italian, Russian, Japanese, Korean, Vietnamese, Thai, Arabic, and more.
|
16 |
+
|
17 |
+
|
18 |
+
For more details, please refer to Qwen [Blog](https://qwenlm.github.io/blog/qwen2.5/), [GitHub](https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/models/qwen), and [Documentation](https://qwen.readthedocs.io/en/latest/).
|
19 |
+
|
20 |
+
Weights are released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE) . Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).
|
21 |
+
|
22 |
+
## Links
|
23 |
+
|
24 |
+
* [Qwen 2.5 Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/qwen-quickstart-notebook)
|
25 |
+
* [Qwen 2.5 API Documentation](https://keras.io/keras_hub/api/models/qwen/)
|
26 |
+
* [Qwen 2.5 Model Card](https://qwenlm.github.io/blog/qwen2.5/)
|
27 |
+
* [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
|
28 |
+
* [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
|
29 |
+
|
30 |
+
## Installation
|
31 |
+
|
32 |
+
Keras and KerasHub can be installed with:
|
33 |
+
|
34 |
+
```
|
35 |
+
pip install -U -q keras-hub
|
36 |
+
pip install -U -q keras
|
37 |
+
```
|
38 |
+
|
39 |
+
Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.
|
40 |
+
|
41 |
+
## Presets
|
42 |
+
|
43 |
+
The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
|
44 |
+
|
45 |
+
| Preset name | Parameters | Description |
|
46 |
+
|---------------------------------------|------------|--------------------------------------------------------------------------------------------------------------|
|
47 |
+
| qwen2.5_0.5b_en | 0.5B | 24-layer Qwen model with 0.5 billion parameters. |
|
48 |
+
| qwen2.5_3b_en | 3.1B | 36-layer Qwen model with 3.1 billion parameters. |
|
49 |
+
| qwen2.5_7b_en | 7B | 48-layer Qwen model with 7 billion parameters. |
|
50 |
+
| qwen2.5_instruct_0.5b_en | 0.5B | Instruction fine-tuned 24-layer Qwen model with 0.5 billion parameters. |
|
51 |
+
| qwen2.5_instruct_32b_en | 32B | Instruction fine-tuned 64-layer Qwen model with 32 billion parameters. |
|
52 |
+
| qwen2.5_instruct_72b_en | 72B | Instruction fine-tuned 80-layer Qwen model with 72 billion parameters. |
|
53 |
+
|
54 |
+
## Example Usage
|
55 |
+
```Python
|
56 |
+
|
57 |
+
import keras
|
58 |
+
import keras_hub
|
59 |
+
import numpy as np
|
60 |
+
|
61 |
+
# Use generate() to do text generation.
|
62 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("qwen2.5_instruct_32b_en")
|
63 |
+
qwen_lm.generate("I want to say", max_length=30)
|
64 |
+
|
65 |
+
# Generate with batched prompts.
|
66 |
+
qwen_lm.generate(["This is a", "Where are you"], max_length=30)
|
67 |
+
|
68 |
+
# Compile the generate() function with a custom sampler.
|
69 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("qwen2.5_instruct_32b_en")
|
70 |
+
qwen_lm.compile(sampler="greedy")
|
71 |
+
qwen_lm.generate("I want to say", max_length=30)
|
72 |
+
qwen_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
|
73 |
+
qwen_lm.generate("I want to say", max_length=30)
|
74 |
+
|
75 |
+
# Use generate() without preprocessing.
|
76 |
+
# Prompt the model with `15191, 374` (the token ids for `"Who is"`).
|
77 |
+
# Use `"padding_mask"` to indicate values that should not be overridden.
|
78 |
+
prompt = {
|
79 |
+
"token_ids": np.array([[15191, 374, 0, 0, 0]] * 2),
|
80 |
+
"padding_mask": np.array([[1, 1, 0, 0, 0]] * 2),
|
81 |
+
}
|
82 |
+
|
83 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset(
|
84 |
+
"qwen2.5_instruct_32b_en",
|
85 |
+
preprocessor=None,
|
86 |
+
)
|
87 |
+
qwen_lm.generate(prompt)
|
88 |
+
|
89 |
+
# Call fit() on a single batch.
|
90 |
+
features = ["The quick brown fox jumped.", "I forgot my homework."]
|
91 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("qwen2.5_instruct_32b_en")
|
92 |
+
qwen_lm.fit(x=features, batch_size=2)
|
93 |
+
|
94 |
+
# Call fit() without preprocessing.
|
95 |
+
x = {
|
96 |
+
"token_ids": np.array([[1, 2, 3, 4, 5]] * 2),
|
97 |
+
"padding_mask": np.array([[1, 1, 1, 1, 1]] * 2),
|
98 |
+
}
|
99 |
+
y = np.array([[2, 3, 4, 5, 0]] * 2)
|
100 |
+
sw = np.array([[1, 1, 1, 1, 1]] * 2)
|
101 |
+
|
102 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset(
|
103 |
+
"qwen2.5_instruct_32b_en",
|
104 |
+
preprocessor=None,
|
105 |
+
)
|
106 |
+
qwen_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
|
107 |
+
|
108 |
+
```
|
109 |
+
|
110 |
+
## Example Usage with Hugging Face URI
|
111 |
+
|
112 |
+
```Python
|
113 |
+
|
114 |
+
import keras
|
115 |
+
import keras_hub
|
116 |
+
import numpy as np
|
117 |
+
|
118 |
+
# Use generate() to do text generation.
|
119 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("hf://keras/qwen2.5_instruct_32b_en")
|
120 |
+
qwen_lm.generate("I want to say", max_length=30)
|
121 |
+
|
122 |
+
# Generate with batched prompts.
|
123 |
+
qwen_lm.generate(["This is a", "Where are you"], max_length=30)
|
124 |
+
|
125 |
+
# Compile the generate() function with a custom sampler.
|
126 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("hf://keras/qwen2.5_instruct_32b_en")
|
127 |
+
qwen_lm.compile(sampler="greedy")
|
128 |
+
qwen_lm.generate("I want to say", max_length=30)
|
129 |
+
qwen_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
|
130 |
+
qwen_lm.generate("I want to say", max_length=30)
|
131 |
+
|
132 |
+
# Use generate() without preprocessing.
|
133 |
+
# Prompt the model with `15191, 374` (the token ids for `"Who is"`).
|
134 |
+
# Use `"padding_mask"` to indicate values that should not be overridden.
|
135 |
+
prompt = {
|
136 |
+
"token_ids": np.array([[15191, 374, 0, 0, 0]] * 2),
|
137 |
+
"padding_mask": np.array([[1, 1, 0, 0, 0]] * 2),
|
138 |
+
}
|
139 |
+
|
140 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset(
|
141 |
+
"hf://keras/qwen2.5_instruct_32b_en",
|
142 |
+
preprocessor=None,
|
143 |
+
)
|
144 |
+
qwen_lm.generate(prompt)
|
145 |
+
|
146 |
+
# Call fit() on a single batch.
|
147 |
+
features = ["The quick brown fox jumped.", "I forgot my homework."]
|
148 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset("hf://keras/qwen2.5_instruct_32b_en")
|
149 |
+
qwen_lm.fit(x=features, batch_size=2)
|
150 |
+
|
151 |
+
# Call fit() without preprocessing.
|
152 |
+
x = {
|
153 |
+
"token_ids": np.array([[1, 2, 3, 4, 5]] * 2),
|
154 |
+
"padding_mask": np.array([[1, 1, 1, 1, 1]] * 2),
|
155 |
+
}
|
156 |
+
y = np.array([[2, 3, 4, 5, 0]] * 2)
|
157 |
+
sw = np.array([[1, 1, 1, 1, 1]] * 2)
|
158 |
+
|
159 |
+
qwen_lm = keras_hub.models.Qwen2CausalLM.from_preset(
|
160 |
+
"hf://keras/qwen2.5_instruct_32b_en",
|
161 |
+
preprocessor=None,
|
162 |
+
)
|
163 |
+
qwen_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
|
164 |
+
|
165 |
+
```
|