Check whether the cell is a Keras RNN cell. The Keras RNN cell accept the state as a list even the state is a single tensor, whereas the TF RNN cell does not wrap single state tensor in list. This behavior difference should be unified in future version. Args: rnn_cell: An RNN cell inst
(rnn_cell)
| 143 | |
| 144 | |
| 145 | def _is_keras_rnn_cell(rnn_cell): |
| 146 | """Check whether the cell is a Keras RNN cell. |
| 147 | |
| 148 | The Keras RNN cell accept the state as a list even the state is a single |
| 149 | tensor, whereas the TF RNN cell does not wrap single state tensor in list. |
| 150 | This behavior difference should be unified in future version. |
| 151 | |
| 152 | Args: |
| 153 | rnn_cell: An RNN cell instance that either follow the Keras interface or TF |
| 154 | RNN interface. |
| 155 | |
| 156 | Returns: |
| 157 | Boolean, whether the cell is an Keras RNN cell. |
| 158 | """ |
| 159 | # Cell type check is not strict enough since there are cells created by other |
| 160 | # library like Deepmind that didn't inherit tf.nn.rnn_cell.RNNCell. |
| 161 | # Keras cells never had zero_state method, which was from the original |
| 162 | # interface from TF RNN cell. |
| 163 | return (not isinstance(rnn_cell, rnn_cell_impl.RNNCell) and |
| 164 | isinstance(rnn_cell, base_layer.Layer) and |
| 165 | getattr(rnn_cell, "zero_state", None) is None) |
| 166 | |
| 167 | |
| 168 | # pylint: disable=unused-argument |
no outgoing calls
no test coverage detected