Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

运行内存CPU被撑爆 #2

Open
qujinqiang opened this issue Jan 5, 2018 · 2 comments
Open

运行内存CPU被撑爆 #2

qujinqiang opened this issue Jan 5, 2018 · 2 comments

Comments

@qujinqiang
Copy link

我在 bilstm层上加crf 报一下问题:
/data/software/anaconda2/envs/py3_tf4/lib/python3.5/site-packages/tensorflow/python/ops/gradients_impl.py:96: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

训练代码大概如下所示:
def trainModel(self):
with tf.variable_scope('Inputs'):
self.X_inputs = tf.placeholder(tf.int32, [None, self.timestep_size], name='X_input') # 输入
self.y_inputs = tf.placeholder(tf.int32, [None, self.timestep_size], name='y_input') # 对应的标记

    bilstm_output = self.bi_lstm(self.X_inputs) # 返回的是隐藏层状态的输出

    with tf.variable_scope('outputs'):
        softmax_w = self.weight_variable([self.hidden_size * 2, self.class_num])
        softmax_b = self.bias_variable([self.class_num])
        self.y_pred = tf.matmul(bilstm_output, softmax_w) + softmax_b  # 隐藏层状态加上softmax才是实际的y预测值
        print(self.y_pred.shape)
        self.scores = tf.reshape(self.y_pred, [-1, self.timestep_size,
                                          self.class_num])  # 算好分数后,再重新reshape成[batchsize, timesteps, num_class]
        print(self.scores.shape)

    log_likelihood, self.transition_params = crf.crf_log_likelihood(self.scores, self.y_inputs, self.length)
    self.loss = tf.reduce_mean(-log_likelihood)

    optimizer = tf.train.AdamOptimizer(learning_rate=self.lr)
    self.train_op = optimizer.minimize(self.loss)
@Slyne
Copy link
Owner

Slyne commented Jan 9, 2018

Hi 不确定你的bilistm_output的输出shape是怎么样子的
另外crf的参数如下:
tf.contrib.crf.crf_log_likelihood
crf_log_likelihood(
inputs,
tag_indices,
sequence_lengths,
transition_params=None
)
inputs: A [batch_size, max_seq_len, num_tags] tensor of unary potentials to use as input to the CRF layer.
tag_indices: A [batch_size, max_seq_len] matrix of tag indices for which we compute the log-likelihood.
sequence_lengths: A [batch_size] vector of true sequence lengths.
transition_params: A [num_tags, num_tags] transition matrix, if available.

@qujinqiang
Copy link
Author

@Slyne
代码上基本没有变化,但是可以跑模型了;基于2014的人民日报语料训练出来准确率大概92%左右
不过bi_lstm 加上 crf 层后依然存在着 "Converting sparse IndexedSlices to a dense Tensor of unknown shape. " 这种警告;
你那边训练的时候会存在相关警告吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants