code: def create_tensorboard_visualizations(
      model,
      loc,
      entities_subset="all",
      labels=None,
      write_metadata=True,
      export_tsv_embeddings=True,
  ):
      """Export embeddings to Tensorboard.
  
      This function exports embeddings to disk in a format used by
      `TensorBoard <https://www.tensorflow.org/tensorboard>`_ and
      `TensorBoard Embedding Projector <https://projector.tensorflow.org>`_.
      The function exports:
  
      * A number of checkpoint and graph embedding files in the provided location that will allow
        the visualization of the embeddings using Tensorboard. This is generally for use with a
        `local Tensorboard instance <https://www.tensorflow.org/tensorboard/r1/overview>`_.
      * A tab-separated file of embeddings named `embeddings_projector.tsv`. This is generally used to
        visualize embeddings by uploading to `TensorBoard Embedding Projector <https://projector.tensorflow.org>`_.
      * Embeddings metadata (i.e., the embedding labels from the original knowledge graph) saved to in a file named
          `metadata.tsv``. Such file can be used in TensorBoard or uploaded to TensorBoard Embedding Projector.
  
      The content of ``loc`` will look like: ::
  
          tensorboard_files/
              ├── checkpoint
              ├── embeddings_projector.tsv
              ├── graph_embedding.ckpt.data-00000-of-00001
              ├── graph_embedding.ckpt.index
              ├── graph_embedding.ckpt.meta
              ├── metadata.tsv
              └── projector_config.pbtxt
  
      .. Note ::
          A TensorBoard guide is available `here <https://www.tensorflow.org/tensorboard/r1/overview>`_.
  
      .. Note ::
          Uploading `embeddings_projector.tsv` and `metadata.tsv` to
          `TensorBoard Embedding Projector <https://projector.tensorflow.org>`_ will give a result
          similar to the picture below:
  
          .. image:: ../img/embeddings_projector.png
  
      Example
      -------
      >>> # create model and compile using user defined optimizer settings and user defined settings of an existing loss
      >>> from ampligraph.latent_features import ScoringBasedEmbeddingModel
      >>> from ampligraph.latent_features.loss_functions import SelfAdversarialLoss
      >>> import tensorflow as tf
      >>> optim = tf.optimizers.Adam(learning_rate=0.01)
      >>> loss = SelfAdversarialLoss({'margin': 0.1, 'alpha': 5, 'reduction': 'sum'})
      >>> model = ScoringBasedEmbeddingModel(eta=5,
      >>>                                    k=300,
      >>>                                    scoring_type='ComplEx',
      >>>                                    seed=0)
      >>> model.compile(optimizer=optim, loss=loss)
      >>> model.fit('./fb15k-237/train.txt',
      >>>           batch_size=10000,
      >>>           epochs=5)
      Epoch 1/5
      29/29 [==============================] - 2s 67ms/step - loss: 13101.9443
      Epoch 2/5
      29/29 [==============================] - 1s 20ms/step - loss: 11907.5771
      Epoch 3/5
      29/29 [==============================] - 1s 21ms/step - loss: 10890.3447
      Epoch 4/5
      29/29 [==============================] - 1s 20ms/step - loss: 9520.3994
      Epoch 5/5
      29/29 [==============================] - 1s 20ms/step - loss: 8314.7529
      >>> from ampligraph.utils import create_tensorboard_visualizations
      >>> create_tensorboard_visualizations(model,
                                            entities_subset='all',
                                            loc = './full_embeddings_vis')
      >>> # On terminal run: tensorboard --logdir='./full_embeddings_vis' --port=8891
      >>> # Open the browser and go to the following URL: http://127.0.0.1:8891/#projector
  
  
      Parameters
      ----------
      model: EmbeddingModel
          A trained neural knowledge graph embedding model, the model must be an instance of TransE,
          DistMult, ComplEx, or HolE.
      loc: str
          Directory where the files are written.
      entities_subset: list
          List of entities whose embeddings have to be visualized.
      labels: pd.DataFrame
          Label(s) for each embedding point in the Tensorboard visualization.
          Default behaviour is to use the embedding labels included in the model.
      export_tsv_embeddings: bool
           If `True` (default), will generate a tab-separated file of embeddings at the given path.
           This is generally used to visualize embeddings by uploading to
           `TensorBoard Embedding Projector <https://projector.tensorflow.org>`_.
      write_metadata: bool
          If `True` (default), will write a file named `'metadata.tsv'` in the same directory as path.
  
      """
  
      # Create loc if it doesn't exist
      if not os.path.exists(loc):
          logger.debug(
              "Creating Tensorboard visualization directory: %s" % loc
          )
          os.mkdir(loc)
  
      if not model.is_fit():
          raise ValueError(
              "Cannot write embeddings if model is not fitted."
          )
  
      if entities_subset != "all":
          assert isinstance(
              entities_subset, list
          ), "Please pass a list of entities of entities_subset!"
  
      if entities_subset == "all":
          entities_index = np.arange(model.get_count("e"))
  
          entities_label = list(
              model.get_indexes(
                  entities_index, type_of="e", order="ind2raw"
              )
          )
      else:
          entities_index = model.get_indexes(
              entities_subset, type_of="e", order="raw2ind"
          )
          entities_label = entities_subset
  
      if labels is not None:
          # Check if the lengths of the supplied labels is equal to the number of embeddings retrieved
          if len(labels) != len(entities_label):
              raise ValueError(
                  "Label data rows must equal number of embeddings."
              )
      else:
          # If no label data supplied, use model ent_to_idx keys as labels
          labels = entities_label
  
      if write_metadata:
          logger.debug("Writing metadata.tsv to: %s" % loc)
          write_metadata_tsv(loc, labels)
  
      embeddings = model.get_embeddings(entities_label)
  
      if export_tsv_embeddings:
          tsv_filename = "embeddings_projector.tsv"
          logger.info(
              "Writing embeddings tsv to: %s"
              % os.path.join(loc, tsv_filename)
          )
          np.savetxt(
              os.path.join(loc, tsv_filename),
              embeddings,
              delimiter="\t",
          )
  
      # Create a checkpoint with the embeddings only
      embeddings = tf.Variable(embeddings, name="graph_embeddings")
      checkpoint = tf.train.Checkpoint(KGE_embeddings=embeddings)
      checkpoint.save(os.path.join(loc, "graph_embeddings.ckpt"))
  
      # create a config to display the embeddings in the checkpoint
      config = projector.ProjectorConfig()
      embedding = config.embeddings.add()
      embedding.tensor_name = (
          "KGE_embeddings/.ATTRIBUTES/VARIABLE_VALUE"
      )
      embedding.metadata_path = "metadata.tsv"
      projector.visualize_embeddings(loc, config)
  
file_path: AmpliGraph/ampligraph/utils/model_utils.py
imports: import glob
  import logging
  import os
  import pickle
  import shutil
  from time import gmtime, strftime
  import numpy
  import pandas
  import tensorflow
  from tensorboard.plugins import projector
label_desc: Use image node_id 3 for calling a global function with example usage: create_tensorboard_visualizations(model, loc, entities_subset, labels, write_metadata, export_tsv_embeddings) without return types