prasadsachin commited on
Commit
efc37d9
·
verified ·
1 Parent(s): 64a0729

Update README.md with new model card content

Browse files
Files changed (1) hide show
  1. README.md +179 -19
README.md CHANGED
@@ -2,22 +2,182 @@
2
  library_name: keras-hub
3
  pipeline_tag: text-generation
4
  ---
5
- This is a [`Mistral` model](https://keras.io/api/keras_hub/models/mistral) uploaded using the KerasHub library and can be used with JAX, TensorFlow, and PyTorch backends.
6
- This model is related to a `CausalLM` task.
7
-
8
- Model config:
9
- * **name:** mistral_backbone_1
10
- * **trainable:** True
11
- * **vocabulary_size:** 32768
12
- * **num_layers:** 32
13
- * **num_query_heads:** 32
14
- * **hidden_dim:** 4096
15
- * **intermediate_dim:** 14336
16
- * **rope_max_wavelength:** 1000000.0
17
- * **rope_scaling_factor:** 1.0
18
- * **num_key_value_heads:** 8
19
- * **sliding_window:** None
20
- * **layer_norm_epsilon:** 1e-05
21
- * **dropout:** 0
22
-
23
- This model card has been generated automatically and should be completed by the model author. See [Model Cards documentation](https://huggingface.co/docs/hub/model-cards) for more information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  library_name: keras-hub
3
  pipeline_tag: text-generation
4
  ---
5
+ ### Model Overview
6
+ Mistral is a set of large language models published by the Mistral AI team. Both pretrained and instruction tuned models are available with 7 billion parameters. See the model card below for benchmarks, data sources, and intended use cases.
7
+
8
+ Both weights and Keras model code is released under the [Apache 2 License](https://github.com/keras-team/keras-hub/blob/master/LICENSE).
9
+
10
+ ## Links
11
+
12
+ * [Mistral 2 Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/mistral-quickstart)
13
+ * [Mistral 2 API Documentation](https://keras.io/api/keras_hub/models/mistral/)
14
+ * [Mistral 2 Model Card](https://huggingface.co/mistralai/Mistral-7B-v0.1)
15
+ * [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)
16
+ * [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)
17
+
18
+ ## Installation
19
+
20
+ Keras and KerasHub can be installed with:
21
+
22
+ ```
23
+ pip install -U -q keras-hub
24
+ pip install -U -q keras
25
+ ```
26
+
27
+ 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.
28
+
29
+ ## Presets
30
+
31
+ The following model checkpoints are provided by the Keras team. Full code examples for each are available below.
32
+
33
+ | Preset name | Parameters | Description |
34
+ |-----------------------|------------|---------------|
35
+ |` mistral_7b_en` | 7.24B | 7B base model |
36
+ | `mistral_instruct_7b_en ` | 7.24B | 7B instruction-tuned model |
37
+ | `mistral_0.2_instruct_7b_en ` | 7.24B | 7B instruction-tuned model version 0.2 |
38
+
39
+ ## Prompts
40
+
41
+ Mistral "instruct" models are instruction tuned on turn by turn conversations and should be prompted with examples that precisely match the training data. Specifically, you must alternate user and assistant turns that begin and end with special tokens. See the following for an example:
42
+
43
+ ```python
44
+ prompt = """[INST] Hello! [/INST] Hello! How are you? [INST] I'm great. Could you help me with a task? [/INST]
45
+ """
46
+ ```
47
+
48
+ Base models (without instruct in the name) have no specific prompting structure, and should usually be fine-tuned for a specific task.
49
+
50
+ ## Example Usage
51
+ ```python
52
+ import keras
53
+ import keras_hub
54
+ import numpy as np
55
+ ```
56
+
57
+ Use `generate()` to do text generation.
58
+ ```python
59
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("mistral_0.3_instruct_7b_en")
60
+ mistral_lm.generate("[INST] What is Keras? [/INST]", max_length=500)
61
+
62
+ # Generate with batched prompts.
63
+ mistral_lm.generate(["[INST] What is Keras? [/INST]", "[INST] Give me your best brownie recipe. [/INST]"], max_length=500)
64
+ ```
65
+
66
+ Compile the `generate()` function with a custom sampler.
67
+ ```python
68
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("mistral_0.3_instruct_7b_en")
69
+ mistral_lm.compile(sampler="greedy")
70
+ mistral_lm.generate("I want to say", max_length=30)
71
+
72
+ mistral_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
73
+ mistral_lm.generate("I want to say", max_length=30)
74
+ ```
75
+
76
+ Use `generate()` without preprocessing.
77
+ ```python
78
+ prompt = {
79
+ # `1` maps to the start token followed by "I want to say".
80
+ "token_ids": np.array([[1, 315, 947, 298, 1315, 0, 0, 0, 0, 0]] * 2),
81
+ # Use `"padding_mask"` to indicate values that should not be overridden.
82
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 0, 0, 0, 0, 0]] * 2),
83
+ }
84
+
85
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset(
86
+ "mistral_0.3_instruct_7b_en",
87
+ preprocessor=None,
88
+ dtype="bfloat16"
89
+ )
90
+ mistral_lm.generate(prompt)
91
+ ```
92
+
93
+ Call `fit()` on a single batch.
94
+ ```python
95
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
96
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("mistral_0.3_instruct_7b_en")
97
+ mistral_lm.fit(x=features, batch_size=2)
98
+ ```
99
+
100
+ Call `fit()` without preprocessing.
101
+ ```python
102
+ x = {
103
+ "token_ids": np.array([[1, 315, 947, 298, 1315, 369, 315, 837, 0, 0]] * 2),
104
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
105
+ }
106
+ y = np.array([[315, 947, 298, 1315, 369, 315, 837, 0, 0, 0]] * 2)
107
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
108
+
109
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset(
110
+ "mistral_0.3_instruct_7b_en",
111
+ preprocessor=None,
112
+ dtype="bfloat16"
113
+ )
114
+ mistral_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
115
+ ```
116
+
117
+ ## Example Usage with Hugging Face URI
118
+
119
+ ```python
120
+ import keras
121
+ import keras_hub
122
+ import numpy as np
123
+ ```
124
+
125
+ Use `generate()` to do text generation.
126
+ ```python
127
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("hf://keras/mistral_0.3_instruct_7b_en")
128
+ mistral_lm.generate("[INST] What is Keras? [/INST]", max_length=500)
129
+
130
+ # Generate with batched prompts.
131
+ mistral_lm.generate(["[INST] What is Keras? [/INST]", "[INST] Give me your best brownie recipe. [/INST]"], max_length=500)
132
+ ```
133
+
134
+ Compile the `generate()` function with a custom sampler.
135
+ ```python
136
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("hf://keras/mistral_0.3_instruct_7b_en")
137
+ mistral_lm.compile(sampler="greedy")
138
+ mistral_lm.generate("I want to say", max_length=30)
139
+
140
+ mistral_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
141
+ mistral_lm.generate("I want to say", max_length=30)
142
+ ```
143
+
144
+ Use `generate()` without preprocessing.
145
+ ```python
146
+ prompt = {
147
+ # `1` maps to the start token followed by "I want to say".
148
+ "token_ids": np.array([[1, 315, 947, 298, 1315, 0, 0, 0, 0, 0]] * 2),
149
+ # Use `"padding_mask"` to indicate values that should not be overridden.
150
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 0, 0, 0, 0, 0]] * 2),
151
+ }
152
+
153
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset(
154
+ "hf://keras/mistral_0.3_instruct_7b_en",
155
+ preprocessor=None,
156
+ dtype="bfloat16"
157
+ )
158
+ mistral_lm.generate(prompt)
159
+ ```
160
+
161
+ Call `fit()` on a single batch.
162
+ ```python
163
+ features = ["The quick brown fox jumped.", "I forgot my homework."]
164
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset("hf://keras/mistral_0.3_instruct_7b_en")
165
+ mistral_lm.fit(x=features, batch_size=2)
166
+ ```
167
+
168
+ Call `fit()` without preprocessing.
169
+ ```python
170
+ x = {
171
+ "token_ids": np.array([[1, 315, 947, 298, 1315, 369, 315, 837, 0, 0]] * 2),
172
+ "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
173
+ }
174
+ y = np.array([[315, 947, 298, 1315, 369, 315, 837, 0, 0, 0]] * 2)
175
+ sw = np.array([[1, 1, 1, 1, 1, 1, 1, 0, 0, 0]] * 2)
176
+
177
+ mistral_lm = keras_hub.models.MistralCausalLM.from_preset(
178
+ "hf://keras/mistral_0.3_instruct_7b_en",
179
+ preprocessor=None,
180
+ dtype="bfloat16"
181
+ )
182
+ mistral_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)
183
+ ```