# Define early stopping callback early_stop = keras.callbacks.EarlyStopping( monitor="loss", patience=3, min_delta=0.001 ) # Define TensorBoard callback logdir = os.path.join(".", "logs/fit/" + datetime.now().strftime("%Y%m%d-%H%M%S")) tensorboard_callback = keras.callbacks.TensorBoard(log_dir=logdir) # Model Input left_inputs, right_inputs, similarity = process_model_input(data) # Train the encoder model history = encoder.fit( [left_inputs, right_inputs], similarity, batch_size=8, epochs=20, validation_split=0.2, callbacks=[early_stop, tensorboard_callback], ) # Define model input inputs = keras.Input(shape=[], dtype=tf.string) # Pass the input through the embedding layer embedding = hub.KerasLayer(embedding_layer)(inputs) # Create the tuned model tuned_model = keras.Model(inputs=inputs, outputs=embedding)