0

我对 NER 的序列标记不太感兴趣。我按照代码“ https://github.com/monikkinom/ner-lstm/blob/master/model.py ”制作我的模型,如下所示:

X = tf.placeholder(tf.float32, shape=[None, timesteps , num_input])
Y = tf.placeholder("float", [None, timesteps, num_classes])
y_true = tf.reshape(tf.stack(Y), [-1, num_classes])

输入是
X: (batch_size,max_sent_length,word_embed_dim)

Y: (batch_size,max_sent_length,number_of_labels)

然后我将值传递给双向 LSTM 单元:

def BiRNN(x):
    x=tf.unstack(tf.transpose(x, perm=[1, 0, 2]))

    def rnn_cell():
        cell = tf.nn.rnn_cell.LSTMCell(rnn_size, forget_bias=1,state_is_tuple=True)
        return cell

    fw_cell=rnn_cell()
    bw_cell=rnn_cell()
    output,_, _ = tf.nn.static_bidirectional_rnn(fw_cell, bw_cell,x, dtype=tf.float32)
    weight, bias = weight_and_bias(2 * rnn_size, num_classes)
    output = tf.reshape(tf.transpose(tf.stack(output), perm=[1, 0, 2]), [-1, 2 * rnn_size])
return (tf.matmul(output, weight) + bias)

其中,rnn_size = 128

然后我进行以下计算:

logits = BiRNN(X)
logits = tf.reshape(tf.stack(logits), [-1, timesteps,num_classes])
prediction = tf.reshape(logits, [-1, num_classes])
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=prediction, labels=y_true))
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.001)
train_op = optimizer.minimize(cost)

我拿了,batch_size = 64 和 30 个 epoch。
但在我的模型中,每次只检测到一个标签。我无法在我的代码中指出问题。请帮忙。

4

1 回答 1

0

请检查张量 y_true、输出(两个地方)、logits 和预测的维度,并检查它是否符合您的期望。

于 2018-04-23T12:29:07.653 回答