Initialize the basic LSTM cell. Args: num_units: int, The number of units in the LSTM cell. forget_bias: float, The bias added to forget gates (see above). Must set to `0.0` manually when restoring from CudnnLSTM-trained checkpoints. state_is_tuple: If True, accepted a
(self,
num_units,
forget_bias=1.0,
state_is_tuple=True,
activation=None,
reuse=None,
name=None,
dtype=None,
**kwargs)
| 658 | @deprecated(None, "This class is equivalent as tf.keras.layers.LSTMCell," |
| 659 | " and will be replaced by that in Tensorflow 2.0.") |
| 660 | def __init__(self, |
| 661 | num_units, |
| 662 | forget_bias=1.0, |
| 663 | state_is_tuple=True, |
| 664 | activation=None, |
| 665 | reuse=None, |
| 666 | name=None, |
| 667 | dtype=None, |
| 668 | **kwargs): |
| 669 | """Initialize the basic LSTM cell. |
| 670 | |
| 671 | Args: |
| 672 | num_units: int, The number of units in the LSTM cell. |
| 673 | forget_bias: float, The bias added to forget gates (see above). Must set |
| 674 | to `0.0` manually when restoring from CudnnLSTM-trained checkpoints. |
| 675 | state_is_tuple: If True, accepted and returned states are 2-tuples of the |
| 676 | `c_state` and `m_state`. If False, they are concatenated along the |
| 677 | column axis. The latter behavior will soon be deprecated. |
| 678 | activation: Activation function of the inner states. Default: `tanh`. It |
| 679 | could also be string that is within Keras activation function names. |
| 680 | reuse: (optional) Python boolean describing whether to reuse variables in |
| 681 | an existing scope. If not `True`, and the existing scope already has |
| 682 | the given variables, an error is raised. |
| 683 | name: String, the name of the layer. Layers with the same name will share |
| 684 | weights, but to avoid mistakes we require reuse=True in such cases. |
| 685 | dtype: Default dtype of the layer (default of `None` means use the type of |
| 686 | the first input). Required when `build` is called before `call`. |
| 687 | **kwargs: Dict, keyword named properties for common layer attributes, like |
| 688 | `trainable` etc when constructing the cell from configs of get_config(). |
| 689 | When restoring from CudnnLSTM-trained checkpoints, must use |
| 690 | `CudnnCompatibleLSTMCell` instead. |
| 691 | """ |
| 692 | super(BasicLSTMCell, self).__init__( |
| 693 | _reuse=reuse, name=name, dtype=dtype, **kwargs) |
| 694 | _check_supported_dtypes(self.dtype) |
| 695 | if not state_is_tuple: |
| 696 | logging.warn( |
| 697 | "%s: Using a concatenated state is slower and will soon be " |
| 698 | "deprecated. Use state_is_tuple=True.", self) |
| 699 | if context.executing_eagerly() and context.num_gpus() > 0: |
| 700 | logging.warn( |
| 701 | "%s: Note that this cell is not optimized for performance. " |
| 702 | "Please use tf.contrib.cudnn_rnn.CudnnLSTM for better " |
| 703 | "performance on GPU.", self) |
| 704 | |
| 705 | # Inputs must be 2-dimensional. |
| 706 | self.input_spec = input_spec.InputSpec(ndim=2) |
| 707 | |
| 708 | self._num_units = num_units |
| 709 | self._forget_bias = forget_bias |
| 710 | self._state_is_tuple = state_is_tuple |
| 711 | if activation: |
| 712 | self._activation = activations.get(activation) |
| 713 | else: |
| 714 | self._activation = math_ops.tanh |
| 715 | |
| 716 | @property |
| 717 | def state_size(self): |
nothing calls this directly
no test coverage detected