@@ -262,6 +262,7 @@ def embedding(input,
262
262
263
263
264
264
# TODO(qijun): expose H0 and C0
265
+ @templatedoc (op_type = "lstm" )
265
266
def dynamic_lstm (input ,
266
267
size ,
267
268
param_attr = None ,
@@ -274,64 +275,19 @@ def dynamic_lstm(input,
274
275
dtype = 'float32' ,
275
276
name = None ):
276
277
"""
277
- **Dynamic LSTM Layer**
278
-
279
- The defalut implementation is diagonal/peephole connection
280
- (https://arxiv.org/pdf/1402.1128.pdf), the formula is as follows:
281
-
282
- .. math::
283
-
284
- i_t & = \sigma(W_{ix}x_{t} + W_{ih}h_{t-1} + W_{ic}c_{t-1} + b_i)
285
-
286
- f_t & = \sigma(W_{fx}x_{t} + W_{fh}h_{t-1} + W_{fc}c_{t-1} + b_f)
287
-
288
- \\ tilde{c_t} & = act_g(W_{cx}x_t + W_{ch}h_{t-1} + b_c)
289
-
290
- o_t & = \sigma(W_{ox}x_{t} + W_{oh}h_{t-1} + W_{oc}c_t + b_o)
291
-
292
- c_t & = f_t \odot c_{t-1} + i_t \odot \\ tilde{c_t}
293
-
294
- h_t & = o_t \odot act_h(c_t)
295
-
296
- where the :math:`W` terms denote weight matrices (e.g. :math:`W_{xi}` is
297
- the matrix of weights from the input gate to the input), :math:`W_{ic}, \
298
- W_{fc}, W_{oc}` are diagonal weight matrices for peephole connections. In
299
- our implementation, we use vectors to reprenset these diagonal weight
300
- matrices. The :math:`b` terms denote bias vectors (:math:`b_i` is the input
301
- gate bias vector), :math:`\sigma` is the non-linear activations, such as
302
- logistic sigmoid function, and :math:`i, f, o` and :math:`c` are the input
303
- gate, forget gate, output gate, and cell activation vectors, respectively,
304
- all of which have the same size as the cell output activation vector :math:`h`.
305
-
306
- The :math:`\odot` is the element-wise product of the vectors. :math:`act_g`
307
- and :math:`act_h` are the cell input and cell output activation functions
308
- and `tanh` is usually used for them. :math:`\\ tilde{c_t}` is also called
309
- candidate hidden state, which is computed based on the current input and
310
- the previous hidden state.
311
-
312
- Set `use_peepholes` to `False` to disable peephole connection. The formula
313
- is omitted here, please refer to the paper
314
- http://www.bioinf.jku.at/publications/older/2604.pdf for details.
315
-
316
- Note that these :math:`W_{xi}x_{t}, W_{xf}x_{t}, W_{xc}x_{t}, W_{xo}x_{t}`
317
- operations on the input :math:`x_{t}` are NOT included in this operator.
318
- Users can choose to use fully-connect layer before LSTM layer.
278
+ ${comment}
319
279
320
280
Args:
321
- input(Variable): The input of dynamic_lstm layer, which supports
322
- variable-time length input sequence. The underlying
323
- tensor in this Variable is a matrix with shape
324
- (T X 4D), where T is the total time steps in this
325
- mini-batch, D is the hidden size.
326
- size(int): 4 * hidden size.
327
- param_attr(ParamAttr|None): The parameter attribute for the learnable
281
+ input (Variable): ${input_comment}
282
+ size (int): 4 * hidden size.
283
+ param_attr (ParamAttr|None): The parameter attribute for the learnable
328
284
hidden-hidden weights.
329
285
330
286
- Weights = {:math:`W_{ch}, W_{ih}, \
331
287
W_{fh}, W_{oh}`}
332
288
- The shape is (D x 4D), where D is the hidden
333
289
size.
334
- bias_attr(ParamAttr|None): The bias attribute for the learnable bias
290
+ bias_attr (ParamAttr|None): The bias attribute for the learnable bias
335
291
weights, which contains two parts, input-hidden
336
292
bias weights and peephole connections weights if
337
293
setting `use_peepholes` to `True`.
@@ -343,21 +299,14 @@ def dynamic_lstm(input,
343
299
- Biases = { :math:`b_c, b_i, b_f, b_o, W_{ic}, \
344
300
W_{fc}, W_{oc}`}.
345
301
- The shape is (1 x 7D).
346
- use_peepholes(bool): Whether to enable diagonal/peephole connections,
347
- default `True`.
348
- is_reverse(bool): Whether to compute reversed LSTM, default `False`.
349
- gate_activation(str): The activation for input gate, forget gate and
350
- output gate. Choices = ["sigmoid", "tanh", "relu",
351
- "identity"], default "sigmoid".
352
- cell_activation(str): The activation for cell output. Choices = ["sigmoid",
353
- "tanh", "relu", "identity"], default "tanh".
354
- candidate_activation(str): The activation for candidate hidden state.
355
- Choices = ["sigmoid", "tanh",
356
- "relu", "identity"],
357
- default "tanh".
358
- dtype(str): Data type. Choices = ["float32", "float64"], default "float32".
359
- name(str|None): A name for this layer(optional). If set None, the layer
360
- will be named automatically.
302
+ use_peepholes (bool): ${use_peepholes_comment}
303
+ is_reverse (bool): ${is_reverse_comment}
304
+ gate_activation (str): ${gate_activation_comment}
305
+ cell_activation (str): ${cell_activation_comment}
306
+ candidate_activation (str): ${candidate_activation_comment}
307
+ dtype (str): Data type. Choices = ["float32", "float64"], default "float32".
308
+ name (str|None): A name for this layer(optional). If set None, the layer
309
+ will be named automatically.
361
310
362
311
Returns:
363
312
tuple: The hidden state, and cell state of LSTM. The shape of both \
0 commit comments