Extractions¶
Extraction¶
-
class
openrec.legacy.modules.extractions.
Extraction
(train=True, l2_reg=None, scope=None, reuse=False)¶ A direct inheritance of the Module.
Look Up¶
-
class
openrec.legacy.modules.extractions.
LookUp
(embed, ids=None, scope=None, reuse=False)¶ The LookUp module maps (embeds) input ids into fixed representations. The representations are not be updated during training. The module outputs a tensor with shape shape(ids) + [embedding dimensionality].
Parameters: - embed (numpy array) – Fixed embedding matrix.
- ids (Tensorflow tensor, optional) – List of ids to retrieve embeddings. If None, the whole embedding matrix is returned.
- scope (str, optional) – Scope for module variables.
- reuse (bool, optional) – Whether or not to reuse module variables.
Build shared computational graphs across training and serving (may be overridden).
Identity Mapping¶
-
class
openrec.legacy.modules.extractions.
IdentityMapping
(value, scope=None, reuse=False)¶ The IdentityMapping module executes an identity function.
Parameters: - value (Tensorflow tensor) – Input tensor
- scope (str, optional) – Scope for module variables.
- reuse (bool, optional) – Whether or not to reuse module variables.
Build shared computational graphs across training and serving (may be overridden).
Latent Factor¶
-
class
openrec.legacy.modules.extractions.
LatentFactor
(shape, init='normal', ids=None, l2_reg=None, scope=None, reuse=False)¶ The LatentFactor module maps (embeds) input ids into latent representations. The module outputs a tensor with shape shape(ids) + [embedding dimensionality].
Parameters: - shape (list) – Shape of the embedding matrix, i.e. [number of unique ids, embedding dimensionality].
- init (str, optional) – Embedding initialization. ‘zero’ or ‘normal’ (default).
- ids (Tensorflow tensor, optionl) – List of ids to retrieve embeddings. If None, the whole embedding matrix is returned.
- l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
- scope (str, optional) – Scope for module variables.
- reuse (bool, optional) – Whether or not to reuse module variables.
Build shared computational graphs across training and serving (may be overridden).
-
censor_l2_norm_op
(censor_id_list=None, max_norm=1)¶ Limit the norm of embeddings.
Parameters: - censor_id_list (list or Tensorflow tensor) – list of embeddings to censor (indexed by ids).
- max_norm (float, optional) – Maximum norm.
Returns: An operator for post-training execution.
Return type: Tensorflow operator
Multi Layer FC¶
-
class
openrec.legacy.modules.extractions.
MultiLayerFC
(in_tensor, dims, relu_in=False, relu_mid=True, relu_out=False, dropout_in=None, dropout_mid=None, dropout_out=None, bias_in=True, bias_mid=True, bias_out=True, batch_norm=False, train=True, l2_reg=None, scope=None, reuse=False)¶ The MultiLayerFC module implements multi-layer perceptrons with ReLU as non-linear activation functions. Each layer is often referred as a fully-connected layer.
Parameters: - in_tensor (Tensorflow tensor) – An input tensor with shape [*, feature dimensionality]
- dims (list) – Specify the feature size of each layer’s outputs. For example, setting dims=[512, 258, 128] to create three fully-connected layers with output shape [*, 512], [*, 256], and [*, 128], respectively.
- relu_in (bool, optional) – Whether or not to add ReLU to the input tensor.
- relu_mid (bool, optional) – Whether or not to add ReLU to the outputs of intermediate layers.
- relu_out (bool, optional) – Whether or not to add ReLU to the final output tensor.
- dropout_in (float, optional) – Dropout rate for the input tensor. If None, no dropout is used for the input tensor.
- dropout_mid (float, optional) – Dropout rate for the outputs of intermediate layers. If None, no dropout is used for the intermediate outputs.
- dropout_out (float, optional) – Dropout rate for the outputs of the final layer. If None, no dropout is used for the final outputs.
- bias_in (bool, optional) – Whether or not to add bias to the input tensor.
- bias_mid (bool, optional) – Whether or not to add bias to the outputs of intermediate layers.
- bias_out (bool, optional) – Whether or not to add bias to the final output tensor.
- batch_norm (bool, optional) – Whether or not to add batch normalization [1] to each layer’s outputs.
- train (bool, optionl) – An indicator for training or servining phase.
- l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
- scope (str, optional) – Scope for module variables.
- reuse (bool, optional) – Whether or not to reuse module variables.
References
[1] Ioffe, S. and Szegedy, C., 2015, June. Batch normalization: Accelerating deep network training by reducing internal covariate shift. In International Conference on Machine Learning (pp. 448-456). Build shared computational graphs across training and serving (may be overridden).
SDAE¶
-
class
openrec.legacy.modules.extractions.
SDAE
(in_tensor, dims, dropout=None, l2_reconst=1.0, train=True, l2_reg=None, scope=None, reuse=False)¶ The SDAE module implements Stacked Denoising Autoencoders [bn]. It outputs SDAE’s bottleneck representations (i.e., the encoder outputs).
Parameters: - in_tensor (Tensorflow tensor) – An input tensor with shape [*, feature dimensionality]
- dims (list) – Specify the feature size of each encoding layer’s outputs. For example, setting dims=[512, 258, 128] to create an three-layer encoder with output shape [*, 512], [*, 256], and [*, 128], and a two-layer decoder with output shape [*, 256] and [*, 512].
- dropout (float, optional) – Dropout rate for the input tensor. If None, no dropout is used for the input tensor.
- l2_reconst (float, optional) – Weight for reconstruction loss.
- train (bool, optionl) – An indicator for training or servining phase.
- l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
- scope (str, optional) – Scope for module variables.
- reuse (bool, optional) – Whether or not to reuse module variables.
References
[bn] Vincent, P., Larochelle, H., Lajoie, I., Bengio, Y. and Manzagol, P.A., 2010. Stacked denoising autoencoders: Learning useful representations in a deep network with a local denoising criterion. Journal of Machine Learning Research, 11(Dec), pp.3371-3408. Build shared computational graphs across training and serving (may be overridden).
TemporalLatentFactor¶
-
class
openrec.legacy.modules.extractions.
TemporalLatentFactor
(shape, mlp_dims, ids, init='normal', mlp_pretrain=True, l2_reg=None, train=True, scope=None, reuse=False)¶ Build shared computational graphs across training and serving (may be overridden).
-
_build_training_graph
()¶ Build training-specific computational graphs (may be overridden).
-
forward_update_embeddings
(sess)¶ Retrieve update node.
-
pretrain_mlp_as_identity
(sess)¶