merlin.schema.schema.Schema, query_tower:, item_tower: Optional[] = None, query_tower_tag=Tags.USER, item_tower_tag=Tags.ITEM, embedding_options: = EmbeddingOptions(embedding_dims=None, embedding_dim_default=64, infer_embedding_sizes=False, infer_embedding_sizes_multiplier=2.0, infer_embeddings_ensure_dim_multiple_of_8=False, embeddings_initializers=None, embeddings_l2_reg=0.0, combiner='mean'), post: Optional[Union[, str, Sequence[str]]] = None, prediction_tasks: Optional[Union[, List[],]] = None, logits_temperature: float = 1.0, samplers: Sequence[] = (), **kwargs)[source]#

Builds the Two-tower architecture, as proposed in [1].

Example Usage::

two_tower = TwoTowerModel(schema, MLPBlock([256, 64])) two_tower.compile(optimizer=”adam”), epochs=10)


[1] Yi, Xinyang, et al.

“Sampling-bias-corrected neural modeling for large corpus item recommendations.” Proceedings of the 13th ACM Conference on Recommender Systems. 2019.

  • schema (Schema) – The Schema with the input features

  • query_tower (Block) – The Block that combines user features

  • item_tower (Optional[Block], optional) – The optional Block that combines items features. If not provided, a copy of the query_tower is used.

  • query_tower_tag (Tag) – The tag to select query features, by default Tags.USER

  • item_tower_tag (Tag) – The tag to select item features, by default Tags.ITEM

  • embedding_options (EmbeddingOptions) – Options for the input embeddings. - embedding_dims: Optional[Dict[str, int]] - The dimension of the embedding table for each feature (key), by default {} - embedding_dim_default: int - Default dimension of the embedding table, when the feature is not found in embedding_dims, by default 64 - infer_embedding_sizes : bool, Automatically defines the embedding dimension from the feature cardinality in the schema, by default False - infer_embedding_sizes_multiplier: int. Multiplier used by the heuristic to infer the embedding dimension from its cardinality. Generally reasonable values range between 2.0 and 10.0. By default 2.0.

  • post (Optional[Block], optional) – The optional Block to apply on both outputs of Two-tower model

  • prediction_tasks (optional) – The optional PredictionTask or list of PredictionTask to apply on the model.

  • logits_temperature (float) – Parameter used to reduce model overconfidence, so that logits / T. Defaults to 1.

  • loss (Optional[LossType]) – Loss function. Defaults to categorical_crossentropy.

  • samplers (List[ItemSampler]) – List of samplers for negative sampling, by default [InBatchSampler()]

Return type