code: def trim_model_checkpoint(
      parameters_filepath,
      dataset_filepath,
      input_checkpoint_filepath,
      output_checkpoint_filepath,
  ):
      """
      Remove all token embeddings except UNK.
      """
      parameters, _ = neuromodel.load_parameters(
          parameters_filepath=parameters_filepath
      )
      dataset = pickle.load(open(dataset_filepath, "rb"))
      model = EntityLSTM(dataset, parameters)
      with tf.Session() as sess:
          model_saver = (
              tf.train.Saver()
          )  # defaults to saving all variables
  
          # Restore the pretrained model
          model_saver.restore(
              sess, input_checkpoint_filepath
          )  # Works only when the dimensions of tensor variables are matched.
  
          # Get pretrained embeddings
          token_embedding_weights = sess.run(
              model.token_embedding_weights
          )
  
          # Restore the sizes of token embedding weights
          utils_tf.resize_tensor_variable(
              sess,
              model.token_embedding_weights,
              [1, parameters["token_embedding_dimension"]],
          )
  
          initial_weights = sess.run(model.token_embedding_weights)
          initial_weights[
              dataset.UNK_TOKEN_INDEX
          ] = token_embedding_weights[dataset.UNK_TOKEN_INDEX]
          sess.run(
              tf.assign(
                  model.token_embedding_weights,
                  initial_weights,
                  validate_shape=False,
              )
          )
  
          token_embedding_weights = sess.run(
              model.token_embedding_weights
          )
          print(
              "token_embedding_weights: {0}".format(
                  token_embedding_weights
              )
          )
  
          model_saver.save(sess, output_checkpoint_filepath)
  
      dataset.__dict__["vocabulary_size"] = 1
      pickle.dump(dataset, open(dataset_filepath, "wb"))
      pprint(dataset.__dict__)
  
file_path: NeuroNER/neuroner/prepare_pretrained_model.py
imports: import glob
  import os
  import pickle
  from pprint import pprint
  import shutil
  import utils
  from entity_lstm import EntityLSTM
  import tensorflow
  from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
  from neuroner import utils_tf
  from neuroner import neuromodel
label_desc: Use image node_id 2 for calling a global function with example usage: trim_model_checkpoint(parameters_filepath, dataset_filepath, input_checkpoint_filepath, output_checkpoint_filepath) without return types