我尝试在张量流上进行多标签分类,但性能不佳。
输入:[1,0,1,...,0](单热)和文字内容
with tf.name_scope("rnn"):
cells = [dropout() for _ in range(self.config.num_layers)]
rnn_cell = tf.contrib.rnn.MultiRNNCell(cells, state_is_tuple=True)
_outputs, _ = tf.nn.dynamic_rnn(cell=rnn_cell, inputs=embedding_inputs, dtype=tf.float32)
last = _outputs[:, -1, :]
模型: 嵌入层
with tf.name_scope("score"):
fc = tf.layers.dense(last, self.config.hidden_dim, name='fc1')
fc = tf.contrib.layers.dropout(fc, self.keep_prob)
fc = tf.nn.relu(fc)
self.logits = tf.layers.dense(fc, self.config.num_classes, name='fc2')
self.y_pred_cls = tf.nn.sigmoid(self.logits, name='pred')
双LSTM
with tf.name_scope("optimize"):
cross_entropy = tf.nn.sigmoid_cross_entropy_with_logits(logits=self.logits, labels=self.input_y)
self.loss = tf.reduce_mean(cross_entropy)
self.optim = tf.train.AdamOptimizer(learning_rate=self.config.learning_rate).minimize(self.loss)
通过relu
激活 with tf.name_scope("accuracy"):
threashold=0.5
self.labels = tf.equal(self.input_y, 1)
self.preds = tf.greater_equal(self.y_pred_cls,threashold)
self.correct_num = tf.divide(tf.size(tf.where(tf.logical_not(tf.logical_xor(self.labels, self.preds)))),2)
self.total_num = tf.size(self.input_y)
self.correct_pred = tf.divide(tf.cast(self.correct_num, tf.float32),tf.cast(self.total_num, tf.float32))
self.acc = tf.reduce_mean(tf.cast(self.correct_pred, tf.float32))
使用sigmoid cross entropy
$a = 'I need the 11 Stagione';
if ( preg_match( "/\b(Season|Stagione|S|T)\s*\d+|\d+\s*(?1)\b/i", $a, $matches ) )
{
print_r( $matches[0] );
}
计算acc
\b
模型预测[0,0,.... 0](全为零)对测试数据, 不属于任何类别。
我的代码或模型设计出了什么问题?谢谢。