docstr: A TensorRec recommendation model.
  :param n_components: Integer
  The dimension of a single output of the representation function. Must be >= 1.
  :param n_tastes: Integer
  The number of tastes/reprs to be calculated for each user. Must be >= 1.
  :param user_repr_graph: AbstractRepresentationGraph
  An object which inherits AbstractRepresentationGraph that contains a method to calculate user representations.
  See tensorrec.representation_graphs for examples.
  :param item_repr_graph: AbstractRepresentationGraph
  An object which inherits AbstractRepresentationGraph that contains a method to calculate item representations.
  See tensorrec.representation_graphs for examples.
  :param attention_graph: AbstractRepresentationGraph or None
  Optional. An object which inherits AbstractRepresentationGraph that contains a method to calculate user
  attention. Any valid repr_graph is also a valid attention graph. If None, no attention process will be applied.
  :param prediction_graph: AbstractPredictionGraph
  An object which inherits AbstractPredictionGraph that contains a method to calculate predictions from a pair of
  user/item reprs.
  See tensorrec.prediction_graphs for examples.
  :param loss_graph: AbstractLossGraph
  An object which inherits AbstractLossGraph that contains a method to calculate the loss function.
  See tensorrec.loss_graphs for examples.
  :param biased: bool
  If True, a bias value will be calculated for every user feature and item feature.
code: def __init__(
      self,
      n_components=100,
      n_tastes=1,
      user_repr_graph=LinearRepresentationGraph(),
      item_repr_graph=LinearRepresentationGraph(),
      attention_graph=None,
      prediction_graph=DotProductPredictionGraph(),
      loss_graph=RMSELossGraph(),
      biased=True,
  ):
      """
      A TensorRec recommendation model.
      :param n_components: Integer
      The dimension of a single output of the representation function. Must be >= 1.
      :param n_tastes: Integer
      The number of tastes/reprs to be calculated for each user. Must be >= 1.
      :param user_repr_graph: AbstractRepresentationGraph
      An object which inherits AbstractRepresentationGraph that contains a method to calculate user representations.
      See tensorrec.representation_graphs for examples.
      :param item_repr_graph: AbstractRepresentationGraph
      An object which inherits AbstractRepresentationGraph that contains a method to calculate item representations.
      See tensorrec.representation_graphs for examples.
      :param attention_graph: AbstractRepresentationGraph or None
      Optional. An object which inherits AbstractRepresentationGraph that contains a method to calculate user
      attention. Any valid repr_graph is also a valid attention graph. If None, no attention process will be applied.
      :param prediction_graph: AbstractPredictionGraph
      An object which inherits AbstractPredictionGraph that contains a method to calculate predictions from a pair of
      user/item reprs.
      See tensorrec.prediction_graphs for examples.
      :param loss_graph: AbstractLossGraph
      An object which inherits AbstractLossGraph that contains a method to calculate the loss function.
      See tensorrec.loss_graphs for examples.
      :param biased: bool
      If True, a bias value will be calculated for every user feature and item feature.
      """
  
      # Check TensorFlow version
      major, minor, patch = tf.__version__.split(".")
      if int(major) < 1 or int(major) == 1 and int(minor) < 7:
          raise TfVersionException(tf_version=tf.__version__)
  
      # Arg Check
      if (
          (n_components is None)
          or (n_tastes is None)
          or (user_repr_graph is None)
          or (item_repr_graph is None)
          or (prediction_graph is None)
          or (loss_graph is None)
      ):
          raise ValueError(
              "All arguments to TensorRec() must be non-None"
          )
      if n_components < 1:
          raise ValueError("n_components must be >= 1")
      if n_tastes < 1:
          raise ValueError("n_tastes must be >= 1")
      if not isinstance(user_repr_graph, AbstractRepresentationGraph):
          raise ValueError(
              "user_repr_graph must inherit AbstractRepresentationGraph"
          )
      if not isinstance(item_repr_graph, AbstractRepresentationGraph):
          raise ValueError(
              "item_repr_graph must inherit AbstractRepresentationGraph"
          )
      if not isinstance(prediction_graph, AbstractPredictionGraph):
          raise ValueError(
              "prediction_graph must inherit AbstractPredictionGraph"
          )
      if not isinstance(loss_graph, AbstractLossGraph):
          raise ValueError("loss_graph must inherit AbstractLossGraph")
      if attention_graph is not None:
          if not isinstance(
              attention_graph, AbstractRepresentationGraph
          ):
              raise ValueError(
                  "attention_graph must be None or inherit AbstractRepresentationGraph"
              )
          if n_tastes == 1:
              raise ValueError(
                  "attention_graph must be None if n_tastes == 1"
              )
  
      self.n_components = n_components
      self.n_tastes = n_tastes
      self.user_repr_graph_factory = user_repr_graph
      self.item_repr_graph_factory = item_repr_graph
      self.attention_graph_factory = attention_graph
      self.prediction_graph_factory = prediction_graph
      self.loss_graph_factory = loss_graph
      self.biased = biased
  
      # A list of the attr names of every graph hook attr
      self.graph_tensor_hook_attr_names = [
          # Top-level API nodes
          "tf_user_representation",
          "tf_item_representation",
          "tf_prediction_serial",
          "tf_prediction",
          "tf_rankings",
          "tf_predict_similar_items",
          "tf_rank_similar_items",
          # Training nodes
          "tf_basic_loss",
          "tf_weight_reg_loss",
          "tf_loss",
          # Feed placeholders
          "tf_learning_rate",
          "tf_alpha",
          "tf_sample_indices",
          "tf_n_sampled_items",
          "tf_similar_items_ids",
      ]
      if self.biased:
          self.graph_tensor_hook_attr_names += [
              "tf_projected_user_biases",
              "tf_projected_item_biases",
          ]
      if self.attention_graph_factory is not None:
          self.graph_tensor_hook_attr_names += [
              "tf_user_attention_representation"
          ]
  
      self.graph_operation_hook_attr_names = [
          # AdamOptimizer
          "tf_optimizer",
      ]
      self.graph_iterator_hook_attr_names = [
          # Input data iterators
          "tf_user_feature_iterator",
          "tf_item_feature_iterator",
          "tf_interaction_iterator",
      ]
  
      # Calling the break routine during __init__ creates all the attrs on the TensorRec object with an initial value
      # of None
      self._break_graph_hooks()
  
      # A map of every graph hook attr name to the node name after construction
      # Tensors and operations are stored separated because they are handled differently by TensorFlow
      self.graph_tensor_hook_node_names = {}
      self.graph_operation_hook_node_names = {}
      self.graph_iterator_hook_node_names = {}
  
imports: from functools import partial
  from itertools import cycle
  import logging
  import numpy
  import os
  import pickle
  from scipy import sparse
  import tensorflow
  from .errors import ModelNotBiasedException, ModelNotFitException, ModelWithoutAttentionException, BatchNonSparseInputException, TfVersionException
  from .input_utils import create_tensorrec_iterator, get_dimensions_from_tensorrec_dataset
  from .loss_graphs import AbstractLossGraph, RMSELossGraph
  from .prediction_graphs import AbstractPredictionGraph, DotProductPredictionGraph
  from .recommendation_graphs import project_biases, split_sparse_tensor_indices, bias_prediction_dense, bias_prediction_serial, rank_predictions, densify_sampled_item_predictions, collapse_mixture_of_tastes, predict_similar_items
  from .representation_graphs import AbstractRepresentationGraph, LinearRepresentationGraph
  from .session_management import get_session
  from .util import sample_items, calculate_batched_alpha, datasets_from_raw_input
label_desc: Use image node_id 1 to create a new TensorRec object from inherited base classes: object with example: obj = TensorRec(n_components, n_tastes, user_repr_graph, item_repr_graph, attention_graph, prediction_graph, loss_graph, biased)