Repository: sql-machine-learning/elasticdl

Issue:
Rename class EdlEmbedding into Embedding
For details, please refer to https://github.com/wangkuiyi/elasticdl/pull/1028#discussion_r314545339


Discussion:

Resolving patch:
diff --git a/elasticdl/python/layers/embedding.py b/elasticdl/python/elasticdl/layers/embedding.py
similarity index 95%
rename from elasticdl/python/layers/embedding.py
rename to elasticdl/python/elasticdl/layers/embedding.py
--- a/elasticdl/python/layers/embedding.py
+++ b/elasticdl/python/elasticdl/layers/embedding.py
@@ -2,7 +2,7 @@
 from tensorflow.python.keras.utils import tf_utils
 
 
-class EdlEmbedding(tf.keras.layers.Layer):
+class Embedding(tf.keras.layers.Layer):
     """
     Input: indexes for the embedding entries
            shape is (batch_size, input_length)
@@ -14,7 +14,7 @@ class EdlEmbedding(tf.keras.layers.Layer):
     """
 
     def __init__(self, embedding_dim, embedding_initializer="uniform"):
-        super(EdlEmbedding, self).__init__()
+        super(Embedding, self).__init__()
         self.embedding_dim = embedding_dim
         self.embedding_initializer = embedding_initializer
         self.tape = None
diff --git a/elasticdl/python/master/servicer.py b/elasticdl/python/master/servicer.py
--- a/elasticdl/python/master/servicer.py
+++ b/elasticdl/python/master/servicer.py
@@ -252,10 +252,9 @@ def ReportGradient(self, request, _):
             for k, v in request.gradient.items():
                 if k not in self._model:
                     if v.indices:
-                        # IndexedSlices are gradients of Embeddings Table
-                        # of EdlEmbedding layer
-                        # TODO: Updating Embedding Table of EdlEmbedding
-                        # layer will be implemented
+                        # IndexedSlices Gradients of elasticdl.layers.embedding
+                        # TODO: Use the gradients to update embedding
+                        # table of elasticdl.layers.embedding
                         arr = tensor_to_ndarray(v)
                         if k in self._edl_embedding_gradients:
                             self._edl_embedding_gradients[
@@ -266,8 +265,8 @@ def ReportGradient(self, request, _):
                         else:
                             self._edl_embedding_gradients[k] = arr
                         logger.warning(
-                            "Update Embedding Table of EdlEmbedding layer "
-                            "is not implemented."
+                            "Update embedding table of "
+                            "elasticdl.layers.embedding is not implemented."
                         )
                         continue
                     else:
diff --git a/elasticdl/python/worker/worker.py b/elasticdl/python/worker/worker.py
--- a/elasticdl/python/worker/worker.py
+++ b/elasticdl/python/worker/worker.py
@@ -56,7 +56,7 @@ def __init__(
         self._model = load_model_from_module(
             model_def, model_module, model_params
         )
-        # TODO: call find_layer and get EdlEmbedding layers
+        # TODO: call find_layer and get Embedding layers
         self._embedding_layers = []
         self._var_created = self._model.built
         self._dataset_fn = model_module[dataset_fn]
@@ -157,8 +157,8 @@ def report_gradient(self, grads):
                 bet_number += len(layer.bet_ids_pair)
             if len(grads_edlembedding) != bet_number:
                 raise ValueError(
-                    "EdlEmbedding related gradient number %d does not match"
-                    "the number of EdlEmbedding output tensor %d."
+                    "elasticdl.layers.embedding related gradient number %d "
+                    "does not match the number of its output tensor %d."
                     % (len(grads_edlembedding), bet_number)
                 )
 


Test patch:
diff --git a/elasticdl/python/tests/layer_test.py b/elasticdl/python/tests/layer_test.py
--- a/elasticdl/python/tests/layer_test.py
+++ b/elasticdl/python/tests/layer_test.py
@@ -10,7 +10,7 @@
     load_model_from_module,
     load_module,
 )
-from elasticdl.python.layers.embedding import EdlEmbedding
+from elasticdl.python.elasticdl.layers.embedding import Embedding
 
 
 def _get_model_zoo_path():
@@ -71,7 +71,7 @@ def embedding_lookup(self, ids, name, embedding_initializer):
 
 
 def create_embedding_layer(embedding_size, embedding_dim):
-    layer = EdlEmbedding(embedding_dim)
+    layer = Embedding(embedding_dim)
     worker = mock_worker(embedding_size, embedding_dim)
     layer.set_worker(worker)
     return layer