import torch


def mean_crossentropy_loss_alt(weights, targets):
        """
        Evaluates the cross entropy loss
        :param weights: torch Variable,
                (batch_size, num_measures, seq_len, num_notes)
        :param targets: torch Variable,
                (batch_size, num_measures, seq_len)
        :return: float, loss
        """
        criteria = torch.nn.CrossEntropyLoss(reduction='elementwise_mean')
        _, _, _, num_notes = weights.size()
        weights = weights.reshape(-1, num_notes)
        targets = targets.reshape(-1)
        loss = criteria(weights, targets)
        return loss