code: def triplet_network(base_network, embedding_dims=2, embedding_l2=0.0):
      """Creates a triplet Siamese Neural Network from a base_network.
      The base network will have an extra Dense layer of the requested embedding_dims added to
      the end if embedding_dims is not None.
  
      The outputs of the three network heads will be stacked into the shape:
      (3, batch_size, embedding_dims) unless embedding_dims is None (in which case the existing dims
      of last base_network layer will be used).
  
      Outputs: tuple(
          model: tf.keras.models.Model. The constructed triplet Siamese network
          embeddings: [tf.keras.layers.Dense, tf.keras.layers.Dense, tf.keras.layers.Dense].
          Results of applying the base_network to triplet inputs -
          anchor, positive and negative respectively.
      )"""
  
      def output_shape(shapes):
          shape1, _, _ = shapes
          return (
              3,
              shape1[0],
          )
  
      input_a = Input(shape=base_network.input_shape[1:])
      input_p = Input(shape=base_network.input_shape[1:])
      input_n = Input(shape=base_network.input_shape[1:])
  
      if embedding_dims is None:
          embeddings = base_network.output
      else:
          embeddings = Dense(
              embedding_dims, kernel_regularizer=l2(embedding_l2)
          )(base_network.output)
  
      network = Model(base_network.input, embeddings)
  
      processed_a = network(input_a)
      processed_p = network(input_p)
      processed_n = network(input_n)
  
      triplet = Lambda(
          K.stack, output_shape=output_shape, name="stacked_triplets"
      )(
          [processed_a, processed_p, processed_n],
      )
      model = Model([input_a, input_p, input_n], triplet)
  
      return model, (processed_a, processed_p, processed_n)
  
file_path: ivis/ivis/nn/network.py
imports: from functools import partial
  import numpy
  from tensorflow.keras import regularizers
  from tensorflow.keras.models import Model, Sequential
  from tensorflow.keras.layers import Input, Dense, AlphaDropout, Lambda
  from tensorflow.keras import backend
  from tensorflow.keras.regularizers import l2
  from .losses import is_categorical, is_hinge, is_multiclass, validate_sparse_labels
label_desc: Use image node_id 2 for calling a global function with example usage: triplet_network(base_network, embedding_dims, embedding_l2) and returns: model,  processed_a,  processed_p,  processed_n, int,  shape1