Commit 570cfc1d authored by Shakthi Visagan's avatar Shakthi Visagan
Browse files

more work

parent afd74885
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -429,12 +429,10 @@ def _cosine_dist(x, y):
  y: tf.Tensor
    Input Tensor
  """
  x_reshape = tf.reshape(backend.sum(tf.square(x), axis=1), (-1, 1))
  y_reshape = tf.reshape(backend.sum(tf.square(y), axis=1), (1, -1))
  backend.dot(, ) + backend.epsilon()
  denom = backend.sqrt()
  x_norm = tf.nn.l2_normalize(x, axis=1)
  y_norm = tf.nn.l2_normalize(y, axis=1)

  return tf.math.divide(backend.dot(x, tf.transpose(y)), denom)
  return tf.reduce_sum(tf.multiply(x_norm,y_norm))


class AttnLSTMEmbedding(tf.keras.layers.Layer):
+7 −0
Original line number Diff line number Diff line
@@ -7,6 +7,13 @@ from tensorflow.python.framework import test_util

class TestLayers(test_util.TensorFlowTestCase):

  def test_cosine_dist(self):
    """Test invoking _cosine_dist."""
    x = np.ones((5, 4)).astype(np.float32)
    y = np.ones((5, 4)).astype(np.float32)
    assert layers._cosine_dist(x,y)


  def test_highway(self):
    """Test invoking Highway."""
    width = 5