Skip to content

Conversation

@hzavadil98
Copy link
Contributor

In addition to #52 where now logits are passed directly to metrics, I added, as proposed, the micro/macro averaging option to be passed to each metric (except of entropy where I believe it doesn't make sense, right? @Seilmast ). Here is a pretty thorough description of the issue Micro/Macro. This resolves #30 for Johan. Please push your adjusted metrics directly to this Draft PR before we merge them.

@sot176
Copy link
Contributor

sot176 commented Feb 10, 2025

I pushed my adjusted metric now to this draft PR :)

@Seilmast
Copy link
Collaborator

Micro/Macro averages doesn't make sense for Shannon Entropy @hzavadil98. I have added in some averaging functionality for batchwise mean or sum of entropy. As long as the option is passed as a argument then it shouldn't make any difference.

@hzavadil98 hzavadil98 removed the request for review from sot176 February 10, 2025 15:14
@c-salomonsen
Copy link
Contributor

c-salomonsen commented Feb 11, 2025

Yep, I'm working on mine sporadically. Will push in not too long.

Could anyone clarify to me: the input to the metric, what shapes are y_pred and y_true? Cuz if y_pred are logits sent in, I suppose they are one-hot encoded, but is y_true also that?

@Johanmkr
Copy link
Contributor

Yep, I'm working on mine sporadically. Will push in not too long.

Could anyone clarify to me: the input to the metric, what shapes are y_pred and y_true? Cuz if y_pred are logits sent in, I suppose they are one-hot encoded, but is y_true also that?

I do the one-hot-encoding within the metric, but we should maybe decide on this.

@Seilmast
Copy link
Collaborator

Logits are not one-hot encoded. The shape you should expect is N x C where N is the batchsize and C is the number of classes.
y_true is probably just a Nx1 vector, with each row being the numerical label of the sample. That can be converted to a one-hot matrix should you need to do so.

@Johanmkr Johanmkr mentioned this pull request Feb 11, 2025
@c-salomonsen
Copy link
Contributor

c-salomonsen commented Feb 11, 2025

Logits are not one-hot encoded. The shape you should expect is N x C where N is the batchsize and C is the number of classes.

Thats what one-hot encoding is.

y_true is probably just a Nx1 vector, with each row being the numerical label of the sample. That can be converted to a one-hot matrix should you need to do so.

Okay, good. I've noticed that this ambiguity w.r.t the shape of y_true and y_pred means that some of us expect different input shapes. Thus, I guess we should specify if the sizes you are describing is what we want to use, or if both y_pred and y_true should already have shape ($N \times C$) when sent to the MetricWrapper?

@Seilmast
Copy link
Collaborator

Maybe we're not refering to the same thing.
A one-hot encoded vector is a spare vector with a single value on the index representing the class.
Logits are not sparse and represents the networks map of the input onto some probability space (-inf to inf before softmax).
The logits should be the pure output of the network. It's the same as you would input into the CrossEntropyLoss function for example.

Yeah, we should specify the sized. I think working with the logits and labels in the form NxC and Nx1 is easier as

  1. You usually have the labels on that form when doing training / interferance
  2. You don't have to touch the logits after the network returns them

It allows us to send the input sample through the network, and just use the raw output on the metric instance.

@c-salomonsen
Copy link
Contributor

I see, was mixing with the softmax output.

I think we could go for that 👍🏻

This will hopefully simplify the arguments to each metric slightly.
Note that the precision metric needs a rewording as we use the argument
macro_averaging = True/False as input but that one has the argument
micro_averaging.
@c-salomonsen
Copy link
Contributor

c-salomonsen commented Feb 11, 2025

I just pushed my updated metric + tests to this PR. Note that the test will purposefully fail until the Precision metric is updated (see this commit message @Johanmkr)

The tests will likely need to be changed a bit to accomodate the differing input arguments to @Seilmast's entropy metric, but this works for now 😉 See here for test on metricwrapper.

@Johanmkr
Copy link
Contributor

I just pushed my updated metric + tests to this PR. Note that the test will purposefully fail until the Precision metric is updated (see this commit message @Johanmkr)

The tests will likely need to be changed a bit to accomodate the differing input arguments to @Seilmast's entropy metric, but this works for now 😉 See here for test on metricwrapper.

I am resolving this now, but I am still confused about the shapes. So the logits will have shape NxC, but should we enforce y_true to have shape Nx1 rather than just N, which it seems to have in the metric wrapper test @salomaestro?

I will try to fix my code in the breaks of the ethics course today.

@c-salomonsen
Copy link
Contributor

c-salomonsen commented Feb 12, 2025

@Johanmkr as long as your inputs and outputs follow the agreed upon shape you may modify the vectors to your liking. For instance, if you want to use y_true with a shape of N, you could squeeze the dimensions using: y_true.squeeze(), which will do that for you 😉 Maybe we agree upon this shape in our meeting tomorrow?

@Johanmkr
Copy link
Contributor

@Johanmkr as long as your inputs and outputs follow the agreed upon shape you may modify the vectors to your liking. For instance, if you want to use y_true with a shape of N, you could squeeze the dimensions using: y_true.squeeze(), which will do that for you 😉 Maybe we agree upon this shape in our meeting tomorrow?

Yes we can discuss during today's meeting, because it seems to me that the shape we all use for y_true in the tests is in fact (N) and not (N,1), but let's have a look later today :)

@Johanmkr
Copy link
Contributor

Screenshot_20250213_104230_LinkedIn.jpg

@c-salomonsen
Copy link
Contributor

@Johanmkr git push origin main --force 😆

@hzavadil98 hzavadil98 marked this pull request as ready for review February 13, 2025 11:21
@hzavadil98 hzavadil98 merged commit 77b5002 into main Feb 13, 2025
4 checks passed
@hzavadil98 hzavadil98 deleted the Jan-metrics branch February 13, 2025 12:15
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

Successfully merging this pull request may close these issues.

Counting positives/negatves when calculating metrics

6 participants