import tensorflow as tf

        fw_result = directional_attention_with_selections(
            rep_tensor, rep_mask, dep_selection, head_selection,
            'forward', hn, keep_unselected,
            'forward_resa', keep_prob, is_train, wd, activation
        )
        bw_result = directional_attention_with_selections(
            rep_tensor, rep_mask, dep_selection, head_selection,
            'backward', hn, keep_unselected,
            'backward_resa', keep_prob, is_train, wd, activation
        )
        return tf.concat([fw_result, bw_result], -1)


def directional_attention_with_selections(
        rep_tensor, rep_mask, dep_selection, head_selection, direction=None, hn=None, keep_unselected=True,
        scope=None, keep_prob=1., is_train=None, wd=0., activation='elu'):

    bs, sl, vec = tf.shape(rep_tensor)[0], tf.shape(rep_tensor)[1], tf.shape(rep_tensor)[2]
    org_ivec = rep_tensor.get_shape().as_list()[2]
    ivec = hn or org_ivec
