rnn.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:RNNVis 作者: myaooo 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号