class openrec.modules.Module(train=True, l2_reg=None, scope=None, reuse=False)[source]

The module is the OpenRec abstraction for modules. A module may belong to one of the three categories, extractions, fusions, and interactions, depending on its functionality (Read [1] for details).

  • train (bool, optional) – 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.


The module abstraction is used to construct recommenders. It should be extended by all module implementations. During initialization, functions self._build_shared_graph, self._build_training_graph, and self._build_serving_graph are called as follows.

The structure of the module abstraction

A module implementation should follow two steps below:

  • Build computational graphs. Override self._build_shared_graph(), self._build_training_graph(), and/or self._build_serving_graph() functions to build training/serving computational graphs.
  • Define a loss and an output list. Define a loss (self._loss) to be included in training and an output list of Tensorflow tensors (self._outputs).


[1]Yang, L., Bagdasaryan, E., Gruenstein, J., Hsieh, C., and Estrin, D., 2018, June. OpenRec: A Modular Framework for Extensible and Adaptable Recommendation Algorithms. In Proceedings of WSDM‘18, February 5-9, 2018, Marina Del Rey, CA, USA.

Build serving-specific computational graphs (may be overridden).


Build shared computational graphs across training and serving (may be overridden).


Build training-specific computational graphs (may be overridden).


Retrieve the training loss.

Returns:Training loss
Return type:float or Tensor

Retrieve the output list of Tensorflow tensors.

Returns:An output list of Tensorflow tensors
Return type:list