def test_scattered_embedding_coverage(self):
        with self.test_session():
            size = 8
            embedding_weights = self._random_weights(size=size, num_shards=3)
            values = constant_op.constant(["foo"])

            # Large embedding dimension to cover the full range of weights.
            embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
                embedding_weights, values, dimension=100).eval()

            self.assertEqual(len(np.unique(embedding_lookup_result[0])), size)
    def test_scattered_embedding_consistency(self):
        with self.test_session():
            embedding_weights = self._random_weights()
            values = constant_op.constant(["foo", "foo"])

            embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
                embedding_weights, values, dimension=10).eval()

            self.assertAllEqual(embedding_lookup_result.shape, [2, 10])
            self.assertAllEqual(embedding_lookup_result[0],
                                embedding_lookup_result[1])
예제 #3
0
  def test_scattered_embedding_coverage(self):
    with self.cached_session():
      size = 8
      embedding_weights = self._random_weights(size=size, num_shards=3)
      values = constant_op.constant(["foo"])

      # Large embedding dimension to cover the full range of weights.
      embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
          embedding_weights, values, dimension=100).eval()

      self.assertEqual(len(np.unique(embedding_lookup_result[0])), size)
예제 #4
0
  def test_scattered_embedding_consistency(self):
    with self.cached_session():
      embedding_weights = self._random_weights()
      values = constant_op.constant(["foo", "foo"])

      embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
          embedding_weights, values, dimension=10).eval()

      self.assertAllEqual(embedding_lookup_result.shape, [2, 10])
      self.assertAllEqual(embedding_lookup_result[0],
                          embedding_lookup_result[1])
예제 #5
0
  def test_scattered_embedding_multi_dimension(self):
    with self.cached_session(), local_variable_scope():
      embedding_weights = self._random_weights()
      values = constant_op.constant([["foo", "bar", "bar"],
                                     ["bar", "bar", "foo"]])

      embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
          embedding_weights, values, dimension=10).eval()

      self.assertAllEqual(embedding_lookup_result.shape, [2, 3, 10])
      self.assertAllEqual(embedding_lookup_result[0][0],
                          embedding_lookup_result[1][2])
    def test_scattered_embedding_multi_dimension(self):
        with self.cached_session(), local_variable_scope():
            embedding_weights = self._random_weights()
            values = constant_op.constant([["foo", "bar", "bar"],
                                           ["bar", "bar", "foo"]])

            embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
                embedding_weights, values, dimension=10).eval()

            self.assertAllEqual(embedding_lookup_result.shape, [2, 3, 10])
            self.assertAllEqual(embedding_lookup_result[0][0],
                                embedding_lookup_result[1][2])
    def test_scattered_embedding_multiple_partition(self):
        with self.test_session():
            embedding_weights = self._random_weights(num_shards=7)
            values = constant_op.constant([4, 4, 5])

            embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
                embedding_weights, values, dimension=5).eval()

            self.assertAllEqual(embedding_lookup_result.shape, [3, 5])
            self.assertAllEqual(embedding_lookup_result[0],
                                embedding_lookup_result[1])
            # Different embedding expected for different value.
            embedding_diff = np.min(
                (embedding_lookup_result[2] - embedding_lookup_result[0])**2)
            self.assertGreater(embedding_diff, 0)
예제 #8
0
  def test_scattered_embedding_multiple_partition(self):
    with self.cached_session():
      embedding_weights = self._random_weights(num_shards=7)
      values = constant_op.constant([4, 4, 5])

      embedding_lookup_result = embedding_ops.scattered_embedding_lookup(
          embedding_weights, values, dimension=5).eval()

      self.assertAllEqual(embedding_lookup_result.shape, [3, 5])
      self.assertAllEqual(embedding_lookup_result[0],
                          embedding_lookup_result[1])
      # Different embedding expected for different value.
      embedding_diff = np.min(
          (embedding_lookup_result[2] - embedding_lookup_result[0])**2)
      self.assertGreater(embedding_diff, 0)