merlin.models.tf.Embeddings

merlin.models.tf.Embeddings(schema: merlin.schema.schema.Schema, dim: Optional[Union[Dict[str, int], int]] = None, infer_dim_fn: Callable[[merlin.schema.schema.ColumnSchema], int] = <function infer_embedding_dim>, sequence_combiner: Optional[Union[str, keras.engine.base_layer.Layer, Dict[str, Union[str, keras.engine.base_layer.Layer]]]] = 'mean', embeddings_initializer: Optional[Union[str, keras.initializers.initializers.Initializer, Dict[str, Union[str, keras.initializers.initializers.Initializer]]]] = None, embeddings_regularizer: Optional[Union[str, keras.regularizers.Regularizer, Dict[str, Union[str, keras.regularizers.Regularizer]]]] = None, activity_regularizer: Optional[Union[str, keras.regularizers.Regularizer, Dict[str, Union[str, keras.regularizers.Regularizer]]]] = None, trainable: Optional[Union[bool, Dict[str, bool]]] = None, table_cls: Type[keras.engine.base_layer.Layer] = <class 'merlin.models.tf.inputs.embedding.EmbeddingTable'>, pre: Optional[Union[merlin.models.tf.core.base.Block, str, Sequence[str]]] = None, post: Optional[Union[merlin.models.tf.core.base.Block, str, Sequence[str]]] = None, aggregation: Optional[Union[str, merlin.models.tf.core.tabular.TabularAggregation]] = None, block_name: str = 'embeddings', l2_batch_regularization_factor: Optional[Union[float, Dict[str, float]]] = 0.0, **kwargs)merlin.models.tf.core.combinators.ParallelBlock[source]

Creates a ParallelBlock with an EmbeddingTable for each categorical feature in the schema.

Parameters
  • schema (Schema) – Schema of the input data. This Schema object will be automatically generated using [NVTabular](https://nvidia-merlin.github.io/NVTabular/main/Introduction.html). Next to this, it’s also possible to construct it manually.

  • dim (Optional[Union[Dict[str, int], int]], optional) – A dim to use for all features, or a Dict like {“feature_name”: embedding size, …}, by default None

  • infer_dim_fn (Callable[[ColumnSchema], int], defaults to infer_embedding_dim) – The function to use to infer the embedding dimension, by default infer_embedding_dim

  • sequence_combiner (Optional[Union[str, tf.keras.layers.Layer]], optional) – A string specifying how to combine embedding results for each entry (“mean”, “sqrtn” and “sum” are supported) or a layer. Default is None (no combiner used)

  • embeddings_initializer (Union[InitializerType, Dict[str, InitializerType]], optional) – An initializer function or a dict where keys are feature names and values are callable to initialize embedding tables. Pre-trained embeddings can be fed via embeddings_initializer arg.

  • embeddings_regularizer (Union[RegularizerType, Dict[str, RegularizerType]], optional) – A regularizer function or a dict where keys are feature names and values are callable to apply regularization to embedding tables.

  • activity_regularizer (Union[RegularizerType, Dict[str, RegularizerType]], optional) – A regularizer function or a dict where keys are feature names and values are callable to apply regularization to the activations of the embedding tables.

  • trainable (Optional[Dict[str, bool]] = None) – Name of the column(s) whose embeddings should be frozen (or trainable) during training trainable will be set to False/True for these column(s), accordingly

  • table_cls (Type[tf.keras.layers.Layer], by default EmbeddingTable) – The class to use for each embedding table.

  • pre (Optional[BlockType], optional) – Transformation block to apply before the embeddings lookup, by default None

  • post (Optional[BlockType], optional) – Transformation block to apply after the embeddings lookup, by default None

  • aggregation (Optional[TabularAggregationType], optional) – Transformation block to apply for aggregating the inputs, by default None

  • block_name (str, optional) – Name of the block, by default “embeddings”

  • l2_batch_regularization_factor (Optional[float, Dict[str, float]] = 0.0) – Factor for L2 regularization of the embeddings vectors (from the current batch only) If a dictionary is provided, the keys are feature names and the values are regularization factors

Returns

Returns a parallel block with an embedding table for each categorical features

Return type

ParallelBlock