Views
No views yet
from_preset constructor.pip install -U -q keras-hub
pip install -U -q keras| Preset name | Parameters | Description |
|---|---|---|
| albert_base_en_uncased | 11.68M | 12-layer ALBERT model where all input is lowercased. Trained on English Wikipedia + BooksCorpus. |
| albert_large_en_uncased | 17.68M | 24-layer ALBERT model where all input is lowercased. Trained on English Wikipedia + BooksCorpus. |
| albert_extra_large_en_uncased | 58.72M | 24-layer ALBERT model where all input is lowercased. Trained on English Wikipedia + BooksCorpus. |
| albert_extra_extra_large_en_uncased | 222.60M | 12-layer ALBERT model where all input is lowercased. Trained on English Wikipedia + BooksCorpus. |
num_groups. The number of
"virtual" layers, i.e., the total number of times the input sequence
will be fed through the groups in one forward pass. The input will
be routed to the correct group based on the layer index.num_inner_repetitions number of TransformerEncoder layers.TransformerEncoder layers per
group.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 np1features = ["The quick brown fox jumped.", "I forgot my homework."]
2labels = [0, 3]
3
4# Pretrained classifier.
5classifier = keras_hub.models.AlbertClassifier.from_preset(
6 "albert_base_en_uncased",
7 num_classes=4,
8)
9classifier.fit(x=features, y=labels, batch_size=2)
10classifier.predict(x=features, batch_size=2)
11
12# Re-compile (e.g., with a new learning rate).
13classifier.compile(
14 loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
15 optimizer=keras.optimizers.Adam(5e-5),
16 jit_compile=True,
17)
18# Access backbone programmatically (e.g., to change `trainable`).
19classifier.backbone.trainable = False
20# Fit again.
21classifier.fit(x=features, y=labels, batch_size=2)1features = {
2 "token_ids": np.ones(shape=(2, 12), dtype="int32"),
3 "segment_ids": np.array([[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0]] * 2),
4 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
5}
6labels = [0, 3]
7
8# Pretrained classifier without preprocessing.
9classifier = keras_hub.models.AlbertClassifier.from_preset(
10 "albert_base_en_uncased",
11 num_classes=4,
12 preprocessor=None,
13)
14classifier.fit(x=features, y=labels, batch_size=2)1import keras
2import keras_hub
3import numpy as np1features = ["The quick brown fox jumped.", "I forgot my homework."]
2labels = [0, 3]
3
4# Pretrained classifier.
5classifier = keras_hub.models.AlbertClassifier.from_preset(
6 "hf://keras/albert_base_en_uncased",
7 num_classes=4,
8)
9classifier.fit(x=features, y=labels, batch_size=2)
10classifier.predict(x=features, batch_size=2)
11
12# Re-compile (e.g., with a new learning rate).
13classifier.compile(
14 loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
15 optimizer=keras.optimizers.Adam(5e-5),
16 jit_compile=True,
17)
18# Access backbone programmatically (e.g., to change `trainable`).
19classifier.backbone.trainable = False
20# Fit again.
21classifier.fit(x=features, y=labels, batch_size=2)1features = {
2 "token_ids": np.ones(shape=(2, 12), dtype="int32"),
3 "segment_ids": np.array([[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0]] * 2),
4 "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
5}
6labels = [0, 3]
7
8# Pretrained classifier without preprocessing.
9classifier = keras_hub.models.AlbertClassifier.from_preset(
10 "hf://keras/albert_base_en_uncased",
11 num_classes=4,
12 preprocessor=None,
13)
14classifier.fit(x=features, y=labels, batch_size=2)