Open Peetee06 opened 1 year ago
@Peetee06 Thanks for flagging this.
If I understand correctly, your output feature label
only has 1 class? If yes, then this is actually an expected error (that in this case is raised by PyTorch).
At a very high level, it doesn't really make sense to train a machine learning model where the inputs vary but the output feature value is the same. Intuitively, one could just guess the same output value every single time and be right 100% of the time. If that is the case, one wouldn't really need a machine learning model since the "learning" being done is rather trivial. At a slightly more technical level, the reason this doesn't make sense is that your model is always going to learn to predict the same output value with high confidence, leading to the right prediction every time. This will result in virtually no back-prop happening and the weights won't get updated.
A couple of different things I wanted to note:
output_features:
-
name: label
type: category
or
output_features:
-
name: label
type: category
num_classes: 1
Ludwig would have raised a validation error upfront letting you know about the issue and what to do to resolve it. https://github.com/ludwig-ai/ludwig/blob/master/ludwig/features/category_feature.py#L124
weights
assignment, where I believe it's set to 1 instead of 1.0 like you've pointed out. On my end, I can work on making sure that we always cast these values to float to make sure this doesn't happen in the future.Let me know what you think!
Thanks for your answer, @arnavgarg1
I mean to train on 2 classes but accidentally generated training data that contained only 1 class.
I think casting to float will resolve the error.
Additionally it might be useful to check if the training data contains the same amount of classes as specified in the model configuration's output_features. Ludwig could notify the user when there are mismatching number of classes. What do you think?
@Peetee06 Definitely agreed with both of these things!
Are you potentially interested in contributing to Ludwig and making these fixes? Happy to work with you through them!
@arnavgarg1 definitely!
That will be my first contribution to any open source project. How do I go about this? I saw there are guidelines in the docs. Do you have any additional info/tips?
Hi @Peetee06, it's great to hear about your interest to contribute to Ludwig!
We have a contributing guide here: https://github.com/ludwig-ai/ludwig/blob/master/CONTRIBUTING.md
Also, I recommend joining our slack!
Hi @justinxzhao, I read the guide and joined the Slack. Will get familiar with the repo next.
@dalianaliu Re-assigning this to you since you expressed interest! Could be awesome for @Peetee06 and you to work together on fixing this issue in Ludwig :)
@justinxzhao and I are happy to help where needed!
I've been trying to find the source in the code. Currently looking at line 204 in ludwig/modules/loss_modules.py
:
target = target.long()
If I understand that correctly, the target
Tensor gets converted to Long here and then passed on up to here:
File "/home/trost/miniconda3/envs/mlflow-95b8fe275e9987dafa102b0ee13278631dbef1f5/lib/python3.8/site-packages/torch/nn/functional.py", line 3026, in cross_entropy
return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
The error says it expects a floating point type. Why are we converting to long here?
Hey @Peetee06, sorry last week got away from me and I haven't had a chance to look. Work has been pretty busy. I do plan to fix all of these issues possibly over this week!
Are there any updates on this issue?
Describe the bug If the training data contains just one class in a multi-class output feature, pytorch raises a RuntimeException. From the error message I would guess that torch does not expect a class probability of 1, but rather 1.0. I'm not 100% sure if this issue stems from ludwig or is calculated by pytorch.
I used the following config:
To Reproduce Steps to reproduce the behavior:
Expected behavior The training will finish without an Exception. Or exits, saying there is only one class present.