<jupyter_start><jupyter_text>Use Tensorboard for Experiments  This tutorial demonstrates how you can use Tensorboard for your experiments. Tensorboard can not just be used with Tensorflow, but also with any other machine learning library via [tensorboardX](https://github.com/lanpa/tensorboardX). ML Lab provides a seamless integration with Tensorboard as shown below.**In this notebook:*** Run two experiments using tensorboard logger* Compare experiments inside workspace using tensorboard viewer * Download tensorboard logs from Lab and compare experiments  Dependencies- _Please use a Python 3 kernel for the notebook_  Import Dependencies<jupyter_code># System libraries
from __future__ import absolute_import, division, print_function
import logging, os, sys, random

# Enable logging
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO, stream=sys.stdout)

# Intialize tqdm to always use the notebook progress bar
import tqdm
tqdm.tqdm = tqdm.tqdm_notebook

# Third-party libraries
import matplotlib.pyplot as plt

# Lab libraries
from lab_client import Environment<jupyter_output><empty_output><jupyter_text>Initialize Environment<jupyter_code># Initialize environment
env = Environment(project="LAB_PROJECT",  # Lab project you want to work on
                  # Only required in stand-alone workspace deployments 
                  # lab_endpoint="LAB_ENDPOINT", 
                  # lab_api_token="LAB_<PASSWORD>"
                 )<jupyter_output><empty_output><jupyter_text>Run Experiments with Tensorboard LoggerImplementation, configuration, and evaluation of the experiments.  Define Experiment<jupyter_code># Define experiment
def run_experiment(exp, params, artifacts):    
    # for this example we will just shuffle all lines in a file
    random.seed(params["seed"])
    
    # Tensorboard Logging
    tensorboard_log = exp.tensorboard_logger
    print("Tensorboard Logger initialized in: " + str(exp.tensorboard_path))
    
    # Log scalar data via tensorboard logger
    for i in range(100):
        tensorboard_log.add_scalar('rand-scalar', random.randint(1,1000), i)
    
    # Log text via tensorboard logger
    tensorboard_log.add_text('Sample Text','this is a sample ' + str(random.randint(1,1000)))
    
    # Log a matplotlib figure via tensorboard logger
    plt.plot([random.randint(1,1000) for i in range(10)])
    tensorboard_log.add_figure(tag="example-figure", figure=plt.gcf())<jupyter_output><empty_output><jupyter_text>For more information on how to log with the tensorboard logger, please refer to the [tensorboardX documentation](https://github.com/lanpa/tensorboardX).  Run ExperimentsRun two experiments with different parameters and upload the experiment with the tensorboard logs.<jupyter_code>tensorboard_logs_keys = []

# Create experiment
exp = env.create_experiment('Tensorboard Example')

# Define parameter configuration for experiment run
params = {
    'seed': 1 
}

# Run experiment and automatically sync all metadata
exp.run_exp(run_experiment, params)
tensorboard_logs_keys.append(exp.exp_metadata.resources.tensorboard_logs)

# Create experiment
exp = env.create_experiment('Tensorboard Example')

# Define parameter configuration for experiment run
params = {
    'seed': 2
}
# Run experiment and automatically sync all metadata
exp.run_exp(run_experiment, params)
tensorboard_logs_keys.append(exp.exp_metadata.resources.tensorboard_logs)

print("Finished both experiments.")
print("Tensorboard logs are saved in Lab following keys: " + str(tensorboard_logs_keys))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07763194638369171, 'fraction_numerical': 0.006422786931024853, 'mean_word_length': 5.1652323580034425, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '176468', 'license': 'Apache-2.0', 'n_tokens_mistral': 997, 'n_tokens_neox': 962, 'n_words': 313, 'path': 'services/lab-workspace/docker-res/tutorials/tutorials/tensorboard-experiment-tutorial.ipynb', 'repo_name': 'Felipe-Renck/machine-learning-lab', 'size': '3576'}