rnn_cell_additions.py 文件源码

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

项目:gradual-learning-rnn 作者: zivaharoni 项目源码 文件源码
def __init__(self, cell, batch_size, hidden_size, output_keep_prob=1.0, state_keep_prob=1.0):
        self._cell = cell
        self._new_output_keep_prob = tf.placeholder(tf.float32, shape=[], name="output_keep_prob")
        self._new_state_keep_prob = tf.placeholder(tf.float32, shape=[], name="state_keep_prob")
        self._output_keep_prob = tf.Variable(output_keep_prob, trainable=False)
        self._state_keep_prob = tf.Variable(state_keep_prob, trainable=False)

        self._output_keep_prob_update = tf.assign(self._output_keep_prob, self._new_output_keep_prob)
        self._state_keep_prob_update = tf.assign(self._state_keep_prob, self._new_state_keep_prob)

        self._batch_size = batch_size
        with tf.name_scope("variational_masks"):
            self._output_mask = tf.Variable(tf.ones(shape=[self._batch_size, hidden_size]), trainable=False)
            self._state_mask = tf.Variable(tf.ones(shape=[self._batch_size, hidden_size]), trainable=False)
            self._mem_mask = tf.Variable(tf.ones(shape=[self._batch_size, hidden_size]), trainable=False)

            with tf.name_scope("out_mask"):

                random_tensor = ops.convert_to_tensor(self._output_keep_prob)
                random_tensor += random_ops.random_uniform([self._batch_size, self._cell.output_size])
                output_mask = math_ops.floor(random_tensor)
                self._assign_output_mask = tf.assign(self._output_mask, output_mask)

            with tf.name_scope("rec_mask"):
                random_tensor = ops.convert_to_tensor(self._state_keep_prob)
                random_tensor += random_ops.random_uniform([self._batch_size, self._cell.output_size])
                state_mask = math_ops.floor(random_tensor)
                self._assign_state_mask = tf.assign(self._state_mask, state_mask)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号