code: def _prepare_data(self, train_set, val_set):
      nd_positive_rating_values = torch.FloatTensor(
          self.rating_values
      ).to(self.device)
  
      # Prepare Data
      def _generate_labels(ratings):
          labels = torch.LongTensor(
              np.searchsorted(self.rating_values, ratings)
          ).to(self.device)
          return labels
  
      self.train_enc_graph = self._generate_enc_graph(
          train_set, add_support=True
      )
      train_dec_graph = self._generate_dec_graph(train_set)
  
      train_labels = _generate_labels(train_set.uir_tuple[2])
      train_truths = torch.FloatTensor(train_set.uir_tuple[2]).to(
          self.device
      )
  
      def _count_pairs(graph):
          pair_count = 0
          for r_val in self.rating_values:
              r_val = str(r_val).replace(".", "_")
              pair_count += graph.num_edges(str(r_val))
          return pair_count
  
      logging.info(
          "Train enc graph: %s users, %s items, %s pairs",
          self.train_enc_graph.num_nodes("user"),
          self.train_enc_graph.num_nodes("item"),
          _count_pairs(self.train_enc_graph),
      )
  
      logging.info(
          "Train dec graph: %s users, %s items, %s pairs",
          train_dec_graph.num_nodes("user"),
          train_dec_graph.num_nodes("item"),
          train_dec_graph.num_edges(),
      )
  
      valid_enc_graph = self.train_enc_graph
      if val_set:
          valid_dec_graph = self._generate_dec_graph(val_set)
          valid_truths = torch.FloatTensor(val_set.uir_tuple[2]).to(
              self.device
          )
          logging.info(
              "Valid enc graph: %s users, %s items, %s pairs",
              valid_enc_graph.num_nodes("user"),
              valid_enc_graph.num_nodes("item"),
              _count_pairs(valid_enc_graph),
          )
          logging.info(
              "Valid dec graph: %s users, %s items, %s pairs",
              valid_dec_graph.num_nodes("user"),
              valid_dec_graph.num_nodes("item"),
              valid_dec_graph.num_edges(),
          )
      else:
          valid_dec_graph = None
  
      return (
          nd_positive_rating_values,
          train_dec_graph,
          valid_enc_graph,
          valid_dec_graph,
          train_labels,
          train_truths,
          valid_truths,
      )
  
imports: import logging
  import time
  from collections import defaultdict
  import torch
  from torch import nn
  import dgl
  import numpy
  import scipy.sparse
  from tqdm import tqdm
  from .nn_modules import NeuralNetwork
  from .utils import get_optimizer, torch_net_info, torch_total_param_num
label_desc: Use image node_id 6 for calling the Model obj's underlying member method code with example usage: obj._prepare_data(train_set, val_set) and returns: nd_positive_rating_values,  train_dec_graph,  valid_enc_graph,  valid_dec_graph,  train_labels,  train_truths,  valid_truths, labels, pair_count