class_docstr: The Recommender is the OpenRec abstraction [1]_ for recommendation algorithms.
  
  Parameters
  ----------
  batch_size: int
      Training batch size. The structure of a training instance varies across recommenders.
  max_user: int
      Maximum number of users in the recommendation system.
  max_item: int
      Maximum number of items in the recommendation system.
  extra_interactions_funcs: list, optional
      List of functions to build extra interaction modules.
  extra_fusions_funcs: list, optional
      List of functions to build extra fusion modules.
  test_batch_size: int, optional
      Batch size for testing and serving. The structure of a testing/serving instance varies across recommenders.
  l2_reg: float, optional
      Weight for L2 regularization, i.e., weight decay.
  opt: 'SGD'(default) or 'Adam', optional
      Optimization algorithm, SGD: Stochastic Gradient Descent.
  init_dict: dict, optional
      Key-value pairs for initial parameter values.
  sess_config: tensorflow.ConfigProto(), optional
      Tensorflow session configuration.
  
  Notes  
  -----
  .. highlight:: python
  
  The recommender abstraction defines the procedures to build a recommendation computational graph and exposes 
  interfaces for training and evaluation. During training, for each batch, the :code:`self.train` function should be 
  called with a :code:`batch_data` input,
  
  .. code:: python
  
      recommender_instance.train(batch_data)
  
  and during testing/serving, the *serve* function should be called with a *batch_data* input:
  
  .. code:: python
  
      recommender_instance.serve(batch_data)
  
  A recommender contains four major components: **inputs**, **extractions**, **fusions**, and 
  **interactions**. The figure below shows the order of which each related function is called. The 
  :code:`train` parameter in each function is used to build different computational graphs for training 
  and serving.
  
  .. image:: recommender.png
      :scale: 50 %
      :alt: The structure of the recommender abstraction
      :align: center
  
  A new recommender class should be inherent from the *Recommender* class. Follow the steps below to override 
  corresponding functions. To make a recommender easily extensible, it is **NOT** recommended to override functions 
  :code:`self._build_inputs`, :code:`self._build_fusions`, and :code:`self._build_interactions`. 
  
      * **Define inputs.** Override functions :code:`self._build_user_inputs`, :code:`self._build_item_inputs`,         and :code:`self._build_extra_inputs` to define inputs for users', items', and contextual data sources         respectively. An input should be defined using the *input* function as follows.
  
      .. code:: python
  
          self._add_input(name='input_name', dtype='float32', shape=data_shape, train=True)
  
      * **Define input mappings.** Override the function :code:`self._input_mappings` to feed a *batch_data* into         the defined inputs. The mapping should be specified using a python dict where a *key* corresponds to an input         object retrieved by :code:`self._get_input(input_name, train=train)`, and a *value* corresponds to a         :code:`batch_data` value.
  
      * **Define extraction modules.** Override functions :code:`self._build_user_extractions`,         :code:`self._build_item_extractions`, and :code:`self._build_extra_extractions` to define extraction         modules for users, items, and extra contexts respectively. Use :code:`self._add_module` to construct a         module, and :code:`self._get_input`/:code:`self._get_module` to retrieve an existing input/module.
  
      * **Define fusion modules.** Override the function :code:`self._build_default_fusions` to build fusion modules.        Custom functions can also be used as long as they are included in the input :code:`extra_fusions_funcs` list.         Use :code:`self._add_module` to construct a module, and :code:`self._get_input`/:code:`self._get_module` to         retrieve an existing input/module.
  
      * **Define interaction modules.** Override the fuction :code:`build_default_interactions` to build interaction         modules. Custom functions can also be used as long as they are included in the input         :code:`extra_interactions_funcs` list. Use :code:`self._add_module` to construct a module, and         :code:`self._get_input`/:code:`self._get_module` to retrieve an existing input/module.
  
  When (:code:`train==False`), a variable named :code:`self._scores` should be defined for *user-item scores*.     Such a score is higher if an item should be ranked higher in the recommendation list.
  
  References
  ----------
  .. [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.
class_docstr_tok: ["The","Recommender","is","the","OpenRec","abstraction","[","1","]","_","for","recommendation","algorithms",".","Parameters","--","--","--","--","--","batch_size",":","int","Training","batch","size",".","The","structure","of","a","training","instance","varies","across","recommenders",".","max_user",":","int","Maximum","number","of","users","in","the","recommendation","system",".","max_item",":","int","Maximum","number","of","items","in","the","recommendation","system",".","extra_interactions_funcs",":","list",",","optional","List","of","functions","to","build","extra","interaction","modules",".","extra_fusions_funcs",":","list",",","optional","List","of","functions","to","build","extra","fusion","modules",".","test_batch_size",":","int",",","optional","Batch","size","for","testing","and","serving",".","The","structure","of","a","testing\/serving","instance","varies","across","recommenders",".","l2_reg",":","float",",","optional","Weight","for","L2","regularization",",","i.e.",",","weight","decay",".","opt",":","'SGD","'","(","default",")","or","'Adam","'",",","optional","Optimization","algorithm",",","SGD",":","Stochastic","Gradient","Descent",".","init_dict",":","dict",",","optional","Key-value","pairs","for","initial","parameter","values",".","sess_config",":","tensorflow.ConfigProto","(",")",",","optional","Tensorflow","session","configuration",".","Notes","--","--","-","..","highlight",":",":","python","The","recommender","abstraction","defines","the","procedures","to","build","a","recommendation","computational","graph","and","exposes","interfaces","for","training","and","evaluation",".","During","training",",","for","each","batch",",","the",":","code",":","`","self.train","`","function","should","be","called","with","a",":","code",":","`","batch_data","`","input",",","..","code",":",":","python","recommender_instance.train","(","batch_data",")","and","during","testing\/serving",",","the","*","serve","*","function","should","be","called","with","a","*","batch_data","*","input",":","..","code",":",":","python","recommender_instance.serve","(","batch_data",")","A","recommender","contains","four","major","components",":","*","*","inputs","*","*",",","*","*","extractions","*","*",",","*","*","fusions","*","*",",","and","*","*","interactions","*","*",".","The","figure","below","shows","the","order","of","which","each","related","function","is","called",".","The",":","code",":","`","train","`","parameter","in","each","function","is","used","to","build","different","computational","graphs","for","training","and","serving",".","..","image",":",":","recommender.png",":","scale",":","50","%",":","alt",":","The","structure","of","the","recommender","abstraction",":","align",":","center","A","new","recommender","class","should","be","inherent","from","the","*","Recommender","*","class",".","Follow","the","steps","below","to","override","corresponding","functions",".","To","make","a","recommender","easily","extensible",",","it","is","*","*","NOT","*","*","recommended","to","override","functions",":","code",":","`","self._build_inputs","`",",",":","code",":","`","self._build_fusions","`",",","and",":","code",":","`","self._build_interactions","`",".","*","*","*","Define","inputs",".","*","*","Override","functions",":","code",":","`","self._build_user_inputs","`",",",":","code",":","`","self._build_item_inputs","`",",","and",":","code",":","`","self._build_extra_inputs","`","to","define","inputs","for","users","'",",","items","'",",","and","contextual","data","sources","respectively",".","An","input","should","be","defined","using","the","*","input","*","function","as","follows",".","..","code",":",":","python","self._add_input","(","name='input_name","'",",","dtype='float32","'",",","shape=data_shape",",","train=True",")","*","*","*","Define","input","mappings",".","*","*","Override","the","function",":","code",":","`","self._input_mappings","`","to","feed","a","*","batch_data","*","into","the","defined","inputs",".","The","mapping","should","be","specified","using","a","python","dict","where","a","*","key","*","corresponds","to","an","input","object","retrieved","by",":","code",":","`","self._get_input","(","input_name",",","train=train",")","`",",","and","a","*","value","*","corresponds","to","a",":","code",":","`","batch_data","`","value",".","*","*","*","Define","extraction","modules",".","*","*","Override","functions",":","code",":","`","self._build_user_extractions","`",",",":","code",":","`","self._build_item_extractions","`",",","and",":","code",":","`","self._build_extra_extractions","`","to","define","extraction","modules","for","users",",","items",",","and","extra","contexts","respectively",".","Use",":","code",":","`","self._add_module","`","to","construct","a","module",",","and",":","code",":","`","self._get_input","`","\/",":","code",":","`","self._get_module","`","to","retrieve","an","existing","input\/module",".","*","*","*","Define","fusion","modules",".","*","*","Override","the","function",":","code",":","`","self._build_default_fusions","`","to","build","fusion","modules",".","Custom","functions","can","also","be","used","as","long","as","they","are","included","in","the","input",":","code",":","`","extra_fusions_funcs","`","list",".","Use",":","code",":","`","self._add_module","`","to","construct","a","module",",","and",":","code",":","`","self._get_input","`","\/",":","code",":","`","self._get_module","`","to","retrieve","an","existing","input\/module",".","*","*","*","Define","interaction","modules",".","*","*","Override","the","fuction",":","code",":","`","build_default_interactions","`","to","build","interaction","modules",".","Custom","functions","can","also","be","used","as","long","as","they","are","included","in","the","input",":","code",":","`","extra_interactions_funcs","`","list",".","Use",":","code",":","`","self._add_module","`","to","construct","a","module",",","and",":","code",":","`","self._get_input","`","\/",":","code",":","`","self._get_module","`","to","retrieve","an","existing","input\/module",".","When","(",":","code",":","`","train==False","`",")",",","a","variable","named",":","code",":","`","self._scores","`","should","be","defined","for","*","user-item","scores","*",".","Such","a","score","is","higher","if","an","item","should","be","ranked","higher","in","the","recommendation","list",".","References","--","--","--","--","--","..","[","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","."]
docstr: Compute the loss of a module, specified by the name and the train flag.
  
  Parameters
  ----------
  name: str
      The module name.
  batch_data: dict
      A batch of training or serving data.
  train: bool
      Specify the computational graph (train/serving) to compute loss.
  
  Returns
  -------
  Numpy array
      The loss of the specified module.
docstr_tok: ["Compute","the","loss","of","a","module",",","specified","by","the","name","and","the","train","flag",".","Parameters","--","--","--","--","--","name",":","str","The","module","name",".","batch_data",":","dict","A","batch","of","training","or","serving","data",".","train",":","bool","Specify","the","computational","graph","(","train\/serving",")","to","compute","loss",".","Returns","--","--","--","-","Numpy","array","The","loss","of","the","specified","module","."]
code: def compute_module_loss(self, name, batch_data, train=True):
      """Compute the loss of a module, specified by the name and the train flag.
  
      Parameters
      ----------
      name: str
          The module name.
      batch_data: dict
          A batch of training or serving data.
      train: bool
          Specify the computational graph (train/serving) to compute loss.
  
      Returns
      -------
      Numpy array
          The loss of the specified module.
      """
  
      module = self._get_module(name=name, train=train)
  
      if type(module.get_loss()) == float:
          return module.get_loss()
  
      return self._sess.run(
          module.get_loss(),
          feed_dict=self._input_mappings(batch_data, train=train),
      )
  
imports: import tensorflow
  import numpy
label_desc: Use image node_id 5 for calling the Recommender obj's underlying member method code with example usage: obj.compute_module_loss(name, batch_data, train) and returns: self, module