merlin.models.tf.MatrixFactorizationModelV2#

merlin.models.tf.MatrixFactorizationModelV2(schema: merlin.schema.schema.Schema, dim: int, query_id_tag=Tags.USER_ID, candidate_id_tag=Tags.ITEM_ID, embeddings_initializers: Optional[Union[Dict[str, Callable[[Any], None]], Callable[[Any], None]]] = None, embeddings_l2_batch_regularization: Union[float, Dict[str, float]] = 0.0, post: Optional[Union[merlin.models.tf.core.base.Block, str, Sequence[str]]] = None, outputs: Optional[Union[merlin.models.tf.outputs.base.ModelOutput, List[merlin.models.tf.outputs.base.ModelOutput]]] = None, negative_samplers: Optional[Union[merlin.models.tf.outputs.sampling.base.CandidateSampler, Sequence[Union[merlin.models.tf.outputs.sampling.base.CandidateSampler, str]], str]] = None, logits_temperature: float = 1.0, **kwargs) merlin.models.tf.models.base.RetrievalModelV2[source]#

Builds a matrix factorization (MF) model.

Example Usage::

mf = MatrixFactorizationModelV2(schema, dim=128) mf.compile(optimizer=”adam”) mf.fit(train_data, epochs=10)

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

  • dim (int) – The dimension of the embeddings.

  • query_id_tag (Tag) – The tag to select query-id feature, by default Tags.USER_ID

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

  • embeddings_initializers (Optional[Dict[str, Callable[[Any], None]]] = None) – An initializer function or a dict where keys are feature names and values are callable to initialize embedding tables

  • embeddings_l2_batch_regularization (Union[float, Dict[str, float]] = 0.0) – Factor for L2 regularization of the embeddings vectors (from the current batch only) If a dictionary is provided, the keys are the query-id and candidate-id names and the values are the regularization factor.

  • post (Optional[Block], optional) – The optional Block to apply on both outputs of the MF towers.

  • outputs (optional) – The optional ModelOutput or list of ModelOutput to apply on the MF model.

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

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

Return type

RetrievalModelV2