import tensorflow as tf

        else:
            direct_mask = tf.less(head_idxs, dep_idxs)  # [bs, slh, sld]
    # [bs, slh, slh]
    rep_mask_tile = tf.logical_and(tf.expand_dims(rep_dep_mask, 1), tf.expand_dims(rep_head_mask, 2))
    attn_mask = tf.logical_and(direct_mask, rep_mask_tile)  # [bs, slh, sld]

    # tensor tile
    rep_map_tile = tf.tile(tf.expand_dims(rep_dep_tensor, 1), [1, sl_head, 1, 1])  # bs,slh,sld,vec
    with tf.variable_scope('attention'):  # bs,sl,sl,vec
        f_bias = tf.get_variable('f_bias', [ivec], tf.float32, tf.constant_initializer(0.))
        dependent = linear(rep_dep_tensor_dp, ivec, False, scope='linear_dependent')  # bs,sld,vec
        dependent_etd = tf.expand_dims(dependent, 1)  # bs,1,sld,vec
        head = linear(rep_head_tensor_dp, ivec, False, scope='linear_head')  # bs,slh,vec
        head_etd = tf.expand_dims(head, 2)  # bs,slh,1,vec

        logits = scaled_tanh(dependent_etd + head_etd + f_bias, 5.0)  # bs,slh,sld,vec
        logits_masked = exp_mask_for_high_rank(logits, attn_mask)  # bs,slh,sld,vec
        attn_score = tf.nn.softmax(logits_masked, 2)  # bs,slh,sld,vec
        attn_score = mask_for_high_rank(attn_score, attn_mask)
        attn_result = tf.reduce_sum(attn_score * rep_map_tile, 2)  # bs,slh,vec -> head_org_idx
    return attn_result

