<jupyter_start><jupyter_text>Ch `02`: Concept `08`  Using TensorBoard TensorBoard is a great way to visualize what's happening behind the code. In this example, we'll loop through some numbers to improve our guess of the average value. Then we can visualize the results on TensorBoard. Let's just set ourselves up with some data to work with:<jupyter_code>import tensorflow as tf
import numpy as np

raw_data = np.random.normal(10, 1, 100)<jupyter_output><empty_output><jupyter_text>The moving average is defined as follows:<jupyter_code>alpha = tf.constant(0.05)
curr_value = tf.placeholder(tf.float32)
prev_avg = tf.Variable(0.)

update_avg = alpha * curr_value + (1 - alpha) * prev_avg<jupyter_output><empty_output><jupyter_text>Here's what we care to visualize:<jupyter_code>avg_hist = tf.summary.scalar("running_average", update_avg)
value_hist = tf.summary.scalar("incoming_values", curr_value)

merged = tf.summary.merge_all()
writer = tf.summary.FileWriter("./logs")<jupyter_output><empty_output><jupyter_text>Time to compute the moving averages. We'll also run the `merged` op to track how the values change:<jupyter_code>init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    for i in range(len(raw_data)):
        summary_str, curr_avg = sess.run([merged, update_avg], feed_dict={curr_value: raw_data[i]})
        sess.run(tf.assign(prev_avg, curr_avg))
        print(raw_data[i], curr_avg)
        writer.add_summary(summary_str, i)<jupyter_output>10.7201648998 0.536008
8.48030241652 0.933223
8.30247090956 1.30169
9.24097542488 1.69865
10.2088633934 2.12416
10.3614895822 2.53603
9.37371628589 2.87791
10.9862606878 3.28333
10.9225657991 3.66529
10.4472644201 4.00439
9.99326579845 4.30383
9.57330486057 4.56731
9.45675635064 4.81178
9.9941788904 5.0709
9.09836853805 5.27227
12.0245321032 5.60989
10.2562304744 5.8422
10.1191878763 6.05605
8.70716447101 6.18861
8.90712163427 6.32453
10.5681769153 6.53672
10.9797007819 6.75886
10.6030210585 6.95107
10.9491388896 7.15098
11.6004465495 7.37345
8.91282749896 7.45042
10.763125555 7.61605
9.41257928138 7.70588
9.79326530865 7.81025
9.44668651831 7.89207
9.51611890893 7.97327
10.4691714006 8.09807
9.91965385005 8.18915
11.2162023225 8.3405
9.63270946431 8.40511
9.0511922839 8.43742
7.42832296956 8.38696
9.6116479518 8.44819
9.43684146689 8.49763
10.7361498484 8.60955
8.78547061442 8.61835
10.4454290488 8.7097
10.3123350408 8.78983
12.0810408439 8.95439
10.8530456005 9.04932
9.49097084294 9.[...]
{'fraction_non_alphanumeric': 0.10231814548361311, 'fraction_numerical': 0.3333333333333333, 'mean_word_length': 5.1048780487804875, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '278549', 'license': 'MIT', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1027, 'n_words': 225, 'path': 'tensorflow/Tensorflow-book/ch02_basics/Concept08_TensorBoard.ipynb', 'repo_name': 'gopala-kr/ds-notebooks', 'size': '2502'}