Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample weights #244

Open
allchemist opened this issue Jul 23, 2018 · 5 comments
Open

Sample weights #244

allchemist opened this issue Jul 23, 2018 · 5 comments

Comments

@allchemist
Copy link

Hello,

is there a designed way to train models with weighted samples? especially to set specific weights to each output in multi-output tasks.

Thanks

@corochann
Copy link
Member

I think you can multiply weight to the loss.
what is your task, regression or classification? what kind of loss function currently you are using?

@allchemist
Copy link
Author

both regression and classification tasks, with use mean_squared_error and sigmoid_cross_entropy loss functions.
Do i need to modify my loss functions for this trick? or i can provide a modified metric in "metrics_fun" argument?

@allchemist
Copy link
Author

I suppose metrics do not participate in backward pass, so i have to modify loss functions

@mottodora
Copy link
Member

mottodora commented Jul 24, 2018

Yes. You need to modify functions to to set specific weights to each output in multi-output tasks.

I'm planning to implement task_weight argument in mean_squared_error and mean_absolute_error. Maybe it is useful for you.
https://github.com/pfnet-research/chainer-chemistry/blob/master/chainer_chemistry/functions/mean_squared_error.py#L14-L15

@allchemist
Copy link
Author

allchemist commented Jul 29, 2018

Weighted loss function is an easy part. Seems like sending only two arguments to loss function is hard-coded inside models/prediction/regressor.py and classifier.py, and also in GraphConvPredictor definition (which is not part of chainer_chemistry though).

    if self.weighted:
        loss_args = self.y, t, args[-1]
    else:
        loss_args = self.y, t
        
    self.loss = self.lossfun(*loss_args)   

This works fine, but i do not fully understand lines 91-109 (regressor.py), so i'm curious if it is right way instead of calling self.loss = self.lossfun(self.y, t)

If we insert weights into dataset like this:

    ds._datasets = ds._datasets[0], ds._datasets[1], ds._datasets[2], sample_weights

then args[-1] above is batch of weights

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants