torchmetrics icon indicating copy to clipboard operation
torchmetrics copied to clipboard

Instance Weighting

Open mossaab0 opened this issue 3 years ago • 8 comments

🚀 Feature

Support providing weights for instances (not classes).

Motivation

As is the case with search engines, I have a dataset in which a document (e.g., query) might appear more than once. From a binary relevance stand point (i.e., the classification task), all occurrences of the same document have the same label. To save some memory and computation, instead of having a unique document d repeated N_d times in this dataset, and using those repeated instances to compute the relevant metrics (e.g., F_1 score), it's better to provide the array of weights as a parameter to use it as a multiplier for TP, TN, FP and FN.

Pitch

Add a parameter example_weight.

Alternatives

Repeat the documents N times. But this is not practical when some documents appear several orders of magnitudes compared to others (e.g., head vs tail queries in a search engine).

mossaab0 avatar Jan 20 '22 14:01 mossaab0

Hi! thanks for your contribution!, great first issue!

github-actions[bot] avatar Jan 20 '22 14:01 github-actions[bot]

I am using TweedieDevianceScore as a loss function and was also thinking along these lines. It would be really useful to be able to provide weights for each sample. Would the best way to do this currently to implement my own version of the TweedieDevianceScore as a custom metric?

EvanZ avatar Apr 08 '22 19:04 EvanZ

It would be easy to incorporate weights if the metrics had an option to not reduce to a single scalar number, similar to setting reduction='none' in PyTorch loss functions.

EvanZ avatar Apr 08 '22 19:04 EvanZ

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 12 '22 07:07 stale[bot]

Up (to avoid auto closing).

mossaab0 avatar Jul 12 '22 21:07 mossaab0

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '22 01:09 stale[bot]

Up (to avoid auto closing).

mossaab0 avatar Sep 21 '22 01:09 mossaab0

That would be a nice addition to the package. For reference, I believe this is related to #94

bilelomrani1 avatar Nov 07 '22 14:11 bilelomrani1