def __call__(self, query, state):
    '\n        Calculate the alignments and next_state for the current decoder output.\n\n        Arguments:\n            query (tf.Tensor):\n                Decoder cell outputs to compare to the keys (memory).\n                The shape is expected to be shape=(B, num_units) with B being the batch size\n                and `num_units` being the output size of the decoder_cell.\n\n            state (tf.Tensor):\n                In Luong attention the state is equal to the alignments. Therefore this will\n                contain the alignments from the previous decoding step.\n\n        Returns:\n            (alignments, next_state):\n                alignments (tf.Tensor):\n                    The normalized attention scores for the attention window. The shape is\n                    shape=(B, 2D+1), with B being the batch size and `2D+1` being the window size.\n                next_state (tf.Tensor):\n                    In Luong attention this is equal to `alignments`.\n        '
    with tf.variable_scope(None, 'local_luong_attention', [query]):
        num_units = self._keys.get_shape()[(- 1)]
        source_seq_length = tf.shape(self._keys)[1]
        if (self.attention_mode == AttentionMode.PREDICTIVE):
            vp = tf.get_variable(name='local_v_p', shape=[num_units, 1], dtype=tf.float32)
            wp = tf.get_variable(name='local_w_p', shape=[num_units, num_units], dtype=tf.float32)
            _intermediate_result = tf.transpose(tf.tensordot(wp, query, [0, 1]))
            _tmp = tf.transpose(tf.tensordot(vp, tf.tanh(_intermediate_result), [0, 1]))
            self.p = (tf.cast(source_seq_length, tf.float32) * tf.sigmoid(_tmp))
        elif (self.attention_mode == AttentionMode.MONOTONIC):
            self.p = tf.tile([[self.time]], tf.convert_to_tensor([self.batch_size, 1]))
            self.p = tf.maximum(self.p, self.d)
            self.p = tf.minimum(self.p, (source_seq_length - (self.d + 1)))
            self.p = tf.cast(self.p, dtype=tf.float32)
        start_index = (tf.floor(self.p) - self.d)
        start_index = tf.cast(start_index, dtype=tf.int32)
        self.window_start = tf.maximum(0, start_index)
        stop_index = ((tf.floor(self.p) + self.d) + 1)
        stop_index = tf.cast(stop_index, dtype=tf.int32)
        self.window_stop = tf.minimum(source_seq_length, stop_index)
        self.full_seq_pre_padding = tf.abs(start_index)
        self.full_seq_post_padding = tf.abs((stop_index - source_seq_length))
        self.window_pre_padding = tf.abs((self.window_start - start_index))
        self.window_post_padding = tf.abs((self.window_stop - stop_index))
        with tf.variable_scope(None, 'window_extraction', [query]):
            windows = []
            for i in range(0, self.const_batch_size):
                __window = self._keys[i, self.window_start[i][0]:self.window_stop[i][0], :]
                paddings = [[self.window_pre_padding[i][0], self.window_post_padding[i][0]], [0, 0]]
                __window = tf.pad(__window, paddings, 'CONSTANT')
                windows.append(__window)
            window = tf.stack(windows)
        if (self.score_mode == AttentionScore.DOT):
            score = _luong_dot_score(query, window, self._scale)
        elif (self.score_mode == AttentionScore.GENERAL):
            score = _luong_general_score(query, window)
        elif (self.score_mode == AttentionScore.CONCAT):
            score = _luong_concat_score(query, window)
        else:
            score = None
            raise Exception('An invalid attention scoring mode was supplied.')
    alignments = self._probability_fn(score, state)
    next_state = alignments
    return (alignments, next_state)
Calculate the alignments and next_state for the current decoder output.

Arguments:
    query (tf.Tensor):
        Decoder cell outputs to compare to the keys (memory).
        The shape is expected to be shape=(B, num_units) with B being the batch size
        and `num_units` being the output size of the decoder_cell.

    state (tf.Tensor):
        In Luong attention the state is equal to the alignments. Therefore this will
        contain the alignments from the previous decoding step.

Returns:
    (alignments, next_state):
        alignments (tf.Tensor):
            The normalized attention scores for the attention window. The shape is
            shape=(B, 2D+1), with B being the batch size and `2D+1` being the window size.
        next_state (tf.Tensor):
            In Luong attention this is equal to `alignments`.
def __call__(self, query, state):
    '\n        Calculate the alignments and next_state for the current decoder output.\n\n        Arguments:\n            query (tf.Tensor):\n                Decoder cell outputs to compare to the keys (memory).\n                The shape is expected to be shape=(B, num_units) with B being the batch size\n                and `num_units` being the output size of the decoder_cell.\n\n            state (tf.Tensor):\n                In Luong attention the state is equal to the alignments. Therefore this will\n                contain the alignments from the previous decoding step.\n\n        Returns:\n            (alignments, next_state):\n                alignments (tf.Tensor):\n                    The normalized attention scores for the attention window. The shape is\n                    shape=(B, 2D+1), with B being the batch size and `2D+1` being the window size.\n                next_state (tf.Tensor):\n                    In Luong attention this is equal to `alignments`.\n        '
    with tf.variable_scope(None, 'local_luong_attention', [query]):
        num_units = self._keys.get_shape()[(- 1)]
        source_seq_length = tf.shape(self._keys)[1]
        if (self.attention_mode == AttentionMode.PREDICTIVE):
            vp = tf.get_variable(name='local_v_p', shape=[num_units, 1], dtype=tf.float32)
            wp = tf.get_variable(name='local_w_p', shape=[num_units, num_units], dtype=tf.float32)
            _intermediate_result = tf.transpose(tf.tensordot(wp, query, [0, 1]))
            _tmp = tf.transpose(tf.tensordot(vp, tf.tanh(_intermediate_result), [0, 1]))
            self.p = (tf.cast(source_seq_length, tf.float32) * tf.sigmoid(_tmp))
        elif (self.attention_mode == AttentionMode.MONOTONIC):
            self.p = tf.tile([[self.time]], tf.convert_to_tensor([self.batch_size, 1]))
            self.p = tf.maximum(self.p, self.d)
            self.p = tf.minimum(self.p, (source_seq_length - (self.d + 1)))
            self.p = tf.cast(self.p, dtype=tf.float32)
        start_index = (tf.floor(self.p) - self.d)
        start_index = tf.cast(start_index, dtype=tf.int32)
        self.window_start = tf.maximum(0, start_index)
        stop_index = ((tf.floor(self.p) + self.d) + 1)
        stop_index = tf.cast(stop_index, dtype=tf.int32)
        self.window_stop = tf.minimum(source_seq_length, stop_index)
        self.full_seq_pre_padding = tf.abs(start_index)
        self.full_seq_post_padding = tf.abs((stop_index - source_seq_length))
        self.window_pre_padding = tf.abs((self.window_start - start_index))
        self.window_post_padding = tf.abs((self.window_stop - stop_index))
        with tf.variable_scope(None, 'window_extraction', [query]):
            windows = []
            for i in range(0, self.const_batch_size):
                __window = self._keys[i, self.window_start[i][0]:self.window_stop[i][0], :]
                paddings = [[self.window_pre_padding[i][0], self.window_post_padding[i][0]], [0, 0]]
                __window = tf.pad(__window, paddings, 'CONSTANT')
                windows.append(__window)
            window = tf.stack(windows)
        if (self.score_mode == AttentionScore.DOT):
            score = _luong_dot_score(query, window, self._scale)
        elif (self.score_mode == AttentionScore.GENERAL):
            score = _luong_general_score(query, window)
        elif (self.score_mode == AttentionScore.CONCAT):
            score = _luong_concat_score(query, window)
        else:
            score = None
            raise Exception('An invalid attention scoring mode was supplied.')
    alignments = self._probability_fn(score, state)
    next_state = alignments
    return (alignments, next_state)