def encode_op(params,
              set_ids, set_mask,
              embeddings_mat, all_sketches
              ):
  """Encode set to EmQL representations.

  Args:
    params: a dictionary of hyper-parameters.
    set_ids: a tf.Tensor of element ids in the set.
    set_mask: a 0/1 tf.Tensor of mask of element ids.
    embeddings_mat: embedding matrix of shape [vocab_size, d]
    all_sketches: precomputed hash ids of all candidate elements.

  Returns:
    dense embedding and sparse count-min sketch of the EmQL representation.
  """
  set_embs = tf.nn.embedding_lookup(embeddings_mat, set_ids)  # b, s, d
  set_mask = tf.cast(tf.expand_dims(set_mask, axis=2), dtype=tf.float32)
  set_embs = tf.reduce_sum(set_embs * set_mask, axis=1)  # b, d
  set_count = tf.reduce_sum(set_mask, axis=1)  # b, 1
  set_embs /= set_count  # b, d

  set_softmax = tf.squeeze(set_mask, axis=2) / set_count  # b, s
  set_sketch = create_cm_sketch(
      set_ids, set_softmax, all_sketches, params['cm_width'])
  return set_embs, set_sketch
Encode set to EmQL representations.

  Args:
    params: a dictionary of hyper-parameters.
    set_ids: a tf.Tensor of element ids in the set.
    set_mask: a 0/1 tf.Tensor of mask of element ids.
    embeddings_mat: embedding matrix of shape [vocab_size, d]
    all_sketches: precomputed hash ids of all candidate elements.

  Returns:
    dense embedding and sparse count-min sketch of the EmQL representation.
  
language/emql/module.py