, candidate_tower:, candidate_id_tag=Tags.ITEM_ID, outputs: Optional[Union[, List[]]] = None, logits_temperature: float = 1.0, negative_samplers: Optional[Union[, Sequence[Union[, str]], str]] = None, schema: Optional[merlin.schema.schema.Schema] = None, **kwargs)[source]#

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

Example Usage::

query = mm.Encoder(user_schema, mm.MLPBlock([128])) candidate = mm.Encoder(item_schema, mm.MLPBlock([128])) model = TwoTowerModel(query, candidate) 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.

  • query_tower (Encoder) – The layer that encodes query features

  • candidate_tower (Encoder) – The layer that encodes candidates features

  • candidate_id_tag (Tag, optional) – The tag to select candidate-id feature, by default Tags.ITEM_ID

  • outputs (Union[ModelOutput, List[ModelOutput]], optional) – The optional ModelOutput or list of ModelOutput to apply on the model.

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

  • negative_samplers (List[ItemSampler]) – List of samplers for negative sampling, by default None If the outputs and negative_samplers are not specified the two tower model is trained with contrastive learning and in-batch negative sampling strategy.

  • schema (Schema) – A schema with all input features fed to the two-tower model.

Return type