def bidirectional_dynamic_rnn(cell_fw, cell_bw, inputs, sequence_length=None, initial_state_fw=None, initial_state_bw=None, dtype=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None):
    'Creates a dynamic version of bidirectional recurrent neural network.\n\n  Similar to the unidirectional case above (rnn) but takes input and builds\n  independent forward and backward RNNs. The input_size of forward and\n  backward cell must match. The initial state for both directions is zero by\n  default (but can be set optionally) and no intermediate states are ever\n  returned -- the network is fully unrolled for the given (passed in)\n  length(s) of the sequence(s) or completely unrolled if length(s) is not\n  given.\n\n  Args:\n    cell_fw: An instance of RNNCell, to be used for forward direction.\n    cell_bw: An instance of RNNCell, to be used for backward direction.\n    inputs: The RNN inputs.\n      If time_major == False (default), this must be a tensor of shape:\n        `[batch_size, max_time, input_size]`.\n      If time_major == True, this must be a tensor of shape:\n        `[max_time, batch_size, input_size]`.\n      [batch_size, input_size].\n    sequence_length: An int32/int64 vector, size `[batch_size]`,\n      containing the actual lengths for each of the sequences.\n    initial_state_fw: (optional) An initial state for the forward RNN.\n      This must be a tensor of appropriate type and shape\n      `[batch_size, cell_fw.state_size]`.\n      If `cell_fw.state_size` is a tuple, this should be a tuple of\n      tensors having shapes `[batch_size, s] for s in cell_fw.state_size`.\n    initial_state_bw: (optional) Same as for `initial_state_fw`, but using\n      the corresponding properties of `cell_bw`.\n    dtype: (optional) The data type for the initial states and expected output.\n      Required if initial_states are not provided or RNN states have a\n      heterogeneous dtype.\n    parallel_iterations: (Default: 32).  The number of iterations to run in\n      parallel.  Those operations which do not have any temporal dependency\n      and can be run in parallel, will be.  This parameter trades off\n      time for space.  Values >> 1 use more memory but take less time,\n      while smaller values use less memory but computations take longer.\n    swap_memory: Transparently swap the tensors produced in forward inference\n      but needed for back prop from GPU to CPU.  This allows training RNNs\n      which would typically not fit on a single GPU, with very minimal (or no)\n      performance penalty.\n    time_major: The shape format of the `inputs` and `outputs` Tensors.\n      If true, these `Tensors` must be shaped `[max_time, batch_size, depth]`.\n      If false, these `Tensors` must be shaped `[batch_size, max_time, depth]`.\n      Using `time_major = True` is a bit more efficient because it avoids\n      transposes at the beginning and end of the RNN calculation.  However,\n      most TensorFlow data is batch-major, so by default this function\n      accepts input and emits output in batch-major form.\n    dtype: (optional) The data type for the initial state.  Required if\n      either of the initial states are not provided.\n    scope: VariableScope for the created subgraph; defaults to\n      "bidirectional_rnn"\n\n  Returns:\n    A tuple (outputs, output_states) where:\n      outputs: A tuple (output_fw, output_bw) containing the forward and\n        the backward rnn output `Tensor`.\n        If time_major == False (default),\n          output_fw will be a `Tensor` shaped:\n          `[batch_size, max_time, cell_fw.output_size]`\n          and output_bw will be a `Tensor` shaped:\n          `[batch_size, max_time, cell_bw.output_size]`.\n        If time_major == True,\n          output_fw will be a `Tensor` shaped:\n          `[max_time, batch_size, cell_fw.output_size]`\n          and output_bw will be a `Tensor` shaped:\n          `[max_time, batch_size, cell_bw.output_size]`.\n        It returns a tuple instead of a single concatenated `Tensor`, unlike\n        in the `bidirectional_rnn`. If the concatenated one is preferred,\n        the forward and backward outputs can be concatenated as\n        `tf.concat(outputs, 2)`.\n      output_states: A tuple (output_state_fw, output_state_bw) containing\n        the forward and the backward final states of bidirectional rnn.\n\n  Raises:\n    TypeError: If `cell_fw` or `cell_bw` is not an instance of `RNNCell`.\n  '
    if (not isinstance(cell_fw, rnn_cell_impl._RNNCell)):
        raise TypeError('cell_fw must be an instance of RNNCell')
    if (not isinstance(cell_bw, rnn_cell_impl._RNNCell)):
        raise TypeError('cell_bw must be an instance of RNNCell')
    with vs.variable_scope((scope or 'bidirectional_rnn')):
        with vs.variable_scope('fw') as fw_scope:
            (output_fw, output_state_fw) = dynamic_rnn(cell=cell_fw, inputs=inputs, sequence_length=sequence_length, initial_state=initial_state_fw, dtype=dtype, parallel_iterations=parallel_iterations, swap_memory=swap_memory, time_major=time_major, scope=fw_scope)
        if (not time_major):
            time_dim = 1
            batch_dim = 0
        else:
            time_dim = 0
            batch_dim = 1
        with vs.variable_scope('bw') as bw_scope:
            inputs_reverse = array_ops.reverse_sequence(input=inputs, seq_lengths=sequence_length, seq_dim=time_dim, batch_dim=batch_dim)
            (tmp, output_state_bw) = dynamic_rnn(cell=cell_bw, inputs=inputs_reverse, sequence_length=sequence_length, initial_state=initial_state_bw, dtype=dtype, parallel_iterations=parallel_iterations, swap_memory=swap_memory, time_major=time_major, scope=bw_scope)
    output_bw = array_ops.reverse_sequence(input=tmp, seq_lengths=sequence_length, seq_dim=time_dim, batch_dim=batch_dim)
    outputs = (output_fw, output_bw)
    output_states = (output_state_fw, output_state_bw)
    return (outputs, output_states)
Creates a dynamic version of bidirectional recurrent neural network.

Similar to the unidirectional case above (rnn) but takes input and builds
independent forward and backward RNNs. The input_size of forward and
backward cell must match. The initial state for both directions is zero by
default (but can be set optionally) and no intermediate states are ever
returned -- the network is fully unrolled for the given (passed in)
length(s) of the sequence(s) or completely unrolled if length(s) is not
given.

Args:
  cell_fw: An instance of RNNCell, to be used for forward direction.
  cell_bw: An instance of RNNCell, to be used for backward direction.
  inputs: The RNN inputs.
    If time_major == False (default), this must be a tensor of shape:
      `[batch_size, max_time, input_size]`.
    If time_major == True, this must be a tensor of shape:
      `[max_time, batch_size, input_size]`.
    [batch_size, input_size].
  sequence_length: An int32/int64 vector, size `[batch_size]`,
    containing the actual lengths for each of the sequences.
  initial_state_fw: (optional) An initial state for the forward RNN.
    This must be a tensor of appropriate type and shape
    `[batch_size, cell_fw.state_size]`.
    If `cell_fw.state_size` is a tuple, this should be a tuple of
    tensors having shapes `[batch_size, s] for s in cell_fw.state_size`.
  initial_state_bw: (optional) Same as for `initial_state_fw`, but using
    the corresponding properties of `cell_bw`.
  dtype: (optional) The data type for the initial states and expected output.
    Required if initial_states are not provided or RNN states have a
    heterogeneous dtype.
  parallel_iterations: (Default: 32).  The number of iterations to run in
    parallel.  Those operations which do not have any temporal dependency
    and can be run in parallel, will be.  This parameter trades off
    time for space.  Values >> 1 use more memory but take less time,
    while smaller values use less memory but computations take longer.
  swap_memory: Transparently swap the tensors produced in forward inference
    but needed for back prop from GPU to CPU.  This allows training RNNs
    which would typically not fit on a single GPU, with very minimal (or no)
    performance penalty.
  time_major: The shape format of the `inputs` and `outputs` Tensors.
    If true, these `Tensors` must be shaped `[max_time, batch_size, depth]`.
    If false, these `Tensors` must be shaped `[batch_size, max_time, depth]`.
    Using `time_major = True` is a bit more efficient because it avoids
    transposes at the beginning and end of the RNN calculation.  However,
    most TensorFlow data is batch-major, so by default this function
    accepts input and emits output in batch-major form.
  dtype: (optional) The data type for the initial state.  Required if
    either of the initial states are not provided.
  scope: VariableScope for the created subgraph; defaults to
    "bidirectional_rnn"

Returns:
  A tuple (outputs, output_states) where:
    outputs: A tuple (output_fw, output_bw) containing the forward and
      the backward rnn output `Tensor`.
      If time_major == False (default),
        output_fw will be a `Tensor` shaped:
        `[batch_size, max_time, cell_fw.output_size]`
        and output_bw will be a `Tensor` shaped:
        `[batch_size, max_time, cell_bw.output_size]`.
      If time_major == True,
        output_fw will be a `Tensor` shaped:
        `[max_time, batch_size, cell_fw.output_size]`
        and output_bw will be a `Tensor` shaped:
        `[max_time, batch_size, cell_bw.output_size]`.
      It returns a tuple instead of a single concatenated `Tensor`, unlike
      in the `bidirectional_rnn`. If the concatenated one is preferred,
      the forward and backward outputs can be concatenated as
      `tf.concat(outputs, 2)`.
    output_states: A tuple (output_state_fw, output_state_bw) containing
      the forward and the backward final states of bidirectional rnn.

Raises:
  TypeError: If `cell_fw` or `cell_bw` is not an instance of `RNNCell`.
def bidirectional_dynamic_rnn(cell_fw, cell_bw, inputs, sequence_length=None, initial_state_fw=None, initial_state_bw=None, dtype=None, parallel_iterations=None, swap_memory=False, time_major=False, scope=None):
    'Creates a dynamic version of bidirectional recurrent neural network.\n\n  Similar to the unidirectional case above (rnn) but takes input and builds\n  independent forward and backward RNNs. The input_size of forward and\n  backward cell must match. The initial state for both directions is zero by\n  default (but can be set optionally) and no intermediate states are ever\n  returned -- the network is fully unrolled for the given (passed in)\n  length(s) of the sequence(s) or completely unrolled if length(s) is not\n  given.\n\n  Args:\n    cell_fw: An instance of RNNCell, to be used for forward direction.\n    cell_bw: An instance of RNNCell, to be used for backward direction.\n    inputs: The RNN inputs.\n      If time_major == False (default), this must be a tensor of shape:\n        `[batch_size, max_time, input_size]`.\n      If time_major == True, this must be a tensor of shape:\n        `[max_time, batch_size, input_size]`.\n      [batch_size, input_size].\n    sequence_length: An int32/int64 vector, size `[batch_size]`,\n      containing the actual lengths for each of the sequences.\n    initial_state_fw: (optional) An initial state for the forward RNN.\n      This must be a tensor of appropriate type and shape\n      `[batch_size, cell_fw.state_size]`.\n      If `cell_fw.state_size` is a tuple, this should be a tuple of\n      tensors having shapes `[batch_size, s] for s in cell_fw.state_size`.\n    initial_state_bw: (optional) Same as for `initial_state_fw`, but using\n      the corresponding properties of `cell_bw`.\n    dtype: (optional) The data type for the initial states and expected output.\n      Required if initial_states are not provided or RNN states have a\n      heterogeneous dtype.\n    parallel_iterations: (Default: 32).  The number of iterations to run in\n      parallel.  Those operations which do not have any temporal dependency\n      and can be run in parallel, will be.  This parameter trades off\n      time for space.  Values >> 1 use more memory but take less time,\n      while smaller values use less memory but computations take longer.\n    swap_memory: Transparently swap the tensors produced in forward inference\n      but needed for back prop from GPU to CPU.  This allows training RNNs\n      which would typically not fit on a single GPU, with very minimal (or no)\n      performance penalty.\n    time_major: The shape format of the `inputs` and `outputs` Tensors.\n      If true, these `Tensors` must be shaped `[max_time, batch_size, depth]`.\n      If false, these `Tensors` must be shaped `[batch_size, max_time, depth]`.\n      Using `time_major = True` is a bit more efficient because it avoids\n      transposes at the beginning and end of the RNN calculation.  However,\n      most TensorFlow data is batch-major, so by default this function\n      accepts input and emits output in batch-major form.\n    dtype: (optional) The data type for the initial state.  Required if\n      either of the initial states are not provided.\n    scope: VariableScope for the created subgraph; defaults to\n      "bidirectional_rnn"\n\n  Returns:\n    A tuple (outputs, output_states) where:\n      outputs: A tuple (output_fw, output_bw) containing the forward and\n        the backward rnn output `Tensor`.\n        If time_major == False (default),\n          output_fw will be a `Tensor` shaped:\n          `[batch_size, max_time, cell_fw.output_size]`\n          and output_bw will be a `Tensor` shaped:\n          `[batch_size, max_time, cell_bw.output_size]`.\n        If time_major == True,\n          output_fw will be a `Tensor` shaped:\n          `[max_time, batch_size, cell_fw.output_size]`\n          and output_bw will be a `Tensor` shaped:\n          `[max_time, batch_size, cell_bw.output_size]`.\n        It returns a tuple instead of a single concatenated `Tensor`, unlike\n        in the `bidirectional_rnn`. If the concatenated one is preferred,\n        the forward and backward outputs can be concatenated as\n        `tf.concat(outputs, 2)`.\n      output_states: A tuple (output_state_fw, output_state_bw) containing\n        the forward and the backward final states of bidirectional rnn.\n\n  Raises:\n    TypeError: If `cell_fw` or `cell_bw` is not an instance of `RNNCell`.\n  '
    if (not isinstance(cell_fw, rnn_cell_impl._RNNCell)):
        raise TypeError('cell_fw must be an instance of RNNCell')
    if (not isinstance(cell_bw, rnn_cell_impl._RNNCell)):
        raise TypeError('cell_bw must be an instance of RNNCell')
    with vs.variable_scope((scope or 'bidirectional_rnn')):
        with vs.variable_scope('fw') as fw_scope:
            (output_fw, output_state_fw) = dynamic_rnn(cell=cell_fw, inputs=inputs, sequence_length=sequence_length, initial_state=initial_state_fw, dtype=dtype, parallel_iterations=parallel_iterations, swap_memory=swap_memory, time_major=time_major, scope=fw_scope)
        if (not time_major):
            time_dim = 1
            batch_dim = 0
        else:
            time_dim = 0
            batch_dim = 1
        with vs.variable_scope('bw') as bw_scope:
            inputs_reverse = array_ops.reverse_sequence(input=inputs, seq_lengths=sequence_length, seq_dim=time_dim, batch_dim=batch_dim)
            (tmp, output_state_bw) = dynamic_rnn(cell=cell_bw, inputs=inputs_reverse, sequence_length=sequence_length, initial_state=initial_state_bw, dtype=dtype, parallel_iterations=parallel_iterations, swap_memory=swap_memory, time_major=time_major, scope=bw_scope)
    output_bw = array_ops.reverse_sequence(input=tmp, seq_lengths=sequence_length, seq_dim=time_dim, batch_dim=batch_dim)
    outputs = (output_fw, output_bw)
    output_states = (output_state_fw, output_state_bw)
    return (outputs, output_states)