利用卷积神经网络进行文本分类。我在我的项目中使用了健康文档(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]
。在
有人能告诉我为什么会发生这种情况,以及如何改进它吗?在
标签编码似乎正确。如果有多个正确的标签,
[1 0 1 0 ... 1]
看起来很好。Denny的post中使用的损失函数是tf.nn.softmax_cross_entropy_with_logits
,这是一个多类问题的损失函数。在在多标签问题中,您应该使用
tf.nn.sigmoid_cross_entropy_with_logits
:loss函数的输入是logits(
WX
)和目标(labels)。在修正精度测量值
为了正确测量多标签问题的精度,需要更改以下代码。在
当您可以有多个正确的标签时,上面
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
)报告分类器性能。在相关问题 更多 >
编程相关推荐