class_docstr: Builds a TFR estimator with subscore signatures of GAM models.
  
  Neural Generalized Additive Ranking Model is an additive ranking model.
  See the paper (https://arxiv.org/abs/2005.02553) for more details.
  For each example x with n features (x_1, x_2, ..., x_n), the ranking score is:
  
  F(x) = f1(x_1) + f2(x_2) + ... + fn(x_n)
  
  where each feature is scored by a corresponding submodel, and the overall
  ranking score is the sum of all the submodels' outputs. Each submodel is a
  standalone feed-forward network.
  
  When there are m context features (c_1, c_2, ..., c_m), the ranking score
  will be determined by:
  
  F(c, x) = w1(c) * f1(x_1) + w2(c) * f2(x_2) + ... + wn(c) * fn(x_n)
  
  where (w1(c), w2(c), ..., wn(c)) is a weighting vector determined solely by
  context features. For each context feature c_j, a feed-forward submodel is
  constructed to derive a weighting vector (wj1(c_j), wj2(c_j), ..., wjn(c_j)).
  The final weighting vector is the sum of the output of all the context
  features' submodels.
  
  The model is implicitly interpretable as the contribution of each feature to
  the final ranking score can be easily visualized. However, the model does not
  have higher-order inter-feature interactions and hence may not have
  performance as good as the fully-connected DNN.
  
  The output of each example feature's submodel can be retrieved by tensor
  named `{feature_name}_subscore`. The output of each context feature's submodel
  is a n-dimensional vector and can be retrieved by tensor named
  `{feature_name}_subweight`.
class_docstr_tok: ["Builds","a","TFR","estimator","with","subscore","signatures","of","GAM","models",".","Neural","Generalized","Additive","Ranking","Model","is","an","additive","ranking","model",".","See","the","paper","(","https",":","\/\/arxiv.org\/abs\/2005.02553",")","for","more","details",".","For","each","example","x","with","n","features","(","x_1",",","x_2",",","...",",","x_n",")",",","the","ranking","score","is",":","F","(","x",")","=","f1","(","x_1",")","+","f2","(","x_2",")","+","...","+","fn","(","x_n",")","where","each","feature","is","scored","by","a","corresponding","submodel",",","and","the","overall","ranking","score","is","the","sum","of","all","the","submodels","'","outputs",".","Each","submodel","is","a","standalone","feed-forward","network",".","When","there","are","m","context","features","(","c_1",",","c_2",",","...",",","c_m",")",",","the","ranking","score","will","be","determined","by",":","F","(","c",",","x",")","=","w1","(","c",")","*","f1","(","x_1",")","+","w2","(","c",")","*","f2","(","x_2",")","+","...","+","wn","(","c",")","*","fn","(","x_n",")","where","(","w1","(","c",")",",","w2","(","c",")",",","...",",","wn","(","c",")",")","is","a","weighting","vector","determined","solely","by","context","features",".","For","each","context","feature","c_j",",","a","feed-forward","submodel","is","constructed","to","derive","a","weighting","vector","(","wj1","(","c_j",")",",","wj2","(","c_j",")",",","...",",","wjn","(","c_j",")",")",".","The","final","weighting","vector","is","the","sum","of","the","output","of","all","the","context","features","'","submodels",".","The","model","is","implicitly","interpretable","as","the","contribution","of","each","feature","to","the","final","ranking","score","can","be","easily","visualized",".","However",",","the","model","does","not","have","higher-order","inter-feature","interactions","and","hence","may","not","have","performance","as","good","as","the","fully-connected","DNN",".","The","output","of","each","example","feature","'s","submodel","can","be","retrieved","by","tensor","named","`","{","feature_name","}","_subscore","`",".","The","output","of","each","context","feature","'s","submodel","is","a","n-dimensional","vector","and","can","be","retrieved","by","tensor","named","`","{","feature_name","}","_subweight","`","."]
docstr: Wraps model_fn with additional signatures of subscores.
docstr_tok: ["Wraps","model_fn","with","additional","signatures","of","subscores","."]
code: def _model_fn(self):
      """Wraps model_fn with additional signatures of subscores."""
  
      def _gam_model_fn(features, labels, mode, params, config):
          """Redefines the model_fn for GAM to include subscore signatures."""
          estimator_spec = super(GAMEstimatorBuilder, self)._model_fn()(
              features, labels, mode, params, config
          )
          if mode == tf_estimator.ModeKeys.PREDICT:
              # Export subscores of each feature.  Find nodes ending with
              # `_SUBSCORE_POSTFIX` and `_SUBWEIGHT_POSTFIX` and create signatures
              # with their corresponding tensors as outputs.  Signatures for example
              # feature sub-scores are regression signatures, and signatures for
              # context feature weighting vectors are prediction signatures.
              subscore_signatures = {}
              for node in (
                  tf.compat.v1.get_default_graph().as_graph_def().node
              ):
                  if node.name.endswith(_SUBSCORE_POSTFIX):
                      subscore_name = node.name[
                          node.name.rfind("/") + 1 :
                      ]
                      subscore_tensor = tf.compat.v1.get_default_graph().get_tensor_by_name(
                          "{}:0".format(node.name)
                      )
                      subscore_signatures[
                          subscore_name
                      ] = tf_estimator.export.RegressionOutput(
                          subscore_tensor
                      )  # pylint: disable=g-deprecated-tf-checker
                  elif node.name.endswith(_SUBWEIGHT_POSTFIX):
                      subscore_name = node.name[
                          node.name.rfind("/") + 1 :
                      ]
                      subscore_tensor = tf.compat.v1.get_default_graph().get_tensor_by_name(
                          "{}:0".format(node.name)
                      )
                      subscore_signatures[
                          subscore_name
                      ] = tf_estimator.export.PredictOutput(
                          subscore_tensor
                      )  # pylint: disable=g-deprecated-tf-checker
  
              estimator_spec.export_outputs.update(subscore_signatures)
          return estimator_spec
  
      return _gam_model_fn
  
imports: import tensorflow
  from tensorflow import estimator
  from tensorflow.python.util import function_utils
  from tensorflow_ranking.python import feature
  from tensorflow_ranking.python import head
  from tensorflow_ranking.python import losses
  from tensorflow_ranking.python import metrics
  from tensorflow_ranking.python import model
  from tensorflow_ranking.python import utils
label_desc: Use image node_id 1 for calling the GAMEstimatorBuilder obj's underlying member method code with example usage: obj._model_fn() and returns: _gam_model_fn, estimator_spec