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