Sinyoung
Sinyoung

Reputation: 43

Multi-Label Multi-Class Classifier in Tensorflow

I want to make a multi-label multi-class classifier with TensorFlow. For example,

Data has multi label

I want to classify these labels with neural network. Can I use below code as cost?

loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(data1 prediction, data1 label))

Upvotes: 2

Views: 1597

Answers (1)

rvinas
rvinas

Reputation: 11895

No, you can't use the code you provide for the loss function, because tf.nn.softmax_cross_entropy_with_logits requires a valid probability distribution for the labels argument.

If each example can belong to multiple classes (i.e. classes are independent and not mutually exclusive), tf.nn.sigmoid_cross_entropy_with_logits is the recommended choice.


UPDATE: Answer to your comment

When I talk about a valid probability distribution I mean that the elements of each "label array" must sum 1, and all elements need to be non-negative. For example, data1 label is not a valid probability distribution because the sum of its elements is 2.

Your problem is clearly binary classification, because classes are not mutually exclusive and you want to produce independent probabilities for each class (i.e. probability of belonging to that class).

Upvotes: 2

Related Questions