Views
No views yet
pip install -U -q keras-hub
pip install -U -q keras| Preset name | Parameters | Description |
|---|---|---|
vicuna_1.5_7b_en | 6.74B | 7 billion parameter, 32-layer, instruction tuned Vicuna v1.5 model. |
1import keras
2import keras_hub
3import numpy as npgenerate() to do text generation.1vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("vicuna_1.5_7b_en")
2vicuna_lm.generate("### HUMAN:\nWhat is Keras? \n### RESPONSE:\n", max_length=500)
3
4# Generate with batched prompts.
5vicuna_lm.generate([
6 "### HUMAN:\nWhat is ML? \n### RESPONSE:\n",
7 "### HUMAN:\nGive me your best brownie recipe.\n### RESPONSE:\n",
8],max_length=500)generate() function with a custom sampler.1vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("vicuna_1.5_7b_en")
2vicuna_lm.compile(sampler="greedy")
3vicuna_lm.generate("I want to say", max_length=30)
4
5vicuna_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6vicuna_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 # `1` maps to the start token followed by "I want to say".
3 "token_ids": np.array([[1, 306, 864, 304, 1827, 0, 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, 1, 1, 0, 0, 0, 0, 0]] * 2),
6}
7
8vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset(
9 "vicuna_1.5_7b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13vicuna_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("vicuna_1.5_7b_en")
3vicuna_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[1, 450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 0]] * 2),
4}
5y = np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2)
7
8vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset(
9 "vicuna_1.5_7b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13vicuna_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)1import keras
2import keras_hub
3import numpy as npgenerate() to do text generation.1vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("hf://keras/vicuna_1.5_7b_en")
2vicuna_lm.generate("### HUMAN:\nWhat is Keras? \n### RESPONSE:\n", max_length=500)
3
4# Generate with batched prompts.
5vicuna_lm.generate([
6 "### HUMAN:\nWhat is ML? \n### RESPONSE:\n",
7 "### HUMAN:\nGive me your best brownie recipe.\n### RESPONSE:\n",
8],max_length=500)generate() function with a custom sampler.1vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("hf://keras/vicuna_1.5_7b_en")
2vicuna_lm.compile(sampler="greedy")
3vicuna_lm.generate("I want to say", max_length=30)
4
5vicuna_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6vicuna_lm.generate("I want to say", max_length=30)generate() without preprocessing.1prompt = {
2 # `1` maps to the start token followed by "I want to say".
3 "token_ids": np.array([[1, 306, 864, 304, 1827, 0, 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, 1, 1, 0, 0, 0, 0, 0]] * 2),
6}
7
8vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset(
9 "hf://keras/vicuna_1.5_7b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13vicuna_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset("hf://keras/vicuna_1.5_7b_en")
3vicuna_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[1, 450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 0]] * 2),
4}
5y = np.array([[450, 4996, 17354, 1701, 29916, 12500, 287, 29889, 0, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2)
7
8vicuna_lm = keras_hub.models.LlamaCausalLM.from_preset(
9 "hf://keras/vicuna_1.5_7b_en",
10 preprocessor=None,
11 dtype="bfloat16"
12)
13vicuna_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)