import tensorflow as tf

            pos = tf.reshape(pos, [-1, 1])
            pos = tf.minimum(pos, encoder_input_length - 1)

            idx = tf.tile(tf.to_float(tf.range(attn_length)), tf.stack([batch_size]))
            idx = tf.reshape(idx, [-1, attn_length])

            low = pos - encoder.attn_window_size
            high = pos + encoder.attn_window_size

            mlow = tf.to_float(idx < low)
            mhigh = tf.to_float(idx > high)
            m = mlow + mhigh
            m += tf.to_float(idx >= encoder_input_length)

            mask = tf.to_float(tf.equal(m, 0.0))

            e = compute_energy(hidden_states, state, encoder, input_length=encoder_input_length, **kwargs)
            weights = softmax(e, mask=mask)

            if encoder.attn_window_size > 0:
                sigma = encoder.attn_window_size / 2
                numerator = -tf.pow((idx - pos), tf.convert_to_tensor(2, dtype=tf.float32))
                div = tf.truediv(numerator, 2 * sigma ** 2)

