Views
No views yet
from_preset() constructor.pip install -U -q keras-Hub
pip install -U -q keras| Preset name | Parameters | Description |
|---|---|---|
| opt_1.3b_en | 125.24M | 12-layer OPT model where case in maintained. Trained on BookCorpus, CommonCrawl, Pile, and PushShift.io corpora. |
| opt_125m_en | 1.32B | 24-layer OPT model where case in maintained. Trained on BookCorpus, CommonCrawl, Pile, and PushShift.io corpora. |
| opt_2.7b_en | 2.70B | 32-layer OPT model where case in maintained. Trained on BookCorpus, CommonCrawl, Pile, and PushShift.io corpora. |
| opt_6.7b_en | 6.70B | 32-layer OPT model where case in maintained. Trained on BookCorpus, CommonCrawl, Pile, and PushShift.io corpora. |
None, max_sequence_length uses the value from
sequence length. This determines the variable shape for positional
embeddings.1import keras
2import keras_hub
3import numpy as npgenerate() to do text generation.1opt_lm = keras_hub.models.OPTCausalLM.from_preset("opt_1.3b_en")
2opt_lm.generate("I want to say", max_length=30)
3
4# Generate with batched prompts.
5opt_lm.generate(["This is a", "Where are you"], max_length=30)generate() function with a custom sampler.1opt_lm = keras_hub.models.OPTCausalLM.from_preset("opt_1.3b_en")
2opt_lm.compile(sampler="greedy")
3opt_lm.generate("I want to say", max_length=30)
4
5opt_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6opt_lm.generate("I want to say", max_length=30)generate() without preprocessing.1# Prompt the model with `5338, 318` (the token ids for `"Who is"`).
2# Use `"padding_mask"` to indicate values that should not be overridden.
3prompt = {
4 "token_ids": np.array([[5338, 318, 0, 0, 0]] * 2),
5 "padding_mask": np.array([[1, 1, 0, 0, 0]] * 2),
6}
7
8opt_lm = keras_hub.models.OPTCausalLM.from_preset(
9 "opt_1.3b_en",
10 preprocessor=None,
11)
12opt_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2opt_lm = keras_hub.models.OPTCausalLM.from_preset("opt_1.3b_en")
3opt_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[1, 2, 3, 4, 5]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1]] * 2),
4}
5y = np.array([[2, 3, 4, 5, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1]] * 2)
7
8opt_lm = keras_hub.models.OPTCausalLM.from_preset(
9 "opt_1.3b_en",
10 preprocessor=None,
11)
12opt_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.1opt_lm = keras_hub.models.OPTCausalLM.from_preset("hf://keras/opt_1.3b_en")
2opt_lm.generate("I want to say", max_length=30)
3
4# Generate with batched prompts.
5opt_lm.generate(["This is a", "Where are you"], max_length=30)generate() function with a custom sampler.1opt_lm = keras_hub.models.OPTCausalLM.from_preset("hf://keras/opt_1.3b_en")
2opt_lm.compile(sampler="greedy")
3opt_lm.generate("I want to say", max_length=30)
4
5opt_lm.compile(sampler=keras_hub.samplers.BeamSampler(num_beams=2))
6opt_lm.generate("I want to say", max_length=30)generate() without preprocessing.1# Prompt the model with `5338, 318` (the token ids for `"Who is"`).
2# Use `"padding_mask"` to indicate values that should not be overridden.
3prompt = {
4 "token_ids": np.array([[5338, 318, 0, 0, 0]] * 2),
5 "padding_mask": np.array([[1, 1, 0, 0, 0]] * 2),
6}
7
8opt_lm = keras_hub.models.OPTCausalLM.from_preset(
9 "hf://keras/opt_1.3b_en",
10 preprocessor=None,
11)
12opt_lm.generate(prompt)fit() on a single batch.1features = ["The quick brown fox jumped.", "I forgot my homework."]
2opt_lm = keras_hub.models.OPTCausalLM.from_preset("hf://keras/opt_1.3b_en")
3opt_lm.fit(x=features, batch_size=2)fit() without preprocessing.1x = {
2 "token_ids": np.array([[1, 2, 3, 4, 5]] * 2),
3 "padding_mask": np.array([[1, 1, 1, 1, 1]] * 2),
4}
5y = np.array([[2, 3, 4, 5, 0]] * 2)
6sw = np.array([[1, 1, 1, 1, 1]] * 2)
7
8opt_lm = keras_hub.models.OPTCausalLM.from_preset(
9 "hf://keras/opt_1.3b_en",
10 preprocessor=None,
11)
12opt_lm.fit(x=x, y=y, sample_weight=sw, batch_size=2)