merlin.models.tf.InputBlockV2#

merlin.models.tf.InputBlockV2(schema: typing.Optional[merlin.schema.schema.Schema] = None, categorical: typing.Union[merlin.schema.tags.Tags, keras.engine.base_layer.Layer] = Tags.CATEGORICAL, continuous: typing.Union[merlin.schema.tags.Tags, keras.engine.base_layer.Layer] = Tags.CONTINUOUS, pretrained_embeddings: typing.Union[merlin.schema.tags.Tags, keras.engine.base_layer.Layer] = Tags.EMBEDDING, 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]] = 'concat', tag_to_block={<Tags.CONTINUOUS: 'continuous'>: <class 'merlin.models.tf.inputs.continuous.Continuous'>, <Tags.CATEGORICAL: 'categorical'>: <function Embeddings>, <Tags.EMBEDDING: 'embedding'>: <function PretrainedEmbeddings>}, **branches) merlin.models.tf.core.combinators.ParallelBlock[source]#

The entry block of the model to process input features from a schema.

This is a new version of InputBlock, which is more flexible for accepting the external definition of embeddings block. After 22.10 this will become the default.

Simple Usage::

inputs = InputBlockV2(schema)

Custom Embeddings::
inputs = InputBlockV2(

schema, categorical=Embeddings(schema, dim=32)

)

Sparse outputs for one-hot::
inputs = InputBlockV2(

schema, categorical=CategoryEncoding(schema, sparse=True), post=ToSparse()

)

Add continuous projection::
inputs = InputBlockV2(

schema, continuous=ContinuousProjection(continuous_schema, MLPBlock([32])),

)

Merge 2D and 3D (for session-based)::
inputs = InputBlockV2(

schema, post=BroadcastToSequence(context_schema, sequence_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.

  • categorical (Union[Tags, Layer], defaults to Tags.CATEGORICAL) – A block or column-selector to use for categorical-features. If a column-selector is provided (either a schema or tags), the selector will be passed to Embeddings() to infer the embedding tables from the column-selector.

  • continuous (Union[Tags, Layer], defaults to Tags.CONTINUOUS) – A block to use for continuous-features. If a column-selector is provided (either a schema or tags), the selector will be passed to Continuous() to infer the features from the column-selector.

  • pretrained_embeddings (Union[Tags, Layer], defaults to Tags.EMBEDDING) – A block to use for pre-trained embeddings If a column-selector is provided (either a schema or tags), the selector will be passed to PretrainedEmbeddings() to infer the features from the column-selector.

  • 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 “concat”

  • tag_to_block (Dict[str, Callable[[Schema], Layer]], optional) –

    Mapping from tag to block-type, by default:

    Tags.CONTINUOUS -> Continuous Tags.CATEGORICAL -> Embeddings

  • **branches (dict) – Extra branches to add to the input block.

Returns

Returns a ParallelBlock with a Dict with two branches: continuous and embeddings

Return type

ParallelBlock