<jupyter_start><jupyter_text>TenserBoardのEmbedding Projectorの動作確認<jupyter_code>import os
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.contrib.tensorboard.plugins import projector
LOGS_DIR = '/app/logs'
TMP_DIR = '/app/tmp'
mnist_data_path = os.path.join(TMP_DIR, 'MNIST_data')
mnist = input_data.read_data_sets(mnist_data_path)
images = tf.Variable(mnist.test.images, name='images')
metadata = os.path.join(LOGS_DIR, 'metadata.tsv')
with open(metadata, 'w') as metadata_file:
    for row in mnist.test.labels:
        metadata_file.write('%d\n' % row)
with tf.Session() as sess:
    saver = tf.train.Saver([images])

    sess.run(images.initializer)
    saver.save(sess, os.path.join(LOGS_DIR, 'images.ckpt'))

    config = projector.ProjectorConfig()
    # One can add multiple embeddings.
    embedding = config.embeddings.add()
    embedding.tensor_name = images.name
    # Link this tensor to its metadata file (e.g. labels).
    embedding.metadata_path = metadata
    # Saves a config file that TensorBoard will read during startup.
    projector.visualize_embeddings(tf.summary.FileWriter(LOGS_DIR), config)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 4.872549019607843, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '86524', 'license': 'MIT', 'n_tokens_mistral': 415, 'n_tokens_neox': 410, 'n_words': 85, 'path': 'notebook/check_embedding_projector.ipynb', 'repo_name': 'manba036/bert-as-service', 'size': '1197'}