EmbeddingGemma2TextEmbedder model

[source]

EmbeddingGemma2TextEmbedder class

keras_hub.models.EmbeddingGemma2TextEmbedder(
    backbone, preprocessor=None, pooling_mode="mean", normalize=True, **kwargs
)

An end-to-end EmbeddingGemma2 model for generating sentence embeddings.

This model attaches a mean-pooling and L2 normalization head to an EmbeddingGemma2Backbone instance, mapping from the backbone outputs to fixed-size sentence embeddings suitable for semantic similarity, clustering, and retrieval tasks.

This model can optionally be configured with a preprocessor layer, in which case it will automatically apply preprocessing to raw inputs during fit(), predict(), and evaluate(). This is done by default when creating the model with from_preset().

Arguments


[source]

from_preset method

EmbeddingGemma2TextEmbedder.from_preset(preset, load_weights=True, **kwargs)

Instantiate a keras_hub.models.Task 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 one of:

  1. a built-in preset identifier like 'bert_base_en'
  2. a Kaggle Models handle like 'kaggle://user/bert/keras/bert_base_en'
  3. a Hugging Face handle like 'hf://user/bert_base_en'
  4. a path to a local preset directory like './bert_base_en'

For any Task subclass, you can run cls.presets.keys() to list all built-in presets available on the class.

This constructor can be called in one of two ways. Either from a task specific base class like keras_hub.models.CausalLM.from_preset(), or from a model class like keras_hub.models.BertTextClassifier.from_preset(). If calling from the a base class, the subclass of the returning object will be inferred from the config in the preset directory.

Arguments

  • preset: string. A built-in preset identifier, a Kaggle Models handle, a Hugging Face handle, or a path to a local directory.
  • load_weights: bool. If True, saved weights will be loaded into the model architecture. If False, all weights will be randomly initialized.

Examples

# Load a Gemma generative task.
causal_lm = keras_hub.models.CausalLM.from_preset(
    "gemma_2b_en",
)

# Load a Bert classification task.
model = keras_hub.models.TextClassifier.from_preset(
    "bert_base_en",
    num_classes=2,
)
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.

backbone property

keras_hub.models.EmbeddingGemma2TextEmbedder.backbone

A keras_hub.models.Backbone model with the core architecture.


preprocessor property

keras_hub.models.EmbeddingGemma2TextEmbedder.preprocessor

A keras_hub.models.Preprocessor layer used to preprocess input.