docstr: Define the model in keras
docstr_tok: ["Define","the","model","in","keras"]
code: def _define_model(self):
      """Define the model in keras"""
  
      # network outputs
      outputs = {}
  
      # inputs
      if self.parametric_embedding:
          to_x = tf.keras.layers.Input(shape=self.dims, name="to_x")
          from_x = tf.keras.layers.Input(shape=self.dims, name="from_x")
          inputs = [to_x, from_x]
  
          # parametric embedding
          embedding_to = self.encoder(to_x)
          embedding_from = self.encoder(from_x)
  
          if self.parametric_reconstruction:
              # parametric reconstruction
              if self.autoencoder_loss:
                  embedding_to_recon = self.decoder(embedding_to)
              else:
                  # stop gradient of reconstruction loss before it reaches the encoder
                  embedding_to_recon = self.decoder(
                      tf.stop_gradient(embedding_to)
                  )
  
              embedding_to_recon = tf.keras.layers.Lambda(
                  lambda x: x, name="reconstruction"
              )(embedding_to_recon)
  
              outputs["reconstruction"] = embedding_to_recon
  
      else:
          # this is the sham input (it's just a 0) to make keras think there is input data
          batch_sample = tf.keras.layers.Input(
              shape=(1), dtype=tf.int32, name="batch_sample"
          )
  
          # gather all of the edges (so keras model is happy)
          to_x = tf.squeeze(tf.gather(self.head, batch_sample[0]))
          from_x = tf.squeeze(tf.gather(self.tail, batch_sample[0]))
  
          # grab relevant embeddings
          embedding_to = self.encoder(to_x)[:, -1, :]
          embedding_from = self.encoder(from_x)[:, -1, :]
  
          inputs = [batch_sample]
  
      # concatenate to/from projections for loss computation
      embedding_to_from = tf.concat(
          [embedding_to, embedding_from], axis=1
      )
      embedding_to_from = tf.keras.layers.Lambda(
          lambda x: x, name="umap"
      )(embedding_to_from)
      outputs["umap"] = embedding_to_from
  
      if self.global_correlation_loss_weight > 0:
          outputs["global_correlation"] = tf.keras.layers.Lambda(
              lambda x: x, name="global_correlation"
          )(embedding_to)
  
      # create model
  
      # self.parametric_model = tf.keras.Model(inputs=inputs, outputs=outputs)
      self.parametric_model = GradientClippedModel(
          inputs=inputs, outputs=outputs
      )
  
imports: import numpy
  from umap import UMAP
  from warnings import warn, catch_warnings, filterwarnings
  from numba import TypingError
  import os
  from umap.spectral import spectral_layout
  from sklearn.utils import check_random_state
  import codecs, pickle
  from sklearn.neighbors import KDTree
  import sys
label_desc: Use image node_id 6 for calling the ParametricUMAP obj's underlying member method code with example usage: obj._define_model() without return types