Divyasreepat commited on
Commit
a9fec40
1 Parent(s): 0046286

Update README.md with new model card content

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