예제 #1
0
 def testEmptyLeading(self):
   export_v2.export_module_from_file(
       embedding_file=self._embedding_file_path,
       export_path=self.get_temp_dir(),
       num_oov_buckets=1,
       num_lines_to_ignore=0,
       num_lines_to_use=None)
   hub_module = hub.load(self.get_temp_dir())
   tokens = tf.constant(["", "cat dog"])
   embeddings = hub_module(tokens)
   self.assertAllClose(
       embeddings.numpy(), [[0.0, 0.0, 0.0], [1.49, 3.22, 4.56]], rtol=0.02)
예제 #2
0
 def testNumLinesIgnore(self):
     export_v2.export_module_from_file(
         embedding_file=self._embedding_file_path,
         export_path=self.get_temp_dir(),
         num_oov_buckets=1,
         num_lines_to_ignore=1,
         num_lines_to_use=None)
     hub_module = hub.load(self.get_temp_dir())
     tokens = tf.constant(["cat", "dog", "mouse"])
     embeddings = hub_module(tokens)
     self.assertAllClose(embeddings.numpy(),
                         [[0.0, 0.0, 0.0], [1, 2, 3], [0.5, 0.1, 0.6]],
                         rtol=0.02)
예제 #3
0
 def testExportTextEmbeddingModule(self):
     export_v2.export_module_from_file(
         embedding_file=self._embedding_file_path,
         export_path=self.get_temp_dir(),
         num_oov_buckets=1,
         num_lines_to_ignore=0,
         num_lines_to_use=None)
     hub_module = hub.load(self.get_temp_dir())
     tokens = tf.constant(["cat", "cat cat", "lizard. dog", "cat? dog", ""])
     embeddings = hub_module(tokens)
     self.assertAllClose(
         embeddings.numpy(),
         [[1.11, 2.56, 3.45], [1.57, 3.62, 4.88], [0.70, 1.41, 2.12],
          [1.49, 3.22, 4.56], [0.0, 0.0, 0.0]],
         rtol=0.02)