merlin.models.tf.TwoTowerModelV2#
- merlin.models.tf.TwoTowerModelV2(query_tower: merlin.models.tf.core.encoder.Encoder, candidate_tower: merlin.models.tf.core.encoder.Encoder, candidate_id_tag=Tags.ITEM_ID, outputs: Optional[Union[merlin.models.tf.outputs.base.ModelOutput, List[merlin.models.tf.outputs.base.ModelOutput]]] = None, logits_temperature: float = 1.0, negative_samplers: Optional[Union[merlin.models.tf.outputs.sampling.base.CandidateSampler, Sequence[Union[merlin.models.tf.outputs.sampling.base.CandidateSampler, str]], str]] = None, schema: Optional[merlin.schema.schema.Schema] = None, **kwargs) merlin.models.tf.models.base.RetrievalModelV2 [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”) two_tower.fit(train_data, epochs=10)
References
- [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.
- Parameters
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