import tensorflow as tf

                numerator = -tf.pow((idx - pos), tf.convert_to_tensor(2, dtype=tf.float32))
                div = tf.truediv(numerator, 2 * sigma ** 2)

                weights *= tf.exp(div)  # result of the truncated normal distribution
                # normalize to keep a probability distribution
                # weights /= (tf.reduce_sum(weights, axis=1, keep_dims=True) + 10e-12)

            weighted_average = tf.reduce_sum(tf.expand_dims(weights, axis=2) * hidden_states, axis=1)

        return weighted_average, weights


def attention(encoder, scope=None, **kwargs):
    attention_functions = {
