parameters: (self, inputs, state)
docstring: Perform a step of attention-wrapped RNN.
  
      - Step 1: Mix the `inputs` and previous step's `attention` output via
        `cell_input_fn`.
      - Step 2: Call the wrapped `cell` with this input and its previous state.
      - Step 3: Score the cell's output with `attention_mechanism`.
      - Step 4: Calculate the alignments by passing the score through the
        `normalizer`.
      - Step 5: Calculate the context vector as the inner product between the
        alignments and the attention_mechanism's values (memory).
      - Step 6: Calculate the attention output by concatenating the cell output
        and context through the attention layer (a linear layer with
        `attention_layer_size` outputs).
  
      Args:
        inputs: (Possibly nested tuple of) Tensor, the input at this time step.
        state: An instance of `AttentionWrapperState` containing
          tensors from the previous time step.
  
      Returns:
        A tuple `(attention_or_cell_output, next_state)`, where:
  
        - `attention_or_cell_output` depending on `output_attention`.
        - `next_state` is an instance of `AttentionWrapperState`
           containing the state calculated at this time step.
  
      Raises:
        TypeError: If `state` is not an instance of `AttentionWrapperState`.
docstring_summary: Perform a step of attention-wrapped RNN.
docstring_tokens: Perform a step of attention - wrapped RNN .
function: def call(self, inputs, state):
      """Perform a step of attention-wrapped RNN.
  
      - Step 1: Mix the `inputs` and previous step's `attention` output via
        `cell_input_fn`.
      - Step 2: Call the wrapped `cell` with this input and its previous state.
      - Step 3: Score the cell's output with `attention_mechanism`.
      - Step 4: Calculate the alignments by passing the score through the
        `normalizer`.
      - Step 5: Calculate the context vector as the inner product between the
        alignments and the attention_mechanism's values (memory).
      - Step 6: Calculate the attention output by concatenating the cell output
        and context through the attention layer (a linear layer with
        `attention_layer_size` outputs).
  
      Args:
        inputs: (Possibly nested tuple of) Tensor, the input at this time step.
        state: An instance of `AttentionWrapperState` containing
          tensors from the previous time step.
  
      Returns:
        A tuple `(attention_or_cell_output, next_state)`, where:
  
        - `attention_or_cell_output` depending on `output_attention`.
        - `next_state` is an instance of `AttentionWrapperState`
           containing the state calculated at this time step.
  
      Raises:
        TypeError: If `state` is not an instance of `AttentionWrapperState`.
      """
      if not isinstance(state, AttentionWrapperState):
        raise TypeError("Expected state to be instance of AttentionWrapperState. "
                        "Received type %s instead."  % type(state))
  
      # Step 1: Calculate the true inputs to the cell based on the
      # previous attention value.
      cell_inputs = self._cell_input_fn(inputs, state.attention)
      cell_state = state.cell_state
      cell_output, next_cell_state = self._cell(cell_inputs, cell_state)
  
      cell_batch_size = (
          cell_output.shape[0].value or array_ops.shape(cell_output)[0])
      error_message = (
          "When applying AttentionWrapper %s: " % self.name +
          "Non-matching batch sizes between the memory "
          "(encoder output) and the query (decoder output).  Are you using "
          "the BeamSearchDecoder?  You may need to tile your memory input via "
          "the tf.contrib.seq2seq.tile_batch function with argument "
          "multiple=beam_width.")
      with ops.control_dependencies(
          self._batch_size_checks(cell_batch_size, error_message)):
        cell_output = array_ops.identity(
            cell_output, name="checked_cell_output")
  
      if self._is_multi:
        previous_alignments = state.alignments
        previous_alignment_history = state.alignment_history
      else:
        previous_alignments = [state.alignments]
        previous_alignment_history = [state.alignment_history]
  
      all_alignments = []
      all_attentions = []
      all_histories = []
      for i, attention_mechanism in enumerate(self._attention_mechanisms):
        attention, alignments = _compute_attention(
            attention_mechanism, cell_output, previous_alignments[i],
            self._attention_layers[i] if self._attention_layers else None)
        alignment_history = previous_alignment_history[i].write(
            state.time, alignments) if self._alignment_history else ()
  
        all_alignments.append(alignments)
        all_histories.append(alignment_history)
        all_attentions.append(attention)
  
      attention = array_ops.concat(all_attentions, 1)
      next_state = AttentionWrapperState(
          time=state.time + 1,
          cell_state=next_cell_state,
          attention=attention,
          alignments=self._item_or_tuple(all_alignments),
          alignment_history=self._item_or_tuple(all_histories))
  
      if self._output_attention:
        return attention, next_state
      else:
        return cell_output, next_state
function_tokens: def call ( self , inputs , state ) : if not isinstance ( state , AttentionWrapperState ) : raise TypeError ( "Expected state to be instance of AttentionWrapperState. " "Received type %s instead." % type ( state ) ) # Step 1: Calculate the true inputs to the cell based on the # previous attention value. cell_inputs = self . _cell_input_fn ( inputs , state . attention ) cell_state = state . cell_state cell_output , next_cell_state = self . _cell ( cell_inputs , cell_state ) cell_batch_size = ( cell_output . shape [ 0 ] . value or array_ops . shape ( cell_output ) [ 0 ] ) error_message = ( "When applying AttentionWrapper %s: " % self . name + "Non-matching batch sizes between the memory " "(encoder output) and the query (decoder output).  Are you using " "the BeamSearchDecoder?  You may need to tile your memory input via " "the tf.contrib.seq2seq.tile_batch function with argument " "multiple=beam_width." ) with ops . control_dependencies ( self . _batch_size_checks ( cell_batch_size , error_message ) ) : cell_output = array_ops . identity ( cell_output , name = "checked_cell_output" ) if self . _is_multi : previous_alignments = state . alignments previous_alignment_history = state . alignment_history else : previous_alignments = [ state . alignments ] previous_alignment_history = [ state . alignment_history ] all_alignments = [ ] all_attentions = [ ] all_histories = [ ] for i , attention_mechanism in enumerate ( self . _attention_mechanisms ) : attention , alignments = _compute_attention ( attention_mechanism , cell_output , previous_alignments [ i ] , self . _attention_layers [ i ] if self . _attention_layers else None ) alignment_history = previous_alignment_history [ i ] . write ( state . time , alignments ) if self . _alignment_history else ( ) all_alignments . append ( alignments ) all_histories . append ( alignment_history ) all_attentions . append ( attention ) attention = array_ops . concat ( all_attentions , 1 ) next_state = AttentionWrapperState ( time = state . time + 1 , cell_state = next_cell_state , attention = attention , alignments = self . _item_or_tuple ( all_alignments ) , alignment_history = self . _item_or_tuple ( all_histories ) ) if self . _output_attention : return attention , next_state else : return cell_output , next_state