MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / bottom_data_is

Method bottom_data_is

lstm_code/nicodjimenez/lstm.py:80–97  ·  view source on GitHub ↗
(self, x, s_prev = None, h_prev = None)

Source from the content-addressed store, hash-verified

78 self.xc = None
79
80 def bottom_data_is(self, x, s_prev = None, h_prev = None):
81 # if this is the first lstm node in the network
82 if s_prev == None: s_prev = np.zeros_like(self.state.s)
83 if h_prev == None: h_prev = np.zeros_like(self.state.h)
84 # save data for use in backprop
85 self.s_prev = s_prev
86 self.h_prev = h_prev
87
88 # concatenate x(t) and h(t-1)
89 xc = np.hstack((x, h_prev))
90 self.state.g = np.tanh(np.dot(self.param.wg, xc) + self.param.bg)
91 self.state.i = sigmoid(np.dot(self.param.wi, xc) + self.param.bi)
92 self.state.f = sigmoid(np.dot(self.param.wf, xc) + self.param.bf)
93 self.state.o = sigmoid(np.dot(self.param.wo, xc) + self.param.bo)
94 self.state.s = self.state.g * self.state.i + s_prev * self.state.f
95 self.state.h = self.state.s * self.state.o
96 self.x = x
97 self.xc = xc
98
99 def top_diff_is(self, top_diff_h, top_diff_s):
100 # notice that top_diff_s is carried along the constant error carousel

Callers 1

x_list_addMethod · 0.80

Calls 1

sigmoidFunction · 0.70

Tested by

no test coverage detected