MCPcopy Index your code
hub / github.com/rushter/MLAlgorithms / TimeDistributedDense

Class TimeDistributedDense

mla/neuralnet/layers/basic.py:150–183  ·  view source on GitHub ↗

Apply regular Dense layer to every timestep.

Source from the content-addressed store, hash-verified

148
149
150class TimeDistributedDense(Layer):
151 """Apply regular Dense layer to every timestep."""
152
153 def __init__(self, output_dim):
154 self.output_dim = output_dim
155 self.n_timesteps = None
156 self.dense = None
157 self.input_dim = None
158
159 def setup(self, X_shape):
160 self.dense = Dense(self.output_dim)
161 self.dense.setup((X_shape[0], X_shape[2]))
162 self.input_dim = X_shape[2]
163
164 def forward_pass(self, X):
165 n_timesteps = X.shape[1]
166 X = X.reshape(-1, X.shape[-1])
167 y = self.dense.forward_pass(X)
168 y = y.reshape((-1, n_timesteps, self.output_dim))
169 return y
170
171 def backward_pass(self, delta):
172 n_timesteps = delta.shape[1]
173 X = delta.reshape(-1, delta.shape[-1])
174 y = self.dense.backward_pass(X)
175 y = y.reshape((-1, n_timesteps, self.input_dim))
176 return y
177
178 @property
179 def parameters(self):
180 return self.dense._params
181
182 def shape(self, x_shape):
183 return x_shape[0], x_shape[1], self.output_dim

Callers 1

addition_problemFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected