LSTM(10, input_length=shape[1], input_dim=shape[2],return_sequences=True)
model.add(LSTM(32, input_shape=(10, 64)))
这里的 input_length, input_dim , input_shape是什么意思?怎样使用LSTM?
通过help(LSTM)查看
class LSTM(RNN)
| Long Short-Term Memory layer - Hochreiter 1997.
|
| # Arguments
| units: Positive integer, dimensionality of the output space.
| activation: Activation function to use
| (see [activations](../activations.md)).
| Default: hyperbolic tangent (`tanh`).
| If you pass `None`, no activation is applied
| (ie. "linear" activation: `a(x) = x`).
在Arguments中并没有上面出现的input_length, input_dim, input_shape的描述
到keras的源码路径:
/usr/local/lib/python2.7/dist-packages/keras
grep -nrw LSTM ./
./legacy/layers.py:315: Use its children classes `LSTM`, `GRU` and `SimpleRNN` instead.
./legacy/layers.py:316: All recurrent layers (`LSTM`, `GRU`, `SimpleRNN`) also
./legacy/layers.py:325: model.add(LSTM(32, input_shape=(10, 64)))
./legacy/layers.py:329: model.add(LSTM(16))
./legacy/layers.py:334: model.add(LSTM(64, input_dim=64, input_length=10, return_sequences=True))
./legacy/layers.py:335: model.add(LSTM(32, return_sequences=True))
./legacy/layers.py:336: model.add(LSTM(10))
class LSTM(RNN)
基类RNN
class Recurrent(Layer):
"""Abstract base class for recurrent layers.
Do not use in a model -- it's not a valid layer!
Use its children classes `LSTM`, `GRU` and `SimpleRNN` instead.
All recurrent layers (`LSTM`, `GRU`, `SimpleRNN`) also
follow the specifications of this class and accept
the keyword arguments listed below.
# Example
```python
# as the first layer in a Sequential model
model = Sequential()
model.add(LSTM(32, input_shape=(10, 64))) //input_shape
# now model.output_shape == (None, 32) //output_shape
# note: `None` is the batch dimension.
# for subsequent layers, no need to specify the input size:
model.add(LSTM(16))
# to stack recurrent layers, you must use return_sequences=True
# on any recurrent layer that feeds into another recurrent layer.
# note that you only need to specify the input size on the first layer.
model = Sequential()
model.add(LSTM(64, input_dim=64, input_length=10, return_sequences=True))
model.add(LSTM(32, return_sequences=True))
model.add(LSTM(10))
```
# Arguments
return_sequences: Boolean. Whether to return the last output
in the output sequence, or the full sequence.
input_dim: dimensionality of the input (integer).
This argument (or alternatively, the keyword argument `input_shape`)
is required when using this layer as the first layer in a model.
input_length: Length of input sequences, to be specified
when it is constant.
This argument is required if you are going to connect
`Flatten` then `Dense` layers upstream
(without it, the shape of the dense outputs cannot be computed).
Note that if the recurrent layer is not the first layer
in your model, you would need to specify the input length
at the level of the first layer
(e.g. via the `input_shape` argument)
# Input shapes
3D tensor with shape `(batch_size, timesteps, input_dim)`,
(Optional) 2D tensors with shape `(batch_size, output_dim)`.
# Output shape
- if `return_state`: a list of tensors. The first tensor is
the output. The remaining tensors are the last states,
each with shape `(batch_size, units)`.
- if `return_sequences`: 3D tensor with shape
`(batch_size, timesteps, units)`.
- else, 2D tensor with shape `(batch_size, units)`.
class LSTM(RNN): units
"""Long Short-Term Memory layer - Hochreiter 1997.
# Arguments
units: Positive integer, dimensionality of the output space.
相关链接
https://adventuresinmachinelearning.com/keras-lstm-tutorial/
[Keras] 利用Keras建構LSTM模型,以Stock Prediction 為例 (数据预处理的过程)