Views
No views yet
pip install -U -q keras-hub
pip install -U -q keras>=3| Preset name | Parameters | Description |
|---|---|---|
gemma_2b_en | 2.51B | 2 billion parameter, 18-layer, base Gemma model. |
gemma_instruct_2b_en | 2.51B | 2 billion parameter, 18-layer, instruction tuned Gemma model. |
gemma_1.1_instruct_2b_en | 2.51B | 2 billion parameter, 18-layer, instruction tuned Gemma model. The 1.1 update improves model quality. |
gemma_7b_en | 8.54B | 7 billion parameter, 28-layer, base Gemma model. |
gemma_instruct_7b_en | 8.54B | 7 billion parameter, 28-layer, instruction tuned Gemma model. |
gemma_1.1_instruct_7b_en | 8.54B | 7 billion parameter, 28-layer, instruction tuned Gemma model. The 1.1 update improves model quality. |
gemma_2b_en, gemma_7b_en) will complete sentences. The following are some example prompts:instruct) 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. New lines do matter. See the following for an example:1start_of_turn_user = "<start_of_turn>user\n"
2start_of_turn_model = "<start_of_turn>model\n"
3end_of_turn = "<end_of_turn>\n"
4prompt = start_of_turn_user + "You are a friendly assistant. Say hi." + \
5 end_of_turn + start_of_turn_model1!pip install -U keras-hub
2!pip install -U kerasimport keras
import keras_hub
import numpy as npgenerate() to do text generation.1gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("gemma_instruct_7b_en")
2gemma_lm.generate("Keras is a", max_length=30)
3
4# Generate with batched prompts.
5gemma_lm.generate(["Keras is a", "I want to say"], max_length=30)generate() function with a custom sampler.1gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("gemma_instruct_7b_en")
2gemma_lm.compile(sampler="top_k")
3gemma_lm.generate("I want to say", max_length=30)
4
5gemma_lm.compile(sampler= keras_hub.samplers.BeamSampler(num_beams=2))
6gemma_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 # `2, 214064, 603` maps to the start token followed by "Keras is".
3 "token_ids": np.array([[2, 214064, 603, 0, 0, 0, 0]] * 2),
4 # Use `"padding_mask"` to indicate values that should not be overridden.
5 "padding_mask": np.array([[1, 1, 1, 0, 0, 0, 0]] * 2),
6}
7
8gemma_lm = keras_hub.models.GemmaCausalLM.from_preset(
9 "gemma_instruct_7b_en",
10 preprocessor=None,
11)
12gemma_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("gemma_instruct_7b_en")
3gemma_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[2, 214064, 603, 5271, 6044, 9581, 3, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 0]] * 2),
4}
5y = np.array([[214064, 603, 5271, 6044, 9581, 3, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 0, 0]] * 2)
7
8gemma_lm = keras_hub.models.GemmaCausalLM.from_preset(
9 "gemma_instruct_7b_en",
10 preprocessor=None,
11)
12gemma_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)1!pip install -U keras-hub
2!pip install -U kerasimport keras
import keras_hub
import numpy as npgenerate() to do text generation.1gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("hf://keras/gemma_instruct_7b_en")
2gemma_lm.generate("Keras is a", max_length=30)
3
4# Generate with batched prompts.
5gemma_lm.generate(["Keras is a", "I want to say"], max_length=30)generate() function with a custom sampler.1gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("hf://keras/gemma_instruct_7b_en")
2gemma_lm.compile(sampler="top_k")
3gemma_lm.generate("I want to say", max_length=30)
4
5gemma_lm.compile(sampler= keras_hub.samplers.BeamSampler(num_beams=2))
6gemma_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 # `2, 214064, 603` maps to the start token followed by "Keras is".
3 "token_ids": np.array([[2, 214064, 603, 0, 0, 0, 0]] * 2),
4 # Use `"padding_mask"` to indicate values that should not be overridden.
5 "padding_mask": np.array([[1, 1, 1, 0, 0, 0, 0]] * 2),
6}
7
8gemma_lm = keras_hub.models.GemmaCausalLM.from_preset(
9 "hf://keras/gemma_instruct_7b_en",
10 preprocessor=None,
11)
12gemma_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2gemma_lm = keras_hub.models.GemmaCausalLM.from_preset("hf://keras/gemma_instruct_7b_en")
3gemma_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[2, 214064, 603, 5271, 6044, 9581, 3, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 0]] * 2),
4}
5y = np.array([[214064, 603, 5271, 6044, 9581, 3, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 0, 0]] * 2)
7
8gemma_lm = keras_hub.models.GemmaCausalLM.from_preset(
9 "hf://keras/gemma_instruct_7b_en",
10 preprocessor=None,
11)
12gemma_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)