MCPcopy Create free account
hub / github.com/google-research/language / decode_op

Function decode_op

language/emql/module.py:109–137  ·  view source on GitHub ↗

Decode set representations to member ids. Args: params: a dictionary of hyper-parameters. set_embs: dense embeddings of set. set_sketch: sparse count-min sketch of set. embeddings_mat: embedding lookup table for elements in the set. all_sketches: precomputed hash ids of all ca

(params,
              set_embs, set_sketch,
              embeddings_mat, all_sketches
              )

Source from the content-addressed store, hash-verified

107
108
109def decode_op(params,
110 set_embs, set_sketch,
111 embeddings_mat, all_sketches
112 ):
113 """Decode set representations to member ids.
114
115 Args:
116 params: a dictionary of hyper-parameters.
117 set_embs: dense embeddings of set.
118 set_sketch: sparse count-min sketch of set.
119 embeddings_mat: embedding lookup table for elements in the set.
120 all_sketches: precomputed hash ids of all candidate elements.
121
122 Returns:
123 Ids of the top k predicted elements.
124 """
125 topk_logits, topk_ids = util.topk_search_fn(
126 set_embs, embeddings_mat, params['intermediate_top_k'])
127 # batch_size, top_k batch_size, top_k
128 if set_sketch is not None:
129 is_topk_eligible, _ = check_topk_fact_eligible(
130 topk_ids, set_sketch, all_sketches, params)
131 topk_logits += (1 - is_topk_eligible) * _VERY_NEG
132 # batch_size, top_k
133 _, argmax = tf.nn.top_k(topk_logits, k=params['intermediate_top_k'])
134 # batch_size, top_k
135 topk_ids = tf.gather(topk_ids, argmax, batch_dims=1)
136 # batch_size, top_k
137 return topk_ids, topk_logits
138
139
140def check_topk_fact_eligible(

Callers

nothing calls this directly

Calls 1

check_topk_fact_eligibleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…