EmbedReduce classkeras_rs.layers.EmbedReduce(
input_dim: int,
output_dim: int,
embeddings_initializer: Union[
str,
keras.src.initializers.initializer.Initializer,
type[keras.src.initializers.initializer.Initializer],
Callable[[Sequence[int | None], str], Any],
Any,
] = "uniform",
embeddings_regularizer: Union[
str,
keras.src.regularizers.regularizers.Regularizer,
type[keras.src.regularizers.regularizers.Regularizer],
Callable[[Any], Any],
NoneType,
] = None,
embeddings_constraint: Union[
str,
keras.src.constraints.constraints.Constraint,
type[keras.src.constraints.constraints.Constraint],
Callable[[Any], Any],
NoneType,
] = None,
mask_zero: bool = False,
weights: Any = None,
combiner: str = "mean",
**kwargs: Any
)
An embedding layer that reduces with a combiner.
This layer embeds inputs and then applies a reduction to combine a set of embeddings into a single embedding. This is typically used to embed a sequence of items as a single embedding.
If the inputs passed to __call__ are 1D, no reduction is applied. If the
inputs are 2D, dimension 1 is reduced using the combiner so that the result
is of shape (batch_size, output_dim). Inputs of rank 3 and higher are not
allowed. Weights can optionally be passed to the __call__ method to
apply weights to different samples before reduction.
This layer supports sparse inputs and ragged inputs with backends that support them. The output after reduction is dense. For ragged inputs, the ragged dimension must be 1 as it is the dimension that is reduced.
Arguments
embeddings matrix (see
keras.initializers).embeddings
matrix (see keras.regularizers).embeddings
matrix (see keras.constraints).True, then all subsequent layers in the model need to support
masking or an exception will be raised. If mask_zero is set to
True, as a consequence, index 0 cannot be used in the vocabulary
(input_dim should equal size of vocabulary + 1).(input_dim, output_dim). The initial embeddings values to use.mean, sqrtn and sum are supported.
mean is the default. sqrtn often achieves good accuracy, in
particular with bag-of-words columns.Embedding.call methodEmbedReduce.call(inputs: Any, weights: Optional[Any] = None)
Apply embedding and reduction.
Arguments
inputs (1D case) or match the shape of inputs (2D case).Returns
A dense 2D tensor of shape (batch_size, output_dim).