TensorBoard embedding visualizer does not show labels

Viewed 975

I'm trying to use TensorBoard embedding visualizer to represent a set of 7307 verb embeddings that I've just generated, but the plotted points disappears when I select the Enable 3d labels mode.

Here's my code:

def plot(tsne_matrix, labels_path):

PATH  = os.getcwd()
LOG_DIR = PATH
metadata = os.path.join(LOG_DIR, labels_path)

# Setup a 2D tensor that holds the embeddings
words = tf.Variable(tsne_matrix, name = "words")

with tf.Session() as session:

    # Periodically save the model variables in a checkpoint in LOG_DIR.
    saver = tf.train.Saver([words])

    session.run(words.initializer)
    saver.save(session, os.path.join(LOG_DIR, "model.ckpt"))

    config = projector.ProjectorConfig()
    embedding = config.embeddings.add()
    embedding.tensor_name = words.name
    embedding.metadata_path = metadata
    summary_writer = tf.summary.FileWriter(LOG_DIR)
    projector.visualize_embeddings(summary_writer, config)

The metadata that I want to use consists just of the names of the embeddings (in my case verbs). They are stored in a list in a dictionary with other lists, so I'm using this function to load them to a tsv file (the required format):

# Extract list of labels:
def labels2tsv(name, path):
    output = json2dict("output_parsed.json")
    if name == 'verbs':
        labels_list = list(output["verbs"].keys())
    elif name == 'objects':
        labels_list = list(output["objects"].keys())

    with open(path, 'w') as f:
        wr = csv.writer(f, delimiter='\t')
        wr.writerow(str(labels_list))

The code that I execute then is:

# obtain labels
labels2tsv('verbs', 'verbs_metadata.tsv')
labels2tsv('objects', 'objects_metadata.tsv')

# plotting
tsne_verbs = np.load('verbs_tsne.npy')
plot(tsne_verbs, "verbs_metadata.tsv")

Finally, I access to TensorBoard through the command tensorboard --logdir=LOG_DIR.

The generated projector_config.pbtxt file (which is also in LOG_DIR) has the following content:

embeddings {
  tensor_name: "Variable:0"
  metadata_path: "verbs_metadata.tsv"
}

I guess that the points disappear because I'm not doing a correct metadata association, but I can't see the mistake. It also crashes on both Chrome and Firefox.

0 Answers
Related