EmbeddingGemma2Backbone classkeras_hub.models.EmbeddingGemma2Backbone(
vocabulary_size,
image_size,
num_layers,
num_query_heads,
num_key_value_heads,
hidden_dim,
intermediate_dim,
head_dim,
use_sliding_window_attention=True,
sliding_window_size=512,
sliding_window_pattern=6,
layer_types=None,
global_head_dim=None,
local_rope_scaling_factor=1.0,
global_rope_scaling_factor=1.0,
vision_encoder=None,
audio_encoder=None,
layer_norm_epsilon=1e-06,
dropout=0,
embedding_dim=None,
num_global_key_value_heads=None,
hidden_size_per_layer_input=0,
global_rope_wavelength=None,
local_rope_wavelength=None,
global_rope_partial_rotary_factor=1.0,
dtype=None,
**kwargs
)
EmbeddingGemma 2 core network with hyperparameters.
This backbone implements the EmbeddingGemma 2 encoder: the Gemma 4 text
stack run with fully bidirectional attention, followed by a dense
embedding_projection applied to every token's final hidden state.
Mean pooling and L2 normalisation live in
keras_hub.models.EmbeddingGemma2TextEmbedder.
Images, video frames and audio clips are encoded by the optional
vision_encoder (Gemma4VisionEncoder) and audio_encoder
(Gemma4AudioEncoder); their soft tokens are interleaved into the text
embedding sequence at the placeholder positions before the encoder
blocks run.
The default constructor gives a fully customised, randomly initialised
model. To load preset weights use the from_preset constructor.
Arguments
keras_hub.layers.EmbeddingGemma2ImageConverter
before data reaches the backbone. The vision_encoder has its own
image_size parameter that controls position embedding sizes.True.512.6.None. Explicit specification of the
attention type for every layer sequentially
(e.g. "full_attention", "sliding_attention"). When None,
type sequence is derived from sliding_window_pattern.
Defaults to None.None. Per-head dimension used specifically
for global attention layers. When None, head_dim is used
for all layers. Defaults to None.1.0.1.0.int(factor * head_dim) dimensions are rotated; the remainder are
left unchanged (NoPE). Local layers always use full RoPE
(factor = 1.0). Defaults to 1.0.keras_hub.models.Gemma4VisionEncoder or None. When
None the model processes no images.keras_hub.models.Gemma4AudioEncoder or None. When
None the model processes no audio.1e-6.0.embedding_projection applied to every token's hidden state.None. When set, global attention
layers use this many K/V heads instead of num_key_value_heads
(separate K and V projections are kept). Defaults to None.0 to disable. Defaults to 0.keras.mixed_precision.DTypePolicy. Compute dtype.
Defaults to None.Examples
# Load a pretrained EmbeddingGemma 2 backbone.
model = keras_hub.models.EmbeddingGemma2Backbone.from_preset(
"embedding_gemma2"
)
# Randomly initialised text-only backbone with a custom config.
model = keras_hub.models.EmbeddingGemma2Backbone(
vocabulary_size=262144,
image_size=896,
num_layers=24,
num_query_heads=4,
num_key_value_heads=2,
hidden_dim=512,
intermediate_dim=2048,
head_dim=256,
embedding_dim=768,
dtype="float32",
)
from_preset methodEmbeddingGemma2Backbone.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset can be passed as a
one of:
'bert_base_en''kaggle://user/bert/keras/bert_base_en''hf://user/bert_base_en''modelscope://user/bert_base_en''./bert_base_en'This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset(), or from
a model class like keras_hub.models.GemmaBackbone.from_preset().
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone subclass, you can run cls.presets.keys() to list
all built-in presets available on the class.
Arguments
True, the weights will be loaded into the
model architecture. If False, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)
| Preset | Parameters | Description |
|---|---|---|
| embedding_gemma2 | 744.37M | EmbeddingGemma 2: 744M-parameter, 24-layer multimodal embedding model built on Gemma 4. Embeds text, images, video and audio into a 768-dimensional space. |
token_embedding propertykeras_hub.models.EmbeddingGemma2Backbone.token_embedding
A keras.layers.Embedding instance for embedding token ids.
This layer embeds integer token ids to the hidden dim of the model.
enable_lora methodEmbeddingGemma2Backbone.enable_lora(rank, target_layer_names=None)
Enable Lora on the backbone.
Calling this method will freeze all weights on the backbone,
while enabling Lora on the query & value EinsumDense layers
of the attention layers.
Arguments
None, this will be populated with the
default LoRA layer names as returned by
backbone.default_lora_layer_names().