CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
amanchadha

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: amanchadha/coursera-deep-learning-specialization
Path: blob/master/C5 - Sequence Models/Week 1/Building a Recurrent Neural Network - Step by Step/generateTestCases.py
Views: 4819
1
# New Generate Test Cases
2
from solutions import *
3
import numpy as np
4
import math
5
import os,sys
6
# import tensorflow as tf
7
sys.path.append('../')
8
sys.path.append('../../')
9
10
from grader_support import stdout_redirector
11
from grader_support import util
12
13
14
mFiles = [
15
"rnn_cell_forward.py",
16
"rnn_forward.py",
17
"lstm_cell_forward.py",
18
"lstm_forward.py"
19
]
20
21
# generating test cases for rnn_cell_forward
22
23
24
xt = np.random.randn(3,6)
25
a_prev = np.random.randn(4,6)
26
Waa = np.random.randn(4,4)
27
Wax = np.random.randn(4,3)
28
Wya = np.random.randn(2,4)
29
ba = np.random.randn(4,1)
30
by = np.random.randn(2,1)
31
parameters = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}
32
33
a_next, yt_pred, cache = rnn_cell_forward(xt, a_prev, parameters)
34
35
# -------------------------------------------------------
36
37
# generating test cases for rnn_forward
38
39
40
x1 = np.random.randn(3,6,4)
41
a01 = np.random.randn(4,6)
42
parameters1 = {"Waa": Waa, "Wax": Wax, "Wya": Wya, "ba": ba, "by": by}
43
a, y_pred, caches = rnn_forward(x1, a01, parameters1)
44
45
# -------------------------------------------------------
46
# generate test cases for lstm_cell_forward
47
xt1 = np.random.randn(3,4)
48
a_prev1 = np.random.randn(5,4)
49
c_prev1 = np.random.randn(5,4)
50
Wf = np.random.randn(5, 5+3)
51
bf = np.random.randn(5,1)
52
Wi = np.random.randn(5, 5+3)
53
bi = np.random.randn(5,1)
54
Wo = np.random.randn(5, 5+3)
55
bo = np.random.randn(5,1)
56
Wc = np.random.randn(5, 5+3)
57
bc = np.random.randn(5,1)
58
Wy = np.random.randn(2,5)
59
by = np.random.randn(2,1)
60
parameters2 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}
61
a_next_lstm, c_next_lstm, yt_lstm, cache_lstm = lstm_cell_forward(xt1, a_prev1, c_prev1, parameters2)
62
63
# -------------------------------------------------------
64
# generate test cases for lstm_cell_forward
65
# lstm_forward
66
67
np.random.seed(1)
68
x2 = np.random.randn(3,10,4)
69
a02 = np.random.randn(5,10)
70
Wf = np.random.randn(5, 5+3)
71
bf = np.random.randn(5,1)
72
Wi = np.random.randn(5, 5+3)
73
bi = np.random.randn(5,1)
74
Wo = np.random.randn(5, 5+3)
75
bo = np.random.randn(5,1)
76
Wc = np.random.randn(5, 5+3)
77
bc = np.random.randn(5,1)
78
Wy = np.random.randn(2,5)
79
by = np.random.randn(2,1)
80
81
parameters3 = {"Wf": Wf, "Wi": Wi, "Wo": Wo, "Wc": Wc, "Wy": Wy, "bf": bf, "bi": bi, "bo": bo, "bc": bc, "by": by}
82
83
af, yf, cf, cachesf = lstm_forward(x2, a02, parameters3)
84
85
def generateTestCases():
86
testCases = {
87
'rnn_cell_forward': {
88
'partId': 'KrqbT',
89
'testCases': [
90
{
91
'testInput': (xt, a_prev, parameters),
92
'testOutput': (a_next, yt_pred, cache)
93
}
94
]
95
},
96
'rnn_forward': {
97
'partId': 'CzGAI',
98
'testCases': [
99
{
100
'testInput': (x1, a01, parameters1),
101
'testOutput': (a, y_pred, caches)
102
}
103
]
104
},
105
'lstm_cell_forward': {
106
'partId': '7tvdt',
107
'testCases': [
108
{
109
'testInput': (xt1, a_prev1, c_prev1, parameters2),
110
'testOutput': (a_next_lstm, c_next_lstm, yt_lstm, cache_lstm)
111
}
112
]
113
},
114
'lstm_forward': {
115
'partId': 'SAQvR',
116
'testCases': [
117
{
118
'testInput': (x2, a02, parameters3),
119
'testOutput': (af, yf, cf, cachesf)
120
}
121
]
122
}
123
}
124
return testCases
125
126
127