<jupyter_start><jupyter_text>Exercise 04.02 - Building a policy network with TensorFlow Import required modules<jupyter_code>import numpy as np 
import gym 
import tensorflow as tf<jupyter_output><empty_output><jupyter_text>Instantiate the environment<jupyter_code>env = gym.make('CartPole-v0')<jupyter_output><empty_output><jupyter_text>Print out action and observation spaces<jupyter_code>print("Action space =", env.action_space)  
print("Observation space =", env.observation_space)<jupyter_output>Action space = Discrete(2)
Observation space = Box(4,)<jupyter_text>Print out action and observation dimensions<jupyter_code>print("Action space dimension =", env.action_space.n)  
print("Observation space dimension =", env.observation_space.shape[0])<jupyter_output>Action space dimension = 2
Observation space dimension = 4<jupyter_text>Build the policy network and print its summary<jupyter_code>model = tf.keras.Sequential([ 
        tf.keras.layers.Dense(64, activation='relu', 
                         input_shape=[env.observation_space.shape[0]]), 
        tf.keras.layers.Dense(64, activation='relu'), 
        tf.keras.layers.Dense(env.action_space.n, activation="softmax") 
]) 

model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 64)                320       
_________________________________________________________________
dense_1 (Dense)              (None, 64)                4160      
_________________________________________________________________
dense_2 (Dense)              (None, 2)                 130       
=================================================================
Total params: 4,610
Trainable params: 4,610
Non-trainable params: 0
_________________________________________________________________
{'fraction_non_alphanumeric': 0.14822335025380712, 'fraction_numerical': 0.02081218274111675, 'mean_word_length': 4.631428571428572, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '107202', 'license': 'MIT', 'n_tokens_mistral': 546, 'n_tokens_neox': 499, 'n_words': 103, 'path': 'Chapter04/Exercise04_02/Exercise04_02.ipynb', 'repo_name': 'adityashah95/The-Reinforcement-Learning-Workshop', 'size': '1970'}