code: def _make_functional_regularized_model(distance_config):
      """Makes a model with `PairwiseDistance` and the functional API."""
  
      def _make_unregularized_model(inputs, num_classes):
          """Makes standard 1 layer MLP with logistic regression."""
          x = tf.keras.layers.Dense(16, activation="relu")(inputs)
          model = tf.keras.Model(
              inputs, tf.keras.layers.Dense(num_classes)(x)
          )
          return model
  
      # Each example has 4 features and 2 neighbors, each with an edge weight.
      inputs = (
          tf.keras.Input(shape=(4,), dtype=tf.float32, name="features"),
          tf.keras.Input(
              shape=(2, 4), dtype=tf.float32, name="neighbors"
          ),
          tf.keras.Input(
              shape=(2, 1), dtype=tf.float32, name="neighbor_weights"
          ),
      )
      features, neighbors, neighbor_weights = inputs
      neighbors = tf.reshape(
          neighbors, (-1,) + tuple(features.shape[1:])
      )
      neighbor_weights = tf.reshape(neighbor_weights, [-1, 1])
      unregularized_model = _make_unregularized_model(features, 3)
      logits = unregularized_model(features)
      model = tf.keras.Model(inputs=inputs, outputs=logits)
      # Add regularization.
      regularizer = layers.PairwiseDistance(distance_config)
      graph_loss = regularizer(
          sources=logits,
          targets=unregularized_model(neighbors),
          weights=neighbor_weights,
      )
      model.add_loss(graph_loss)
      model.add_metric(
          graph_loss, aggregation="mean", name="graph_loss"
      )
      return model
  
file_path: neural-structured-learning/neural_structured_learning/keras/layers/layers_test.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import itertools
  from absl.testing import parameterized
  from neural_structured_learning import configs
  from neural_structured_learning.keras import layers
  import numpy
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: _make_functional_regularized_model(distance_config) and returns: model, model