From 8ff354d254dc786dea9fc1f9d3d7cc39df25e39f Mon Sep 17 00:00:00 2001 From: Scott Zhu Date: Fri, 7 Feb 2020 15:10:23 -0800 Subject: [PATCH] Update the docstring for Bidirectional wrapper wrt to the layer used. For any custom layer to work with Bidirectional wrapper, the layer need to support "go_backwards" as its init parameter and property. PiperOrigin-RevId: 293904336 Change-Id: Id65eff898e3acc6d33897f4671c042167f178958 --- tensorflow/python/keras/layers/wrappers.py | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tensorflow/python/keras/layers/wrappers.py b/tensorflow/python/keras/layers/wrappers.py index b5f20ea08f5..08b8835b87b 100644 --- a/tensorflow/python/keras/layers/wrappers.py +++ b/tensorflow/python/keras/layers/wrappers.py @@ -353,21 +353,30 @@ class Bidirectional(Wrapper): """Bidirectional wrapper for RNNs. Arguments: - layer: `Recurrent` instance. - merge_mode: Mode by which outputs of the - forward and backward RNNs will be combined. - One of {'sum', 'mul', 'concat', 'ave', None}. - If None, the outputs will not be combined, - they will be returned as a list. - backward_layer: Optional `Recurrent` instance to be used to handle - backwards input processing. If `backward_layer` is not provided, - the layer instance passed as the `layer` argument will be used to - generate the backward layer automatically. + layer: `keras.layers.RNN` instance, such as `keras.layers.LSTM` or + `keras.layers.GRU`. It could also be a `keras.layers.Layer` instance + that meets the following criteria: + 1. Be a sequence-processing layer (accepts 3D+ inputs). + 2. Have a `go_backwards`, `return_sequences` and `return_state` + attribute (with the same semantics as for the `RNN` class). + 3. Have an `input_spec` attribute. + 4. Implement serialization via `get_config()` and `from_config()`. + Note that the recommended way to create new RNN layers is to write a + custom RNN cell and use it with `keras.layers.RNN`, instead of + subclassing `keras.layers.Layer` directly. + merge_mode: Mode by which outputs of the forward and backward RNNs will be + combined. One of {'sum', 'mul', 'concat', 'ave', None}. If None, the + outputs will not be combined, they will be returned as a list. Default + value is 'concat'. + backward_layer: Optional `keras.layers.RNN`, or keras.layers.Layer` instance + to be used to handle backwards input processing. If `backward_layer` is + not provided, the layer instance passed as the `layer` argument will be + used to generate the backward layer automatically. Note that the provided `backward_layer` layer should have properties matching those of the `layer` argument, in particular it should have the same values for `stateful`, `return_states`, `return_sequence`, etc. - In addition, `backward_layer` and `layer` should have - different `go_backwards` argument values. + In addition, `backward_layer` and `layer` should have different + `go_backwards` argument values. A `ValueError` will be raised if these requirements are not met. Call arguments: