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

Method test_decode_op

language/emql/module_test.py:89–118  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

87 np.array([[0.5, 0, 0, 0.5]], np.float32))
88
89 def test_decode_op(self):
90 params = {
91 'cm_width': 100,
92 'cm_depth': 5,
93 'intermediate_top_k': 2
94 }
95 self.sess.run(tf.global_variables_initializer())
96 all_entity_sketches = tf.constant(
97 [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [11, 13, 15, 17, 19],
98 [12, 14, 16, 18, 20]],
99 dtype=tf.int32)
100
101 embeddings_mat = tf.constant(
102 [[0.1, 0.2, 0.3], [0.2, 0.3, 0.4], [-0.1, -0.2, -0.3],
103 [-0.2, -0.3, -0.4]], dtype=tf.float32)
104 set1_ids = tf.constant([[0, 1]], dtype=tf.int32)
105 weights = tf.constant(
106 np.array([[1, 1]], dtype=np.float32), dtype=tf.float32)
107
108 set1_embs = tf.nn.embedding_lookup(embeddings_mat, set1_ids) # b, s, d
109 set1_embs = tf.reduce_sum(set1_embs, axis=1) # b, d
110 set1_sketch = module.create_cm_sketch(
111 set1_ids, weights, all_entity_sketches, params['cm_width'])
112
113 topk_ids, _ = module.decode_op(
114 params, set1_embs, set1_sketch, embeddings_mat, all_entity_sketches)
115 # The returned value should be entity in the set, scored by the centroid
116 # [0.15, 0.25, 0.35]. Since the embedding of entity 1 ([0.2, 0.3, 0.4])
117 # has the larger inner product than entity 0 ([0.1, 0.2, 0.3]).
118 self.assertAllEqual(topk_ids, np.array([[1, 0]]))
119
120 def test_intersection_union_op(self):
121 params = {

Callers

nothing calls this directly

Calls 2

constantMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected