Embedding visualization with TensorFlow eager execution

Viewed 356

I am using TensorFlow's eager execution and I would like to visualize embeddings in TensorBoard. I use the following code to setup the visualization:

self._writer = tf.contrib.summary.create_file_writer('path')
embedding_config = projector.ProjectorConfig()
embedding = embedding_config.embeddings.add()
embedding.tensor_name = self._word_embeddings.name
embedding.metadata_path = 'metadata.tsv'
projector.visualize_embeddings(self._writer, embedding_config)

where self._word_embeddings is my variable for the embeddings. However, when executing this script TensorFlow throws the following error message:

logdir = summary_writer.get_logdir()
AttributeError: 'SummaryWriter' object has no attribute 'get_logdir'

Has anybody experienced something similar and has an idea how to get the embedding visualization to run in eager mode?

I am using TensorFlow 1.10.0.

Any kind of help is greatly appreciated!

1 Answers

If you only care about visualization, and since you are working in eager mode, things can be much simpler.

As I can see, you already have your metadata.TSV file set. The only thing left, is to write your embedding matrix to a TSV file. Like, just a for loop over the matrix rows, with the values TAB separated.

Last step, you can load the tensorboard projector online, without installing it via: http://projector.tensorflow.org/ and upload your data. You have to upload the embedding file, and the metadata file separately, in two simple steps.

Related