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 エポックを取りました。
しかし、私のモデルでは、毎回 1 つのラベルしか検出されません。私のコードで問題を指摘することはできません。助けてください。

4

1 に答える 1