def map_to_embedding(self, inputs):
"""
Map the input ids into embedding
:param inputs: a 2D Tensor of shape (num_steps, batch_size) of type int32, denoting word ids
:return: a 3D Tensor of shape (num_Steps, batch_size, embedding_size) of type float32.
"""
if self.has_embedding:
# The Variables are already created in the compile(), need to
with tf.variable_scope('embedding', initializer=self.initializer):
with tf.device("/cpu:0"): # Force CPU since GPU implementation is missing
embedding = tf.get_variable("embedding",
[self.vocab_size+1, self.embedding_size],
dtype=data_type())
return tf.nn.embedding_lookup(embedding, inputs)
else:
return None
评论列表
文章目录