I voted to close the question because, the way I see it, the lack of actual content accompanying the description of the context and the intended goal makes it quite open-ended. We know that it is a question about Keras, and that the OP built a model with two loss functions (I'll be ignoring the previous revisions, since those had even less detail):
I have a neural net with two loss functions, one is binary cross entropy for the 2 classes, and another is a regression. Now I want the regression loss to be evaluated only for class_2, and return 0 for class_1, because the regressed feature is meaningless for class_1.
Yet, we were given no MCVE to work with. It would have been much better to have some code depicting how the neural network is currently created and trained, even if the code had the issue mentioned afterwards:
Training it separately on only class_1 data doesn't work because I get nan loss.
Without the MCVE, it is not something that we can easily reproduce (no data, no model specifications, no optimizer algorithm, no hyperparameters, ...). The answerer would have to fill in the gaps. And so, the question in its current state looks like a code request for a generic solution to multi-task learning in Keras.
At the time of writing this, there is one reopen vote left to lift the closure. In my opinion, the question should be improved with a proper MCVE before it's reopened. Changing the number of reopen votes necessary not only feels unfair towards close votes, but would also not be healthy to question subdomains with less moderation. In particular, I found the situation in the context of deep learning questions to be alarming enough to raise a meta question many months ago. This is not to be interpreted as some form of spite towards deep learning questions, but a suggestion to make them better (or make them elsewhere if they're off-topic).