The diagram below displays the Reinforcement Learning (RL) agent-environment loop. The Q-learning agent takes actions (up/down/left/right) in the grid-world environment. In return, the environment provides the new state and rewards, which are used to update the Q-table values.
2. Part 1: Step-by-Step Action Items & Key Execution Steps
STEP 1
Activate Python Virtual Environment
Point the terminal execution environment to the course conda sandbox environment.
$ conda activate ds_ai_ml
This targets active python libraries to the isolated virtual sandbox.
STEP 2
Create Project Folders inside Linux VM
Create a dedicated folder for the project files inside your guest VM home folder directory.
$ mkdir -p ~/Projects/emerging_ai && cd ~/Projects/emerging_ai
This sets up the working directory layout for the emerging AI code files.
STEP 3
Install TTS packages via Pip
Install the Google Text-to-Speech library inside the active conda session.
$ pip install gTTS numpy matplotlib
This installs the `gTTS` library to convert text statements into MP3 audio outputs.
STEP 4
Create Q-learning script file in VS Code
Launch VS Code and create the RL training script file.
Launch VS Code via terminal "code ." -> New File -> Type: q_learning_grid.py -> Paste Python code -> Save file
This registers the grid environment and tabular Q-learning algorithm in `q_learning_grid.py`.
STEP 5
Execute Reinforcement Learning training
Run the script to train the RL agent and output the learned Q-table.
$ python q_learning_grid.py
This runs Q-learning training episodes, prints the final learned Q-table, and saves a TTS audio file.
STEP 6
Verify generated TTS output
Play the generated MP3 file to confirm the text-to-speech conversion was successful.
$ aplay voice_output.mp3
This runs the default audio player inside your VM to play the output file. (If `aplay` is missing, you can skip audio playback checks).
3. Reinforcement Learning Execution Flow
The flowchart below outlines the reinforcement learning execution flow. It details the steps from setting hyperparameter values to updating Q-table values and running policy checks.
4. Part 2: Complete Deliverable Assets & Production Templates
To run the demonstrations, we need the Python script file. Below is a line-by-line explanation of the code, followed by the combined template.
Step-by-Step Code Construction
Lines 1 - 6
Import tabular and TTS modules
Include system packages, Numpy arrays, Google Text-to-Speech libraries, and mathematical modules in the script.
import numpy as np
from gtts import gTTS
import os
import random
These imports pull standard Numpy arrays, gTTS API wrappers, and random selection generators.
Lines 7 - 18
Define Grid World Environment
Define a 4x4 Grid World environment with starting, trap, and goal coordinates.