-
Notifications
You must be signed in to change notification settings - Fork 548
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
[BUG]: NaN outputs for multiclass classification using MCC loss function #306
Comments
I just realized that I only have 1 class represented in my debugging file. If I change
the error no longer occurs, so it must be related to that. But this issue also happened on my full set of 130K molecules that has all 3 classes represented, so it must be more nuanced than that. |
I confirmed that in my full dataset, the train, val, and test splits are identical for the model trained with |
The |
Based on the multiclass definition of MCC from sklearn, it seems that if all of the true values OR predicted values belong to the same class (that number is equal to the total number of samples), then the MCC will be Inf because the denominator will be 0. So if any batch has all predicted values or true values being the same, then MCC will be Inf, which will cause the weights to become NaN through backprop, which will make the predictions be NaN as well. It seems that |
Describe the bug
For a dataset where multiclass classification trains normally with the default
cross_entropy
loss function, it produces an error with themcc
loss function.Example(s)
The script
runs without error while the script
encounters
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
here. The NaN values first appear during the encoding step here. The weights ofself.W_i
start out normally, but turn to NaNs, and I haven't yet been able to trace why that's happening.The contents of
debug.csv
are as follows:The text was updated successfully, but these errors were encountered: