Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/C5 - Sequence Models/Week 1/Building a Recurrent Neural Network - Step by Step/generateTestCases.py
Views: 4819
# New Generate Test Cases1from solutions import *2import numpy as np3import math4import os,sys5# import tensorflow as tf6sys.path.append('../')7sys.path.append('../../')89from grader_support import stdout_redirector10from grader_support import util111213mFiles = [14"rnn_cell_forward.py",15"rnn_forward.py",16"lstm_cell_forward.py",17"lstm_forward.py"18]1920# generating test cases for rnn_cell_forward212223xt = np.random.randn(3,6)24a_prev = np.random.randn(4,6)25Waa = np.random.randn(4,4)26Wax = np.random.randn(4,3)27Wya = np.random.randn(2,4)28ba = np.random.randn(4,1)29by = np.random.randn(2,1)30parameters = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}3132a_next, yt_pred, cache = rnn_cell_forward(xt, a_prev, parameters)3334# -------------------------------------------------------3536# generating test cases for rnn_forward373839x1 = np.random.randn(3,6,4)40a01 = np.random.randn(4,6)41parameters1 = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}42a, y_pred, caches = rnn_forward(x1, a01, parameters1)4344# -------------------------------------------------------45# generate test cases for lstm_cell_forward46xt1 = np.random.randn(3,4)47a_prev1 = np.random.randn(5,4)48c_prev1 = np.random.randn(5,4)49Wf = np.random.randn(5, 5+3)50bf = np.random.randn(5,1)51Wi = np.random.randn(5, 5+3)52bi = np.random.randn(5,1)53Wo = np.random.randn(5, 5+3)54bo = np.random.randn(5,1)55Wc = np.random.randn(5, 5+3)56bc = np.random.randn(5,1)57Wy = np.random.randn(2,5)58by = np.random.randn(2,1)59parameters2 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}60a_next_lstm, c_next_lstm, yt_lstm, cache_lstm = lstm_cell_forward(xt1, a_prev1, c_prev1, parameters2)6162# -------------------------------------------------------63# generate test cases for lstm_cell_forward64# lstm_forward6566np.random.seed(1)67x2 = np.random.randn(3,10,4)68a02 = np.random.randn(5,10)69Wf = np.random.randn(5, 5+3)70bf = np.random.randn(5,1)71Wi = np.random.randn(5, 5+3)72bi = np.random.randn(5,1)73Wo = np.random.randn(5, 5+3)74bo = np.random.randn(5,1)75Wc = np.random.randn(5, 5+3)76bc = np.random.randn(5,1)77Wy = np.random.randn(2,5)78by = np.random.randn(2,1)7980parameters3 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}8182af, yf, cf, cachesf = lstm_forward(x2, a02, parameters3)8384def generateTestCases():85testCases = {86'rnn_cell_forward': {87'partId': 'KrqbT',88'testCases': [89{90'testInput': (xt, a_prev, parameters),91'testOutput': (a_next, yt_pred, cache)92}93]94},95'rnn_forward': {96'partId': 'CzGAI',97'testCases': [98{99'testInput': (x1, a01, parameters1),100'testOutput': (a, y_pred, caches)101}102]103},104'lstm_cell_forward': {105'partId': '7tvdt',106'testCases': [107{108'testInput': (xt1, a_prev1, c_prev1, parameters2),109'testOutput': (a_next_lstm, c_next_lstm, yt_lstm, cache_lstm)110}111]112},113'lstm_forward': {114'partId': 'SAQvR',115'testCases': [116{117'testInput': (x2, a02, parameters3),118'testOutput': (af, yf, cf, cachesf)119}120]121}122}123return testCases124125126127