import tensorflow as tf

        # execute mean pooling based on pooling_mask[bs, sluh, sld] and pooling_data[bs,sluh,sld,hn]
        pooling_data = mask_for_high_rank(pooling_data, pooling_mask)  # [bs,sluh,sld,hn]
        pooling_data_sum = tf.reduce_sum(pooling_data, -2)  # [bs,sluh,hn]
        pooling_den = tf.reduce_sum(tf.cast(pooling_mask, tf.int32), -1, keep_dims=True)  # [bs,sluh]
        pooling_den = tf.where(tf.equal(pooling_den, 0), tf.ones_like(pooling_den), pooling_den)

        pooling_result = pooling_data_sum / tf.cast(pooling_den, tf.float32)
        return pooling_result


def scaled_tanh(x, scale=5.):
    return scale * tf.nn.tanh(1./scale * x)