def model_intersection(self, features,
                         params):
    """Compute logits for intersection.

    A representation of intersection is the sum of representations of sets
    that are being intersected.

    Args:
      features: features
        -- candidate_set1: a k-hot vector of length num_entities representing
                           the entities in the first set.
                           e.g. [1, 0, 1, 0, 1, 1, 0, 0]
        -- candidate_set2: a k-hot vector of length num_entities representing
                           the entities in the first set.
                           e.g. [1, 1, 0, 0, 1, 0, 0, 0]
        -- labels: a k-hot vector of length num_entities representing
                           the entities in the intersection of two sets.
                           e.g. [1, 0, 0, 0, 1, 0, 0, 0]
      params: hyper-parameters

    Returns:
      predictions and losses
    """
    candidate_set1, candidate_set2, labels = features
    candidate_set1_mask = tf.expand_dims(candidate_set1, axis=2)
    # batch_size, num_candidate, 1
    candidate_set2_mask = tf.expand_dims(candidate_set2, axis=2)
    # batch_size, num_candidate, 1
    candidate_embs = self.entity_embeddings_mat
    # batch_size, num_candidate, hidden_size
    set1_embs_query = tf.reduce_sum(
        candidate_embs * candidate_set1_mask, axis=1, keepdims=True) \
        / tf.reduce_sum(candidate_set1_mask, axis=1, keepdims=True)
    # batch_size, 1, hidden_size
    set2_embs_query = tf.reduce_sum(
        candidate_embs * candidate_set2_mask, axis=1, keepdims=True) \
        / tf.reduce_sum(candidate_set2_mask, axis=1, keepdims=True)
    # batch_size, 1, hidden_size
    intersection_embs_query = set1_embs_query + set2_embs_query
    # batch_size, 1, hidden_size
    logits, _ = self.compute_logits(candidate_embs, intersection_embs_query,
                                    params['entity_emb_size'])
    loss = self.compute_tf_loss(logits, labels)
    return loss, {'logits': logits, 'labels': labels}
Compute logits for intersection.

    A representation of intersection is the sum of representations of sets
    that are being intersected.

    Args:
      features: features
        -- candidate_set1: a k-hot vector of length num_entities representing
                           the entities in the first set.
                           e.g. [1, 0, 1, 0, 1, 1, 0, 0]
        -- candidate_set2: a k-hot vector of length num_entities representing
                           the entities in the first set.
                           e.g. [1, 1, 0, 0, 1, 0, 0, 0]
        -- labels: a k-hot vector of length num_entities representing
                           the entities in the intersection of two sets.
                           e.g. [1, 0, 0, 0, 1, 0, 0, 0]
      params: hyper-parameters

    Returns:
      predictions and losses
    
language/emql/model.py