code: def alpha_balance_loss(labels, loss, alpha_weights):
      
      with tf.variable_scope("alpha_balance"):
          # Broadcast multiply labels with alpha weights to select weights and then reduce them along last axis.
          weights = tf.reduce_sum(labels * alpha_weights, axis=-1)
          return weights * loss
docs: Calculate the alpha balanced cross_entropy.
  
      This means for each sample the cross entropy is calculated and then weighted by the class specific weight.
  
      :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities.
      :param loss: A float tensor of shape [batch_size, ...] representing the loss that should be focused.
      :param alpha_weights: A float tensor of shape [1, ..., num_classes] (... is filled with ones to match number
                                of dimensions to labels tensor) representing the weights for each class.
      :return: A tensor representing the weighted cross entropy.