多实验室文本分类

2024-09-28 01:24:01 发布

您现在位置:Python中文网/ 问答频道 /正文

利用卷积神经网络进行文本分类。我在我的项目中使用了健康文档(ICD-9-CM代码),使用了与dennybritz相同的模型,但是我的数据有36个标签。我用一个热编码来编码我的标签。在

这是我的问题,当我运行的数据对每个文档都有一个标签时,我的代码的准确度在0.8到1之间是完美的。如果我运行的数据有多个标签,那么准确性会大大降低。在

例如:一个文档的单个标签为"782.0"[0 0 1 0 ... 0]
一个文档有多个标签"782.0 V13.09 593.5":[1 0 1 0 ... 1]。在

有人能告诉我为什么会发生这种情况,以及如何改进它吗?在


Tags: 数据项目代码文档模型文本利用编码
1条回答
网友
1楼 · 发布于 2024-09-28 01:24:01

标签编码似乎正确。如果有多个正确的标签,[1 0 1 0 ... 1]看起来很好。Denny的post中使用的损失函数是tf.nn.softmax_cross_entropy_with_logits,这是一个多类问题的损失函数。在

Computes softmax cross entropy between logits and labels.

Measures the probability error in discrete classification tasks in which the classes are mutually exclusive (each entry is in exactly one class).

在多标签问题中,您应该使用tf.nn.sigmoid_cross_entropy_with_logits

Computes sigmoid cross entropy given logits.

Measures the probability error in discrete classification tasks in which each class is independent and not mutually exclusive. For instance, one could perform multilabel classification where a picture can contain both an elephant and a dog at the same time.

loss函数的输入是logits(WX)和目标(labels)。在

修正精度测量值

为了正确测量多标签问题的精度,需要更改以下代码。在

# Calculate Accuracy
with tf.name_scope("accuracy"):
    correct_predictions = tf.equal(self.predictions, tf.argmax(self.input_y, 1))
    self.accuracy = tf.reduce_mean(tf.cast(correct_predictions, "float"), name="accuracy")

当您可以有多个正确的标签时,上面correct_predictions的逻辑是不正确的。例如,假设num_classes=4,标签0和2是正确的。因此,您的input_y=[1, 0, 1, 0].correct_predictions需要打破索引0和索引2之间的联系。我不确定tf.argmax是如何打破平局的,但如果它通过选择较小的索引打破平局,标签2的预测总是被认为是错误的,这肯定会损害您的准确度度量。在

实际上在多标签问题中,precision and recall是比准确度更好的度量。也可以考虑使用精度@k(tf.nn.in_top_k)报告分类器性能。在

相关问题 更多 >

    热门问题