如何使用tensorflow将"yes"或"no"的分类更改为"yes"或"no"的分数?

How to change the classification with "yes" or "no" to the score of "yes" or "no" by using tensorflow?

我是 deep 的新手 learning.I 使用 tensorflow 构建我的 TextCNN 模型(两类)参考这个 tutorial.
该模型可以预测文本的类别。但我想要一个分数([0,1] 中的连续值)而不是离散值。例如,如果模型给出 0.77,则文本更可能属于该类别之一;如果它给出 1.0,则文本实际上是该类别。
这是我的代码的一部分。

def cnn(self):
    # word embedding
    with tf.device('/cpu:0'):
        embedding = tf.get_variable('embedding', [self.config.vocab_size, self.config.embedding_dim])
        embedding_inputs = tf.nn.embedding_lookup(embedding, self.input_x)

    with tf.name_scope("cnn"):
        # CNN layer
        conv = tf.layers.conv1d(embedding_inputs, self.config.num_filters, self.config.kernel_size, name='conv')
        # global max pooling layer
        gmp = tf.reduce_max(conv, reduction_indices=[1], name='gmp')

    with tf.name_scope("score"):
        # full connected layer
        fc = tf.layers.dense(gmp, self.config.hidden_dim, name='fc1')
        fc = tf.contrib.layers.dropout(fc, self.keep_prob)
        fc = tf.nn.relu(fc)

        # classification
        self.logits = tf.layers.dense(fc, self.config.num_classes, name='fc2')
        self.y_pred_cls = tf.argmax(tf.nn.softmax(self.logits), 1)  # 预测类别

    with tf.name_scope("optimize"):
        # Loss function, cross entropy
        cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits=self.logits, labels=self.input_y)
        self.loss = tf.reduce_mean(cross_entropy)
        # optimizer
        self.optim = tf.train.AdamOptimizer(learning_rate=self.config.learning_rate).minimize(self.loss)

    with tf.name_scope("accuracy"):
        # accuracy
        correct_pred = tf.equal(tf.argmax(self.input_y, 1), self.y_pred_cls)
        self.acc = tf.reduce_mean(tf.cast(correct_pred, tf.float32))

提前致谢。

使用tf.nn.softmax(self.logits)获得概率分数。另请参阅此问题: