Interactions¶
Interaction¶
PairwiseLog¶

class
openrec.modules.interactions.
PairwiseLog
(user, item=None, item_bias=None, p_item=None, p_item_bias=None, n_item=None, n_item_bias=None, train=None, scope=None, reuse=False)[source]¶ The PairwiseLog module minimizes the pairwise logarithm loss [bpr] as follows (regularization and bias terms are not included):
\[\min \sum_{(i, p, n)} ln\sigma (u_i^T v_p  u_i^T v_n)\]where \(u_i\) denotes the representation for user \(i\); \(v_p\) and \(v_n\) denote representations for positive item \(p\) and negative item \(n\), respectively.
Parameters:  user (Tensorflow tensor) – Representations for users involved in the interactions. Shape: [number of interactions, dimensionality of user representations].
 item (Tensorflow tensor, required for testing) – Representations for items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 item_bias (Tensorflow tensor, required for testing) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 p_item (Tensorflow tensor, required for training) – Representations for positive items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 p_item_bias (Tensorflow tensor, required for training) – Biases for positive items involved in the interactions. Shape: [number of interactions, 1].
 n_item (Tensorflow tensor, required for training) – Representations for negative items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 n_item_bias (Tensorflow tensor, required for training) – Biases for negative items involved in the interactions. Shape: [number of interactions, 1].
 train (bool, optionl) – An indicator for training or serving phase.
 scope (str, optional) – Scope for module variables.
 reuse (bool, optional) – Whether or not to reuse module variables.
References
[bpr] Rendle, S., Freudenthaler, C., Gantner, Z. and SchmidtThieme, L., 2009, June. BPR: Bayesian personalized ranking from implicit feedback. In Proceedings of the twentyfifth conference on uncertainty in artificial intelligence (pp. 452461). AUAI Press.
PairwiseEuDist¶

class
openrec.modules.interactions.
PairwiseEuDist
(user, item=None, item_bias=None, p_item=None, p_item_bias=None, n_item=None, n_item_bias=None, weights=1.0, margin=1.0, train=None, scope=None, reuse=False)[source]¶ The PairwiseEuDist module minimizes the weighted pairwise euclidean distancebased hinge loss [cml] as follows (regularization and bias terms are not included):
\[\min \sum_{(i, p, n)} w_{ip} [m + \lVert c(u_i)c(v_p) \lVert^2  \lVert c(u_i)c(v_n) \lVert^2]_+\]where \(c(x) = \frac{x}{\max(\lVert x \lVert, 1.0)}\); \(u_i\) denotes the representation for user \(i\); \(v_p\) and \(v_n\) denote representations for positive item \(p\) and negative item \(n\), respectively.
Parameters:  user (Tensorflow tensor) – Representations for users involved in the interactions. Shape: [number of interactions, dimensionality of user representations].
 item (Tensorflow tensor, required for testing) – Representations for items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 item_bias (Tensorflow tensor, required for testing) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 p_item (Tensorflow tensor, required for training) – Representations for positive items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 p_item_bias (Tensorflow tensor, required for training) – Biases for positive items involved in the interactions. Shape: [number of interactions, 1].
 n_item (Tensorflow tensor, required for training) – Representations for negative items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 n_item_bias (Tensorflow tensor, required for training) – Biases for negative items involved in the interactions. Shape: [number of interactions, 1].
 weights (Tensorflow tensor, optional) – Weights \(w\). Shape: [number of interactions, 1].
 margin (float, optional) – Margin \(m\). Default to 1.0.
 train (bool, optionl) – An indicator for training or serving phase.
 scope (str, optional) – Scope for module variables.
 reuse (bool, optional) – Whether or not to reuse module variables.
References
[cml] Hsieh, C.K., Yang, L., Cui, Y., Lin, T.Y., Belongie, S. and Estrin, D., 2017, April. Collaborative metric learning. In Proceedings of the 26th International Conference on World Wide Web (pp. 193201). International World Wide Web Conferences Steering Committee.
PointwiseGeCE¶

class
openrec.modules.interactions.
PointwiseGeCE
(user, item, item_bias, l2_reg=None, labels=None, train=None, scope=None, reuse=False)[source]¶ The PointwiseGeCE module minimizes the cross entropy classification loss with generalized dot product as logits. The generalized dotproduct [ncf] between user representation \(u_i\) and item representation \(v_j\) is defined as:
\[h^T(u_i \odot v_j)\]where \(\odot\) denotes elementwise dot product of two vectors, and \(h\) denotes learnable model parameters.
Parameters:  user (Tensorflow tensor) – Representations for users involved in the interactions. Shape: [number of interactions, dimensionality of user representations].
 item (Tensorflow tensor) – Representations for items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 item_bias (Tensorflow tensor) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 labels (Tensorflow tensor, required for training.) – Groundtruth labels for the interactions. Shape [number of interactions, ].
 l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
 train (bool, optionl) – An indicator for training or servining phase.
 scope (str, optional) – Scope for module variables.
 reuse (bool, optional) – Whether or not to reuse module variables.
References
[ncf] (1, 2, 3) He, X., Liao, L., Zhang, H., Nie, L., Hu, X. and Chua, T.S., 2017, April. Neural collaborative filtering. In Proceedings of the 26th International Conference on World Wide Web (pp. 173182). International World Wide Web Conferences Steering Committee.
PointwiseGeMLPCE¶

class
openrec.modules.interactions.
PointwiseGeMLPCE
(user_mlp, user_ge, item_mlp, item_ge, item_bias, dims, labels=None, dropout=None, alpha=0.5, l2_reg=None, train=None, scope=None, reuse=False)[source]¶ The PointwiseGeMLPCE module minimizes the cross entropy classification loss. The logits are calculated as follows [ncf] (Bias term is not included).
\[\alpha h^T(u_i^{ge} \odot v_j^{ge}) + (1  \alpha)MLP([u_i^{mlp}, v_j^{mlp}])\]Parameters:  user_mlp (Tensorflow tensor) – \(u^{mlp}\) for users involved in the interactions. Shape: [number of interactions, dimensionality of \(u^{mlp}\)].
 user_ge (Tensorflow tensor) – \(u^{ge}\) for users involved in the interactions. Shape: [number of interactions, dimensionality of \(u^{ge}\)].
 item_mlp (Tensorflow tensor) – \(v^{mlp}\) for items involved in the interactions. Shape: [number of interactions, dimensionality of \(v^{mlp}\)].
 item_ge (Tensorflow tensor) – \(v^{ge}\) for items involved in the interactions. Shape: [number of interactions, dimensionality of \(v^{ge}\)].
 item_bias (Tensorflow tensor) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 dims (Numpy array.) – Specify the size of the MLP (openrec.modules.extractions.MultiLayerFC).
 labels (Tensorflow tensor, required for training.) – Groundtruth labels for the interactions. Shape [number of interactions, ].
 dropout (float, optional.) – Dropout rate for MLP (intermediate layers only).
 alpha (float, optional.) – Value of \(\alpha\). Default to 0.5.
 l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
 train (bool, optionl) – An indicator for training or servining phase.
 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).
PointwiseMLPCE¶

class
openrec.modules.interactions.
PointwiseMLPCE
(user, item, dims, item_bias=None, extra=None, l2_reg=None, labels=None, dropout=None, train=None, batch_serving=True, scope=None, reuse=False)[source]¶ The PointwiseMLPCE module minimizes the cross entropy classification loss with outputs of a MultiLayer Perceptron (MLP) as logits. The inputs to the MLP are the concatenation between user and item representations [ncf].
Parameters:  user (Tensorflow tensor) – Representations for users involved in the interactions. Shape: [number of interactions, dimensionality of user representations].
 item (Tensorflow tensor) – Representations for items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 dims (Numpy array.) – Specify the size of the MLP (openrec.modules.extractions.MultiLayerFC).
 item_bias (Tensorflow tensor, optional) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 extra (Tensorflow tensor, optional) – Representations for context involved in the interactions. Shape: [number of interaction, dimensionality of context representations]
 l2_reg (float, optional) – Weight for L2 regularization, i.e., weight decay.
 labels (Tensorflow tensor, required for training.) – Groundtruth labels for the interactions. Shape [number of interactions, ].
 dropout (float, optional) – Dropout rate for MLP (intermediate layers only).
 train (bool, optional) – An indicator for training or servining phase.
 batch_serving (bool, optional) – An indicator for batch serving / pointwise serving.
 scope (str, optional) – Scope for module variables.
 reuse (bool, optional) – Whether or not to reuse module variables.
PointwiseMSE¶

class
openrec.modules.interactions.
PointwiseMSE
(user, item, item_bias, labels=None, a=1.0, b=1.0, sigmoid=False, train=True, batch_serving=True, scope=None, reuse=False)[source]¶ The PointwiseMSE module minimizes the pointwise meansqureerror [ctm] as follows (regularization terms are not included):
\[\min \sum_{ij}c_{ij}(r_{ij}  u_i^T v_j)^2\]where \(u_i\) and \(v_j\) are representations for user \(i\) and item \(j\) respectively; \(c_{ij}=a\) if \(r_{ij}=1\), otherwise \(c_{ij}=b\).
Parameters:  user (Tensorflow tensor) – Representations for users involved in the interactions. Shape: [number of interactions, dimensionality of user representations].
 item (Tensorflow tensor) – Representations for items involved in the interactions. Shape: [number of interactions, dimensionality of item representations].
 item_bias (Tensorflow tensor) – Biases for items involved in the interactions. Shape: [number of interactions, 1].
 labels (Tensorflow tensor, required for training) – Groundtruth labels for the interactions. Shape [number of interactions, ].
 a (float, optional) – The value of \(c_{ij}\) if \(r_{ij}=1\).
 b (float, optional) – The value of \(c_{ij}\) if \(r_{ij}=0\).
 sigmoid (bool, optional) – Normalize the dot products, i.e., sigmoid(\(u_i^T v_j\)).
 train (bool, optionl) – An indicator for training or servining phase.
 batch_serving (bool, optional) – If True, the model calculates scores for all users against all items, and returns scores with shape [len(user), len(item)]. Otherwise, it returns scores for specified user item pairs (require
len(user)==len(item)
).  scope (str, optional) – Scope for module variables.
 reuse (bool, optional) – Whether or not to reuse module variables.
References
[ctm] Wang, C. and Blei, D.M., 2011, August. Collaborative topic modeling for recommending scientific articles. In Proceedings of the 17th ACM SIGKDD international conference on Knowledge discovery and data mining (pp. 448456). ACM.