def testBowEncodersSharingEmbeddings(self):
   with self.cached_session() as sess:
     docs = [[0, 1], [2, 3]]
     enc_1 = encoders.bow_encoder(docs, 4, 3, scope='test')
     enc_2 = encoders.bow_encoder(docs, 4, 3, scope='test', reuse=True)
     sess.run(variables.global_variables_initializer())
     avg_1, avg_2 = sess.run([enc_1, enc_2])
     self.assertAllEqual(avg_1, avg_2)
 def testBowEncodersSharingEmbeddingsSharedScope(self):
   with self.cached_session() as sess:
     docs = [[0, 1], [2, 3]]
     enc_1 = encoders.bow_encoder(docs, 4, 3, scope='bow')
     variable_scope.get_variable_scope().reuse_variables()
     enc_2 = encoders.bow_encoder(docs, 4, 3, scope='bow')
     sess.run(variables.global_variables_initializer())
     avg_1, avg_2 = sess.run([enc_1, enc_2])
     self.assertAllEqual(avg_1, avg_2)
 def testBowEncoderSparseTensor(self):
   with self.cached_session() as sess:
     docs = [[0, 1], [2, 3]]
     sparse_docs = sparse_ops.dense_to_sparse_tensor(docs)
     enc = encoders.bow_encoder(sparse_docs, 4, 3)
     sess.run(variables.global_variables_initializer())
     self.assertAllEqual([2, 3], enc.eval().shape)
 def testBowEncoderReuseEmbeddingsVariable(self):
   with self.cached_session() as sess:
     docs = [[1, 1], [2, 3]]
     with variable_scope.variable_scope('test'):
       v = _get_const_var('embeddings', (4, 3),
                          [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]])
       self.assertEqual(v.name, 'test/embeddings:0')
     enc = encoders.bow_encoder(docs, 4, 3, scope='test', reuse=True)
     sess.run(variables.global_variables_initializer())
     self.assertAllClose([[3., 4., 5.], [7.5, 8.5, 9.5]], enc.eval())
 def testBowEncoderSparseTensorDenseLookup(self):
   with self.cached_session():
     docs = [[0, 1]]
     sparse_docs = sparse_ops.dense_to_sparse_tensor(docs)
     with self.assertRaises(TypeError):
       encoders.bow_encoder(sparse_docs, 4, 3, sparse_lookup=False)
 def testBowEncoderDense(self):
   with self.cached_session() as sess:
     docs = [[0, 1], [2, 3], [0, 0], [0, 0]]
     enc = encoders.bow_encoder(docs, 4, 3, sparse_lookup=False)
     sess.run(variables.global_variables_initializer())
     self.assertAllEqual([4, 3], enc.eval().shape)
 def testBowEncoderSparseEmptyRow(self):
   with self.cached_session() as sess:
     docs = [[0, 1], [2, 3], [0, 0]]
     enc = encoders.bow_encoder(docs, 4, 5)
     sess.run(variables.global_variables_initializer())
     self.assertAllEqual([3, 5], enc.eval().shape)