keras 0.2.0__py2.7.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +11 -0
- EGG-INFO/SOURCES.txt +51 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/requires.txt +6 -0
- EGG-INFO/top_level.txt +1 -0
- EGG-INFO/zip-safe +1 -0
- keras/__init__.py +15 -0
- keras/__init__.pyc +0 -0
- keras/activations.py +49 -0
- keras/activations.pyc +0 -0
- keras/backend/__init__.py +39 -0
- keras/backend/__init__.pyc +0 -0
- keras/backend/common.py +31 -0
- keras/backend/common.pyc +0 -0
- keras/backend/tensorflow_backend.py +602 -0
- keras/backend/tensorflow_backend.pyc +0 -0
- keras/backend/theano_backend.py +622 -0
- keras/backend/theano_backend.pyc +0 -0
- keras/callbacks.py +295 -0
- keras/callbacks.pyc +0 -0
- keras/constraints.py +45 -0
- keras/constraints.pyc +0 -0
- keras/datasets/__init__.py +0 -0
- keras/datasets/__init__.pyc +0 -0
- keras/datasets/cifar.py +22 -0
- keras/datasets/cifar.pyc +0 -0
- keras/datasets/cifar10.py +31 -0
- keras/datasets/cifar10.pyc +0 -0
- keras/datasets/cifar100.py +28 -0
- keras/datasets/cifar100.pyc +0 -0
- keras/datasets/data_utils.py +50 -0
- keras/datasets/data_utils.pyc +0 -0
- keras/datasets/imdb.py +66 -0
- keras/datasets/imdb.pyc +0 -0
- keras/datasets/mnist.py +23 -0
- keras/datasets/mnist.pyc +0 -0
- keras/datasets/reuters.py +148 -0
- keras/datasets/reuters.pyc +0 -0
- keras/initializations.py +86 -0
- keras/initializations.pyc +0 -0
- keras/layers/__init__.py +0 -0
- keras/layers/__init__.pyc +0 -0
- keras/layers/advanced_activations.py +156 -0
- keras/layers/advanced_activations.pyc +0 -0
- keras/layers/containers.py +405 -0
- keras/layers/containers.pyc +0 -0
- keras/layers/convolutional.py +505 -0
- keras/layers/convolutional.pyc +0 -0
- keras/layers/core.py +1428 -0
- keras/layers/core.pyc +0 -0
- keras/layers/embeddings.py +88 -0
- keras/layers/embeddings.pyc +0 -0
- keras/layers/noise.py +55 -0
- keras/layers/noise.pyc +0 -0
- keras/layers/normalization.py +123 -0
- keras/layers/normalization.pyc +0 -0
- keras/layers/ntm.py +326 -0
- keras/layers/ntm.pyc +0 -0
- keras/layers/recurrent.py +354 -0
- keras/layers/recurrent.pyc +0 -0
- keras/models.py +743 -0
- keras/models.pyc +0 -0
- keras/objectives.py +59 -0
- keras/objectives.pyc +0 -0
- keras/optimizers.py +229 -0
- keras/optimizers.pyc +0 -0
- keras/preprocessing/__init__.py +0 -0
- keras/preprocessing/__init__.pyc +0 -0
- keras/preprocessing/image.py +246 -0
- keras/preprocessing/image.pyc +0 -0
- keras/preprocessing/sequence.py +124 -0
- keras/preprocessing/sequence.pyc +0 -0
- keras/preprocessing/text.py +176 -0
- keras/preprocessing/text.pyc +0 -0
- keras/regularizers.py +86 -0
- keras/regularizers.pyc +0 -0
- keras/utils/__init__.py +0 -0
- keras/utils/__init__.pyc +0 -0
- keras/utils/generic_utils.py +133 -0
- keras/utils/generic_utils.pyc +0 -0
- keras/utils/io_utils.py +71 -0
- keras/utils/io_utils.pyc +0 -0
- keras/utils/layer_utils.py +93 -0
- keras/utils/layer_utils.pyc +0 -0
- keras/utils/np_utils.py +53 -0
- keras/utils/np_utils.pyc +0 -0
- keras/utils/test_utils.py +27 -0
- keras/utils/test_utils.pyc +0 -0
- keras/utils/theano_utils.py +44 -0
- keras/utils/theano_utils.pyc +0 -0
- keras/utils/visualize_util.py +41 -0
- keras/utils/visualize_util.pyc +0 -0
- keras/wrappers/__init__.py +0 -0
- keras/wrappers/__init__.pyc +0 -0
- keras/wrappers/scikit_learn.py +266 -0
- keras/wrappers/scikit_learn.pyc +0 -0
- tests/__init__.py +0 -0
- tests/__init__.pyc +0 -0
- tests/manual/__init__.py +0 -0
- tests/manual/__init__.pyc +0 -0
- tests/manual/check_autoencoder.py +134 -0
- tests/manual/check_autoencoder.pyc +0 -0
- tests/manual/check_callbacks.py +236 -0
- tests/manual/check_callbacks.pyc +0 -0
- tests/manual/check_constraints.py +100 -0
- tests/manual/check_constraints.pyc +0 -0
- tests/manual/check_masked_recurrent.py +130 -0
- tests/manual/check_masked_recurrent.pyc +0 -0
- tests/manual/check_model_utils.py +44 -0
- tests/manual/check_model_utils.pyc +0 -0
- tests/manual/check_save_weights.py +40 -0
- tests/manual/check_save_weights.pyc +0 -0
- tests/manual/check_wrappers.py +126 -0
- tests/manual/check_wrappers.pyc +0 -0
- tests/manual/check_yaml.py +101 -0
- tests/manual/check_yaml.pyc +0 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from __future__ import absolute_import
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from .. import backend as K
|
|
6
|
+
from .. import activations, initializations
|
|
7
|
+
from ..layers.core import MaskedLayer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Recurrent(MaskedLayer):
|
|
11
|
+
input_ndim = 3
|
|
12
|
+
|
|
13
|
+
def __init__(self, weights=None,
|
|
14
|
+
return_sequences=False, go_backwards=False, stateful=False,
|
|
15
|
+
input_dim=None, input_length=None, **kwargs):
|
|
16
|
+
self.return_sequences = return_sequences
|
|
17
|
+
self.initial_weights = weights
|
|
18
|
+
self.go_backwards = go_backwards
|
|
19
|
+
self.stateful = stateful
|
|
20
|
+
|
|
21
|
+
self.input_dim = input_dim
|
|
22
|
+
self.input_length = input_length
|
|
23
|
+
if self.input_dim:
|
|
24
|
+
kwargs['input_shape'] = (self.input_length, self.input_dim)
|
|
25
|
+
super(Recurrent, self).__init__(**kwargs)
|
|
26
|
+
|
|
27
|
+
def get_output_mask(self, train=False):
|
|
28
|
+
if self.return_sequences:
|
|
29
|
+
return super(Recurrent, self).get_output_mask(train)
|
|
30
|
+
else:
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def output_shape(self):
|
|
35
|
+
input_shape = self.input_shape
|
|
36
|
+
if self.return_sequences:
|
|
37
|
+
return (input_shape[0], input_shape[1], self.output_dim)
|
|
38
|
+
else:
|
|
39
|
+
return (input_shape[0], self.output_dim)
|
|
40
|
+
|
|
41
|
+
def step(self, x, states):
|
|
42
|
+
raise NotImplementedError
|
|
43
|
+
|
|
44
|
+
def get_output(self, train=False):
|
|
45
|
+
# input shape: (nb_samples, time (padded with zeros), input_dim)
|
|
46
|
+
X = self.get_input(train)
|
|
47
|
+
assert K.ndim(X) == 3
|
|
48
|
+
if K._BACKEND == 'tensorflow':
|
|
49
|
+
if not self.input_shape[1]:
|
|
50
|
+
raise Exception('When using TensorFlow, you should define ' +
|
|
51
|
+
'explicitely the number of timesteps of ' +
|
|
52
|
+
'your sequences. Make sure the first layer ' +
|
|
53
|
+
'has an "input_shape" argument with a defined ' +
|
|
54
|
+
'first dimension.')
|
|
55
|
+
|
|
56
|
+
mask = self.get_output_mask(train)
|
|
57
|
+
if mask:
|
|
58
|
+
# apply mask
|
|
59
|
+
X *= K.expand_dims(mask)
|
|
60
|
+
masking = True
|
|
61
|
+
else:
|
|
62
|
+
masking = False
|
|
63
|
+
|
|
64
|
+
if self.stateful:
|
|
65
|
+
initial_states = self.states
|
|
66
|
+
else:
|
|
67
|
+
# build an all-zero tensor of shape (samples, output_dim)
|
|
68
|
+
initial_state = K.zeros_like(X) # (samples, timesteps, input_dim)
|
|
69
|
+
initial_state = K.sum(initial_state, axis=1) # (samples, input_dim)
|
|
70
|
+
reducer = K.zeros((self.input_dim, self.output_dim))
|
|
71
|
+
initial_state = K.dot(initial_state, reducer) # (samples, output_dim)
|
|
72
|
+
initial_states = [initial_state for _ in range(len(self.states))]
|
|
73
|
+
|
|
74
|
+
last_output, outputs, states = K.rnn(self.step, X, initial_states,
|
|
75
|
+
go_backwards=self.go_backwards,
|
|
76
|
+
masking=masking)
|
|
77
|
+
if self.stateful:
|
|
78
|
+
for i in range(len(states)):
|
|
79
|
+
K.set_value(self.states[i], states[i])
|
|
80
|
+
|
|
81
|
+
if self.return_sequences:
|
|
82
|
+
return outputs
|
|
83
|
+
else:
|
|
84
|
+
return last_output
|
|
85
|
+
|
|
86
|
+
def get_config(self):
|
|
87
|
+
config = {"name": self.__class__.__name__,
|
|
88
|
+
"return_sequences": self.return_sequences,
|
|
89
|
+
"input_dim": self.input_dim,
|
|
90
|
+
"input_length": self.input_length,
|
|
91
|
+
"go_backwards": self.go_backwards,
|
|
92
|
+
"stateful": self.stateful}
|
|
93
|
+
base_config = super(Recurrent, self).get_config()
|
|
94
|
+
return dict(list(base_config.items()) + list(config.items()))
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class SimpleRNN(Recurrent):
|
|
98
|
+
'''
|
|
99
|
+
Fully-connected RNN where the output is to fed back to input.
|
|
100
|
+
Takes inputs with shape:
|
|
101
|
+
(nb_samples, max_sample_length, input_dim)
|
|
102
|
+
(samples shorter than `max_sample_length`
|
|
103
|
+
are padded with zeros at the end)
|
|
104
|
+
and returns outputs with shape:
|
|
105
|
+
if not return_sequences:
|
|
106
|
+
(nb_samples, output_dim)
|
|
107
|
+
if return_sequences:
|
|
108
|
+
(nb_samples, max_sample_length, output_dim)
|
|
109
|
+
'''
|
|
110
|
+
def __init__(self, output_dim,
|
|
111
|
+
init='glorot_uniform', inner_init='orthogonal',
|
|
112
|
+
activation='sigmoid', **kwargs):
|
|
113
|
+
self.output_dim = output_dim
|
|
114
|
+
self.init = initializations.get(init)
|
|
115
|
+
self.inner_init = initializations.get(inner_init)
|
|
116
|
+
self.activation = activations.get(activation)
|
|
117
|
+
super(SimpleRNN, self).__init__(**kwargs)
|
|
118
|
+
|
|
119
|
+
def build(self):
|
|
120
|
+
input_shape = self.input_shape
|
|
121
|
+
if self.stateful:
|
|
122
|
+
if not input_shape[0]:
|
|
123
|
+
raise Exception('If a RNN is stateful, a complete ' +
|
|
124
|
+
'input_shape must be provided ' +
|
|
125
|
+
'(including batch size).')
|
|
126
|
+
self.states = [K.zeros(input_shape[0], self.output_dim)]
|
|
127
|
+
else:
|
|
128
|
+
# initial states: all-zero tensor of shape (output_dim)
|
|
129
|
+
self.states = [None]
|
|
130
|
+
input_dim = input_shape[2]
|
|
131
|
+
self.input_dim = input_dim
|
|
132
|
+
|
|
133
|
+
self.W = self.init((input_dim, self.output_dim))
|
|
134
|
+
self.U = self.inner_init((self.output_dim, self.output_dim))
|
|
135
|
+
self.b = K.zeros((self.output_dim))
|
|
136
|
+
self.params = [self.W, self.U, self.b]
|
|
137
|
+
|
|
138
|
+
if self.initial_weights is not None:
|
|
139
|
+
self.set_weights(self.initial_weights)
|
|
140
|
+
del self.initial_weights
|
|
141
|
+
|
|
142
|
+
def step(self, x, states):
|
|
143
|
+
# states only contains the previous output.
|
|
144
|
+
assert len(states) == 1
|
|
145
|
+
prev_output = states[0]
|
|
146
|
+
h = K.dot(x, self.W) + self.b
|
|
147
|
+
output = self.activation(h * K.dot(prev_output, self.U))
|
|
148
|
+
return output, [output]
|
|
149
|
+
|
|
150
|
+
def get_config(self):
|
|
151
|
+
config = {"output_dim": self.output_dim,
|
|
152
|
+
"init": self.init.__name__,
|
|
153
|
+
"inner_init": self.inner_init.__name__,
|
|
154
|
+
"activation": self.activation.__name__}
|
|
155
|
+
base_config = super(SimpleRNN, self).get_config()
|
|
156
|
+
return dict(list(base_config.items()) + list(config.items()))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class GRU(Recurrent):
|
|
160
|
+
'''
|
|
161
|
+
Gated Recurrent Unit - Cho et al. 2014
|
|
162
|
+
Acts as a spatiotemporal projection,
|
|
163
|
+
turning a sequence of vectors into a single vector.
|
|
164
|
+
Takes inputs with shape:
|
|
165
|
+
(nb_samples, max_sample_length, input_dim)
|
|
166
|
+
(samples shorter than `max_sample_length`
|
|
167
|
+
are padded with zeros at the end)
|
|
168
|
+
and returns outputs with shape:
|
|
169
|
+
if not return_sequences:
|
|
170
|
+
(nb_samples, output_dim)
|
|
171
|
+
if return_sequences:
|
|
172
|
+
(nb_samples, max_sample_length, output_dim)
|
|
173
|
+
References:
|
|
174
|
+
On the Properties of Neural Machine Translation:
|
|
175
|
+
Encoder–Decoder Approaches
|
|
176
|
+
http://www.aclweb.org/anthology/W14-4012
|
|
177
|
+
Empirical Evaluation of Gated Recurrent Neural Networks
|
|
178
|
+
on Sequence Modeling
|
|
179
|
+
http://arxiv.org/pdf/1412.3555v1.pdf
|
|
180
|
+
'''
|
|
181
|
+
def __init__(self, output_dim,
|
|
182
|
+
init='glorot_uniform', inner_init='orthogonal',
|
|
183
|
+
activation='sigmoid', inner_activation='hard_sigmoid',
|
|
184
|
+
**kwargs):
|
|
185
|
+
self.output_dim = output_dim
|
|
186
|
+
self.init = initializations.get(init)
|
|
187
|
+
self.inner_init = initializations.get(inner_init)
|
|
188
|
+
self.activation = activations.get(activation)
|
|
189
|
+
self.inner_activation = activations.get(inner_activation)
|
|
190
|
+
super(GRU, self).__init__(**kwargs)
|
|
191
|
+
|
|
192
|
+
def build(self):
|
|
193
|
+
input_shape = self.input_shape
|
|
194
|
+
input_dim = input_shape[2]
|
|
195
|
+
self.input_dim = input_dim
|
|
196
|
+
self.input = K.placeholder(input_shape)
|
|
197
|
+
|
|
198
|
+
self.W_z = self.init((input_dim, self.output_dim))
|
|
199
|
+
self.U_z = self.inner_init((self.output_dim, self.output_dim))
|
|
200
|
+
self.b_z = K.zeros((self.output_dim,))
|
|
201
|
+
|
|
202
|
+
self.W_r = self.init((input_dim, self.output_dim))
|
|
203
|
+
self.U_r = self.inner_init((self.output_dim, self.output_dim))
|
|
204
|
+
self.b_r = K.zeros((self.output_dim,))
|
|
205
|
+
|
|
206
|
+
self.W_h = self.init((input_dim, self.output_dim))
|
|
207
|
+
self.U_h = self.inner_init((self.output_dim, self.output_dim))
|
|
208
|
+
self.b_h = K.zeros((self.output_dim,))
|
|
209
|
+
|
|
210
|
+
self.params = [self.W_z, self.U_z, self.b_z,
|
|
211
|
+
self.W_r, self.U_r, self.b_r,
|
|
212
|
+
self.W_h, self.U_h, self.b_h]
|
|
213
|
+
|
|
214
|
+
if self.stateful:
|
|
215
|
+
if not input_shape[0]:
|
|
216
|
+
raise Exception('If a RNN is stateful, a complete ' +
|
|
217
|
+
'input_shape must be provided ' +
|
|
218
|
+
'(including batch size).')
|
|
219
|
+
self.states = [K.zeros(input_shape[0], self.output_dim)]
|
|
220
|
+
else:
|
|
221
|
+
# initial states: all-zero tensor of shape (output_dim)
|
|
222
|
+
self.states = [None]
|
|
223
|
+
|
|
224
|
+
if self.initial_weights is not None:
|
|
225
|
+
self.set_weights(self.initial_weights)
|
|
226
|
+
del self.initial_weights
|
|
227
|
+
|
|
228
|
+
def step(self, x, states):
|
|
229
|
+
assert len(states) == 1
|
|
230
|
+
x_z = K.dot(x, self.W_z) + self.b_z
|
|
231
|
+
x_r = K.dot(x, self.W_r) + self.b_r
|
|
232
|
+
x_h = K.dot(x, self.W_h) + self.b_h
|
|
233
|
+
|
|
234
|
+
h_tm1 = states[0]
|
|
235
|
+
z = self.inner_activation(x_z + K.dot(h_tm1, self.U_z))
|
|
236
|
+
r = self.inner_activation(x_r + K.dot(h_tm1, self.U_r))
|
|
237
|
+
|
|
238
|
+
hh = self.inner_activation(x_h + K.dot(r * h_tm1, self.U_h))
|
|
239
|
+
h = z * h_tm1 + (1 - z) * hh
|
|
240
|
+
return h, [h]
|
|
241
|
+
|
|
242
|
+
def get_config(self):
|
|
243
|
+
config = {"output_dim": self.output_dim,
|
|
244
|
+
"init": self.init.__name__,
|
|
245
|
+
"inner_init": self.inner_init.__name__,
|
|
246
|
+
"activation": self.activation.__name__,
|
|
247
|
+
"inner_activation": self.inner_activation.__name__}
|
|
248
|
+
base_config = super(GRU, self).get_config()
|
|
249
|
+
return dict(list(base_config.items()) + list(config.items()))
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
class LSTM(Recurrent):
|
|
253
|
+
'''
|
|
254
|
+
Acts as a spatiotemporal projection,
|
|
255
|
+
turning a sequence of vectors into a single vector.
|
|
256
|
+
Takes inputs with shape:
|
|
257
|
+
(nb_samples, max_sample_length, input_dim)
|
|
258
|
+
(samples shorter than `max_sample_length`
|
|
259
|
+
are padded with zeros at the end)
|
|
260
|
+
and returns outputs with shape:
|
|
261
|
+
if not return_sequences:
|
|
262
|
+
(nb_samples, output_dim)
|
|
263
|
+
if return_sequences:
|
|
264
|
+
(nb_samples, max_sample_length, output_dim)
|
|
265
|
+
For a step-by-step description of the algorithm, see:
|
|
266
|
+
http://deeplearning.net/tutorial/lstm.html
|
|
267
|
+
References:
|
|
268
|
+
Long short-term memory (original 97 paper)
|
|
269
|
+
http://deeplearning.cs.cmu.edu/pdfs/Hochreiter97_lstm.pdf
|
|
270
|
+
Learning to forget: Continual prediction with LSTM
|
|
271
|
+
http://www.mitpressjournals.org/doi/pdf/10.1162/089976600300015015
|
|
272
|
+
Supervised sequence labelling with recurrent neural networks
|
|
273
|
+
http://www.cs.toronto.edu/~graves/preprint.pdf
|
|
274
|
+
'''
|
|
275
|
+
def __init__(self, output_dim,
|
|
276
|
+
init='glorot_uniform', inner_init='orthogonal',
|
|
277
|
+
forget_bias_init='one', activation='tanh',
|
|
278
|
+
inner_activation='hard_sigmoid', **kwargs):
|
|
279
|
+
self.output_dim = output_dim
|
|
280
|
+
self.init = initializations.get(init)
|
|
281
|
+
self.inner_init = initializations.get(inner_init)
|
|
282
|
+
self.forget_bias_init = initializations.get(forget_bias_init)
|
|
283
|
+
self.activation = activations.get(activation)
|
|
284
|
+
self.inner_activation = activations.get(inner_activation)
|
|
285
|
+
super(LSTM, self).__init__(**kwargs)
|
|
286
|
+
|
|
287
|
+
def build(self):
|
|
288
|
+
input_shape = self.input_shape
|
|
289
|
+
input_dim = input_shape[2]
|
|
290
|
+
self.input_dim = input_dim
|
|
291
|
+
self.input = K.placeholder(input_shape)
|
|
292
|
+
|
|
293
|
+
if self.stateful:
|
|
294
|
+
if not input_shape[0]:
|
|
295
|
+
raise Exception('If a RNN is stateful, a complete ' +
|
|
296
|
+
'input_shape must be provided ' +
|
|
297
|
+
'(including batch size).')
|
|
298
|
+
self.states = [K.zeros(input_shape[0], self.output_dim),
|
|
299
|
+
K.zeros(input_shape[0], self.output_dim)]
|
|
300
|
+
else:
|
|
301
|
+
# initial states: 2 all-zero tensor of shape (output_dim)
|
|
302
|
+
self.states = [None, None]
|
|
303
|
+
|
|
304
|
+
self.W_i = self.init((input_dim, self.output_dim))
|
|
305
|
+
self.U_i = self.inner_init((self.output_dim, self.output_dim))
|
|
306
|
+
self.b_i = K.zeros((self.output_dim))
|
|
307
|
+
|
|
308
|
+
self.W_f = self.init((input_dim, self.output_dim))
|
|
309
|
+
self.U_f = self.inner_init((self.output_dim, self.output_dim))
|
|
310
|
+
self.b_f = self.forget_bias_init((self.output_dim))
|
|
311
|
+
|
|
312
|
+
self.W_c = self.init((input_dim, self.output_dim))
|
|
313
|
+
self.U_c = self.inner_init((self.output_dim, self.output_dim))
|
|
314
|
+
self.b_c = K.zeros((self.output_dim))
|
|
315
|
+
|
|
316
|
+
self.W_o = self.init((input_dim, self.output_dim))
|
|
317
|
+
self.U_o = self.inner_init((self.output_dim, self.output_dim))
|
|
318
|
+
self.b_o = K.zeros((self.output_dim))
|
|
319
|
+
|
|
320
|
+
self.params = [self.W_i, self.U_i, self.b_i,
|
|
321
|
+
self.W_c, self.U_c, self.b_c,
|
|
322
|
+
self.W_f, self.U_f, self.b_f,
|
|
323
|
+
self.W_o, self.U_o, self.b_o]
|
|
324
|
+
|
|
325
|
+
if self.initial_weights is not None:
|
|
326
|
+
self.set_weights(self.initial_weights)
|
|
327
|
+
del self.initial_weights
|
|
328
|
+
|
|
329
|
+
def step(self, x, states):
|
|
330
|
+
assert len(states) == 2
|
|
331
|
+
h_tm1 = states[0]
|
|
332
|
+
c_tm1 = states[1]
|
|
333
|
+
|
|
334
|
+
x_i = K.dot(x, self.W_i) + self.b_i
|
|
335
|
+
x_f = K.dot(x, self.W_f) + self.b_f
|
|
336
|
+
x_c = K.dot(x, self.W_c) + self.b_c
|
|
337
|
+
x_o = K.dot(x, self.W_o) + self.b_o
|
|
338
|
+
|
|
339
|
+
i = self.inner_activation(x_i + K.dot(h_tm1, self.U_i))
|
|
340
|
+
f = self.inner_activation(x_f + K.dot(h_tm1, self.U_f))
|
|
341
|
+
c = f * c_tm1 + i * self.activation(x_c + K.dot(h_tm1, self.U_c))
|
|
342
|
+
o = self.inner_activation(x_o + K.dot(h_tm1, self.U_o))
|
|
343
|
+
h = o * self.activation(c)
|
|
344
|
+
return h, [h, c]
|
|
345
|
+
|
|
346
|
+
def get_config(self):
|
|
347
|
+
config = {"output_dim": self.output_dim,
|
|
348
|
+
"init": self.init.__name__,
|
|
349
|
+
"inner_init": self.inner_init.__name__,
|
|
350
|
+
"forget_bias_init": self.forget_bias_init.__name__,
|
|
351
|
+
"activation": self.activation.__name__,
|
|
352
|
+
"inner_activation": self.inner_activation.__name__}
|
|
353
|
+
base_config = super(LSTM, self).get_config()
|
|
354
|
+
return dict(list(base_config.items()) + list(config.items()))
|
|
Binary file
|