code: def nn_model_fn(features, labels, mode):
      """NN adapted from github.com/hexiangnan/neural_collaborative_filtering."""
      n_latent_factors_user = 10
      n_latent_factors_movie = 10
      n_latent_factors_mf = 5
  
      user_input = tf.reshape(features["user"], [-1, 1])
      item_input = tf.reshape(features["movie"], [-1, 1])
  
      # number of users: 6040; number of movies: 3706
      mf_embedding_user = tf.keras.layers.Embedding(
          6040, n_latent_factors_mf, input_length=1
      )
      mf_embedding_item = tf.keras.layers.Embedding(
          3706, n_latent_factors_mf, input_length=1
      )
      mlp_embedding_user = tf.keras.layers.Embedding(
          6040, n_latent_factors_user, input_length=1
      )
      mlp_embedding_item = tf.keras.layers.Embedding(
          3706, n_latent_factors_movie, input_length=1
      )
  
      # GMF part
      # Flatten the embedding vector as latent features in GMF
      mf_user_latent = tf.keras.layers.Flatten()(
          mf_embedding_user(user_input)
      )
      mf_item_latent = tf.keras.layers.Flatten()(
          mf_embedding_item(item_input)
      )
      # Element-wise multiply
      mf_vector = tf.keras.layers.multiply(
          [mf_user_latent, mf_item_latent]
      )
  
      # MLP part
      # Flatten the embedding vector as latent features in MLP
      mlp_user_latent = tf.keras.layers.Flatten()(
          mlp_embedding_user(user_input)
      )
      mlp_item_latent = tf.keras.layers.Flatten()(
          mlp_embedding_item(item_input)
      )
      # Concatenation of two latent features
      mlp_vector = tf.keras.layers.concatenate(
          [mlp_user_latent, mlp_item_latent]
      )
  
      predict_vector = tf.keras.layers.concatenate(
          [mf_vector, mlp_vector]
      )
  
      logits = tf.keras.layers.Dense(5)(predict_vector)
  
      # Calculate loss as a vector (to support microbatches in DP-SGD).
      vector_loss = tf.nn.sparse_softmax_cross_entropy_with_logits(
          labels=labels, logits=logits
      )
      # Define mean of loss across minibatch (for reporting through tf.Estimator).
      scalar_loss = tf.reduce_mean(vector_loss)
  
      # Configure the training op (for TRAIN mode).
      if mode == tf_estimator.ModeKeys.TRAIN:
          if FLAGS.dpsgd:
              # Use DP version of GradientDescentOptimizer. Other optimizers are
              # available in dp_optimizer. Most optimizers inheriting from
              # tf.compat.v1.train.Optimizer should be wrappable in differentially
              # private counterparts by calling dp_optimizer.optimizer_from_args().
              optimizer = dp_optimizer.DPAdamGaussianOptimizer(
                  l2_norm_clip=FLAGS.l2_norm_clip,
                  noise_multiplier=FLAGS.noise_multiplier,
                  num_microbatches=microbatches,
                  learning_rate=FLAGS.learning_rate,
              )
              opt_loss = vector_loss
          else:
              optimizer = tf.compat.v1.train.AdamOptimizer(
                  learning_rate=FLAGS.learning_rate
              )
              opt_loss = scalar_loss
  
          global_step = tf.compat.v1.train.get_global_step()
          train_op = optimizer.minimize(
              loss=opt_loss, global_step=global_step
          )
          # In the following, we pass the mean of the loss (scalar_loss) rather than
          # the vector_loss because tf.estimator requires a scalar loss. This is only
          # used for evaluation and debugging by tf.estimator. The actual loss being
          # minimized is opt_loss defined above and passed to optimizer.minimize().
          return tf_estimator.EstimatorSpec(
              mode=mode, loss=scalar_loss, train_op=train_op
          )
  
      # Add evaluation metrics (for EVAL mode).
      if mode == tf_estimator.ModeKeys.EVAL:
          eval_metric_ops = {
              "rmse": tf.compat.v1.metrics.root_mean_squared_error(
                  labels=tf.cast(labels, tf.float32),
                  predictions=tf.tensordot(
                      a=tf.nn.softmax(logits, axis=1),
                      b=tf.constant(
                          np.array([0, 1, 2, 3, 4]), dtype=tf.float32
                      ),
                      axes=1,
                  ),
              )
          }
          return tf_estimator.EstimatorSpec(
              mode=mode,
              loss=scalar_loss,
              eval_metric_ops=eval_metric_ops,
          )
      return None
  
file_path: privacy/tutorials/movielens_tutorial.py
imports: from absl import app
  from absl import flags
  import numpy
  import pandas
  from scipy import stats
  from sklearn.model_selection import train_test_split
  import tensorflow
  from tensorflow import estimator
  from tensorflow.compat.v1 import estimator
  from tensorflow_privacy.privacy.analysis.gdp_accountant import compute_eps_poisson
  from tensorflow_privacy.privacy.analysis.gdp_accountant import compute_mu_poisson
  from tensorflow_privacy.privacy.optimizers import dp_optimizer
label_desc: Use image node_id 1 for calling a global function with example usage: nn_model_fn(features, labels, mode) and returns: None, tf_estimator, tf_estimator