Commit a21220b7 authored by Shakthi Visagan's avatar Shakthi Visagan
Browse files

more work

parent 01425132
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -429,8 +429,8 @@ def _cosine_dist(x, y):
  """
  x_norm = tf.nn.l2_normalize(x, axis=1)
  y_norm = tf.nn.l2_normalize(y, axis=1)

  return tf.reduce_sum(tf.multiply(x_norm, y_norm))
  # the cosine distance is 1 - the cosine similarity
  return 1. - tf.reduce_sum(tf.multiply(x_norm, y_norm), axis=1)


class AttnLSTMEmbedding(tf.keras.layers.Layer):
+4 −3
Original line number Diff line number Diff line
@@ -10,9 +10,10 @@ 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)
    print(layers._cosine_dist(x,y))

    y_same = np.ones((5, 4)).astype(np.float32)
    y_far = np.zeros((5, 4)).astype(np.float32)
    assert sum(layers._cosine_dist(x,y_same)) == 0
    assert sum(layers._cosine_dist(x,y_far)) == 5

  def test_highway(self):
    """Test invoking Highway."""