def additive_self_attention(units, n_hidden=None, n_output_features=None, activation=None):
n_input_features = K.int_shape(units)[<NUM_LIT:2>]<EOL>if n_hidden is None:<EOL><INDENT>n_hidden = n_input_features<EOL><DEDENT>if n_output_features is None:<EOL><INDENT>n_output_features = n_input_features<EOL><DEDENT>exp1 = Lambda(lambda x: expand_tile(x, axis=<NUM_LIT:1>))(units)<EOL>exp2 = Lambda(lambda x: expand_tile(x, axis=<NUM_LIT:2>))(units)<EOL>units_pairs = Concatenate(axis=<NUM_LIT:3>)([exp1, exp2])<EOL>query = Dense(n_hidden, activation="<STR_LIT>")(units_pairs)<EOL>attention = Dense(<NUM_LIT:1>, activation=lambda x: softmax(x, axis=<NUM_LIT:2>))(query)<EOL>attended_units = Lambda(lambda x: K.sum(attention * x, axis=<NUM_LIT:2>))(exp1)<EOL>output = Dense(n_output_features, activation=activation)(attended_units)<EOL>return output<EOL>
Compute additive self attention for time series of vectors (with batch dimension)
        the formula: score(h_i, h_j) = <v, tanh(W_1 h_i + W_2 h_j)>
        v is a learnable vector of n_hidden dimensionality,
        W_1 and W_2 are learnable [n_hidden, n_input_features] matrices

Args:
    units: tf tensor with dimensionality [batch_size, time_steps, n_input_features]
    n_hidden: number of2784131 units in hidden representation of similarity measure
    n_output_features: number of features in output dense layer
    activation: activation at the output

Returns:
    output: self attended tensor with dimensionality [batch_size, time_steps, n_output_features]