deepr.examples.movielens.layers package

Submodules

deepr.examples.movielens.layers.average module

Average Model.

class deepr.examples.movielens.layers.average.AddBias[source]

Bases: Layer

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

deepr.examples.movielens.layers.average.AverageModel(vocab_size, dim, keep_prob, share_embeddings=True, train_embeddings=True, train_biases=True, average_with_bias=False, project=False, reduce_mode='average')[source]

Average Model.

class deepr.examples.movielens.layers.average.Logits(vocab_size, dim, reuse=True, trainable=True)[source]

Bases: Layer

Computes logits as <u, i> + b_i.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.average.Projection(variable_name, reuse=False, transpose=False)[source]

Bases: Layer

Apply symmetric transform to non-projected user embeddings.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.average.UserEmbedding(mode, keep_prob, reduce_mode='average')[source]

Bases: Layer

Compute Weighted Sum (randomly masking inputs in TRAIN mode).

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

deepr.examples.movielens.layers.bpr module

BPR Loss with biases.

deepr.examples.movielens.layers.bpr.BPRLoss(vocab_size)[source]

BPR Loss with biases.

deepr.examples.movielens.layers.losses module

Losses.

class deepr.examples.movielens.layers.losses.L2Loss[source]

Bases: Layer

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

deepr.examples.movielens.layers.losses.Loss(loss, vocab_size)[source]

Return the relevant loss layer.

deepr.examples.movielens.layers.losses.VAELoss(loss, vocab_size, beta_start, beta_end, beta_steps)[source]

Add beta * KL to the loss and return relevant loss layer.

deepr.examples.movielens.layers.multi module

MultiLogLikelihood Loss with Complementarity Sampling.

deepr.examples.movielens.layers.multi.MultiLogLikelihoodCSS(vocab_size)[source]

MultiLogLikelihood Loss with Complementarity Sampling.

deepr.examples.movielens.layers.ns module

Negative Sampling Loss with biases.

deepr.examples.movielens.layers.ns.NegativeSampling(vocab_size)[source]

Negative Sampling Loss with biases.

deepr.examples.movielens.layers.transformer module

Transformer Model.

class deepr.examples.movielens.layers.transformer.Logits(vocab_size, dim)[source]

Bases: Layer

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

deepr.examples.movielens.layers.transformer.TransformerModel(vocab_size, dim, **kwargs)[source]

Transformer Model.

deepr.examples.movielens.layers.vae module

VAE Model.

class deepr.examples.movielens.layers.vae.AddBias(variable_name, seed)[source]

Bases: Layer

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.vae.Decode(dims, activation, seed)[source]

Bases: Layer

Decode tensor.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.vae.Encode(dims, activation, seed)[source]

Bases: Layer

Encode tensor, apply KL constraint.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.vae.GaussianNoise(mode, seed)[source]

Bases: Layer

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.vae.Logits(vocab_size, dim, trainable, reuse, seed)[source]

Bases: Layer

Compute logits given user and create target item embeddings.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

class deepr.examples.movielens.layers.vae.Projection(variable_name, seed)[source]

Bases: Layer

Apply symmetric transform to non-projected user embeddings.

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

deepr.examples.movielens.layers.vae.VAEModel(vocab_size, dims_encode=(600, 200), dims_decode=(200, 600), keep_prob=0.5, train_embeddings=True, project=False, share_embeddings=False, seed=42)[source]

VAE Model.

Return type:

Layer

class deepr.examples.movielens.layers.vae.WeightedSum(mode, keep_prob, seed)[source]

Bases: Layer

Compute Weighted Sum (randomly masking inputs in TRAIN mode).

forward(tensors, mode: Optional[str] = None)

Forward method on one Tensor or a tuple of Tensors.

Parameters:
  • tensors (Union[tf.Tensor, Tuple[tf.Tensor, ...]]) –

    • n_in = 1: one tensor (NOT wrapped in a tuple)

    • n_in > 1: a tuple of tensors

  • mode (str, optional) – Description

Returns:

  • n_out = 1: one tensor (NOT wrapped in a tuple)

  • n_out > 1: a tuple of tensors

Return type:

Union[tf.Tensor, Tuple[tf.Tensor, …]]

Module contents