How does exactly class_weight in Keras work?
A weighted classification layer computes the weighted cross entropy loss for classification problems. Weighted cross entropy is an error measure between two continuous random variables. For prediction scores Y and training targets T, the weighted cross entropy loss between Y and T is given by

$$ F = -\frac{1}{N}\sum_{i=1}^{N}\sum_{k=1}^{M} w_i \cdot T_{ni} \cdot log(p_{ij}))$$

where $N$ is the number of instances, K is the number of classes, and w is a vector of weights for each class.

The cost function per label is measuring how good our classifier is doing per label, but it is affected by the number of instances $N$ that don't contain this label.