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

Weighted loss #94

Open
al13n321 opened this issue Oct 26, 2013 · 9 comments
Open

Weighted loss #94

al13n321 opened this issue Oct 26, 2013 · 9 comments

Comments

@al13n321
Copy link

It would be nice to be able to pass node weights for Hamming loss function, i.e. make some labels more important than the others. For example, if we are labeling superpixels of an image instead of pixels, we want to minimize the number of wrong pixels, not superpixels.

@amueller
Copy link
Member

You are right, that would be a nice enhancement. It would be quite easy if we changed the interface of loss to also contain x. Then you could store the weighting factor in x and use that in the loss.

@al13n321
Copy link
Author

Yep, I'm adding x argument to all loss() functions all over the code right now.

@amueller
Copy link
Member

Cool. Do you think it is feasible to do this in a backward-compatible way?
I think I would add it as a last and optional argument for the models, so that they would also work with learners that don't do it. But I don't see an easy way to make the new learners work with models that don't take an x.

@al13n321
Copy link
Author

I don't know how to add weights to all models without going through all the code, so I'll probably only add support for weights to EdgeFeatureGraphCRF (since I'm currently only interested in it). I'm thinking to just check the length of x tuple to decide if the weights are given and the loss should be weighted.

@amueller
Copy link
Member

I would rather create a new model that inherits from EdgeFeatureGraphCRF which always wants weighted nodes. If that is too complicated, I'd at least add a boolean parameter.
If you inherit and create a new model, you only have to write a new loss and overwrite the function that checks x to be in the correct format.

@zaxtax
Copy link
Member

zaxtax commented Oct 26, 2013

+1 for boolean parameter that can be checked if loss is weighted.
On Oct 26, 2013 7:33 PM, "Andreas Mueller" notifications@github.com wrote:

I would rather create a new model that inherits from EdgeFeatureGraphCRFwhich always wants weighted nodes. If that is too complicated, I'd at least
add a boolean parameter.
If you inherit and create a new model, you only have to write a new lossand overwrite the function that checks
x to be in the correct format.


Reply to this email directly or view it on GitHubhttps://github.com//issues/94#issuecomment-27158238
.

@amueller
Copy link
Member

Ideally, this should be implemented in a way that also includes the class_weight option. That is currently hacked in a bit. Maybe the class_weight should be implemented in terms of instance weights?

@al13n321
Copy link
Author

Yeah, class_weight seems redundant when nodes can have weights, but still more convenient. EdgeFeatureGraphCRF could translate class weights to node weights so that lower levels don't have know about class weights.

@amueller
Copy link
Member

exactly :)

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