def calc_overlap(vec1, vec2):
    """
    :param vec1: batch of binary vectors
    :param vec2: batch of binary vectors
    :return: (float) vec1 and vec2 similarity (overlap)
    """
    vec1 = vec1.flatten(start_dim=1)
    vec2 = vec2.flatten(start_dim=1)
    k_active = (vec1.sum(dim=1) + vec2.sum(dim=1)) / 2
    similarity = (vec1 * vec2).sum(dim=1) / k_active
    similarity = similarity.mean()
    return similarity