Classification loss function: how to implement individual weights for each observation and class
What you are referring to is called a weighted loss function.
In Keras:


Define a dictionary with your labels and their associated weights or just a list of the weights (by class order):

loss_weights = {0: 0.5, 
                 1: 0.2, 
                 2: 1.5}...
Feed the it to the compile method:

model.compile(optimizer=opt,
               loss='categorical_crossentropy',
               metrics='acc',
               loss_weights=loss_weights)


The loss value that will be minimized by the model will then be the weighted sum of all individual losses, weighted by the loss_weights coefficients.