How to train model from negative samples?

933 views
Skip to first unread message

Lior Magen

unread,
Jul 27, 2016, 3:14:06 AM7/27/16
to Keras-users
I'm working on a multi-class multi-label classifier. The example I'm working with is the Reuters_MLP. In this example it is only multi-class and not multi-label (each document gets a single label). I'm wondering how to train the model from negative sample, meaning - if the classifier classified a tech document as both tech document and sports document (which is a wrong classification) and I want to retrain the model using this document and to teach it that the document is a tech document but not a sports document. 

What will be the best way of doing that?

Iv'e seen many works on multi-class classification but didn't find much about this issue.




Daπid

unread,
Jul 27, 2016, 6:28:41 AM7/27/16
to Lior Magen, Keras-users
I think what you are looking for is "hard negative mining". You can
use it when you have highly unbalanced classes: for example, if you
want to recognise platypuses in images, it is much easier to get
photos of non-platypuses than of platypuses.

In that case, you train on a balanced set, sweep the negative
examples, and add a few of the "most wrong" ones: some of the
non-platypuses that your network is very sure they are platypuses, but
keeping your original training set. Rinse and repeat if needed. This
technique is only useful if you have a very unbalanced set.

If you retrain only on the worse cases, you will improve them, but it
will be at the cost of the good predictions: your network will be
optimised for the special case, but ignoring the common ones.


One thing that may improve your performance is to train a specialist
network using Hinton's dark knowledge:

http://deepdish.io/2014/10/28/hintons-dark-knowledge/


/David.
> --
> You received this message because you are subscribed to the Google Groups
> "Keras-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to keras-users...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/keras-users/d7a8c71b-e52b-4af7-ab7a-ee06dffb4eb5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lior Magen

unread,
Jul 27, 2016, 8:28:50 AM7/27/16
to Keras-users, li...@revuze.it
This method will be relevant if I'm training a single class classifier, right? My problem is that I'm training multi-class multi-label classifier. Let's say I have a document that belongs to two classes: A and B and the classifier classified the document as belong to A only, I'll simply retrain the model and tell it that the document belongs to class B as well. But if the classifier classified the document to class A, class B and class C, how can I train it in a way that it'll learn that the document does not belong to class C?
If it was a sentiment task than I'll simply train positive and negative samples but in this case if I'll add to each class two optional outputs - class A and class ^A (^A means that the sentence does not belong to class A) I'll have twice the number of classes which will damage the classifier accuracy.

Daπid

unread,
Jul 27, 2016, 8:48:30 AM7/27/16
to Lior Magen, Keras-users
On 27 July 2016 at 14:28, Lior Magen <li...@revuze.it> wrote:
> I'll add to each class two optional outputs - class A and class ^A (^A means
> that the sentence does not belong to class A) I'll have twice the number of
> classes which will damage the classifier accuracy.

No need. Your output will be a vector of length 3, probability of A,
probability of B, probability of C. Since they can be multiclass, you
will replace the softmax activation for a sigmoid, and the cost
function can be MSE.

Lior Magen

unread,
Jul 27, 2016, 8:54:01 AM7/27/16
to Keras-users, li...@revuze.it
I don't understand how it will help me when I'll need to train the model with negative samples. 
This is a solution for training with positive samples only, what if the classifier predicts an input to a wrong class? how can I solve this and make sure that it wont happen in the next prediction?

Daπid

unread,
Jul 27, 2016, 9:14:19 AM7/27/16
to Lior Magen, Keras-users
On 27 July 2016 at 14:54, Lior Magen <li...@revuze.it> wrote:
> what if the classifier predicts an input to a wrong class?

If the label is 0 (negative example) and your model says 0.8, the
contribution to the loss function will be high (for MSE, 0.8**2).

You can even train for fully negative examples (they don't belong to any class).

Lior Magen

unread,
Jul 27, 2016, 9:34:58 AM7/27/16
to Keras-users, li...@revuze.it
Sounds good. 
The only thing I don't really understand is this: If my classifier classifies images and I have both a cat and a dog in a given image and my classifier classifies this image just as dog is a really different case than when there is an image of a tiger and the classifier classifies it as cat. Do you get what I'm saying? cats and tigers are more alike than cats and dogs and when I'll train a classifier my training set will contain images of dogs with labels of dogs and images of cats labeled as cats and image of tigers labeled as not-cats because they are really similar to cats. 

Will this method tackle this? 
Reply all
Reply to author
Forward
0 new messages