一. 背景
继续做”字嵌入+LSTM+CRF“,一如既往地, 继续遇到问题。
二. 代码
batch_size = 1000
class Model:
def __init__(self, inputs, labels):
....(此为省略代码的标志)
# get the batch_size
self.batch_size = batch_size
with tf.Graph().as_default() as g:
X = tf.placeholder('float', [batch_size, max_seq_len, 128])
Y = tf.placeholder('float', [batch_size, max_seq_len])
model = Model(inputs=X, labels=Y)
initer = tf.global_variables_initializer()
....
loss, accuracy, size, _ = sess.run([model.loss, model.accuracy, model.batch_size, model.optimizer], feed_dict={X: vectors, Y: labels})
....
三. 问题
四. 解决方案
后来发现原来是因为不可以向图中变量传入非(string or tensor)的值,解决方法是就是不传入值
删除掉batch_size的调用即可。
batch_size = 1000
class Model:
def __init__(self, inputs, labels):
....(此为省略代码的标志)
with tf.Graph().as_default() as g:
X = tf.placeholder('float', [batch_size, max_seq_len, 128])
Y = tf.placeholder('float', [batch_size, max_seq_len])
model = Model(inputs=X, labels=Y)
initer = tf.global_variables_initializer()
....
loss, accuracy, _ = sess.run([model.loss, model.accuracy, model.optimizer], feed_dict={X: vectors, Y: labels})
....