<jupyter_start><jupyter_text>1. Importing Dependencies<jupyter_code>import gym 
from stable_baselines3 import A2C
from stable_baselines3.common.vec_env import VecFrameStack
from stable_baselines3.common.evaluation import evaluate_policy
from stable_baselines3.common.env_util import make_atari_env
import os<jupyter_output><empty_output><jupyter_text>2. Environment<jupyter_code>environment_name = "Breakout-v0"
env = gym.make(environment_name)
episodes = 5
for episode in range(1, episodes+1):
    state = env.reset()
    done = False
    score = 0 
    
    while not done:
        env.render()
        action = env.action_space.sample()
        n_state, reward, done, info = env.step(action)
        score+=reward
    print('Episode:{} Score:{}'.format(episode, score))
env.close()
env.action_space
env.observation_space<jupyter_output><empty_output><jupyter_text>3. Training a model<jupyter_code>from stable_baselines3.common.vec_env import DummyVecEnv
env = gym.make(environment_name)
env = DummyVecEnv([lambda: env])
model = A2C('MlpPolicy', env, verbose = 1)
model.learn(total_timesteps=20000)
episodes = 5
for episode in range(1, episodes+1):
    obs = env.reset()
    done = False
    score = 0 
    
    while not done:
        
        env.render()
        action, _ = model.predict(obs)
        obs, reward, done, info = env.step(action)
        score+=reward
    print('Episode:{} Score:{}'.format(episode, score))
env.close()<jupyter_output><empty_output><jupyter_text>4. Training a model using vectorized environments<jupyter_code>env = make_atari_env('Breakout-v0', n_envs=4, seed=0)
env = VecFrameStack(env, n_stack=4)
model = A2C('CnnPolicy', env, verbose = 1)
model.learn(total_timesteps=1000)<jupyter_output><empty_output><jupyter_text>5. Evaluating the model<jupyter_code>env = make_atari_env('Breakout-v0', n_envs=1, seed=0)
env = VecFrameStack(env, n_stack=4)
evaluate_policy(model, env, n_eval_episodes=10, render=True)
env.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11738035264483627, 'fraction_numerical': 0.021662468513853905, 'mean_word_length': 5.167701863354037, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '322666', 'license': 'Apache-2.0', 'n_tokens_mistral': 731, 'n_tokens_neox': 707, 'n_words': 135, 'path': 'Atari.ipynb', 'repo_name': 'kindawingingit/RL', 'size': '1985'}