import torch


def log_softmax(x):
    """
    Computes the log-softmax activation over the last dimension of x.
    Args:
        x: Tensor,
           data to compute the softmax activations for.

    Returns:
        log_x_softmax, Tensor same shape as x.
                       log-softmax activations of x over the last dimension.

    """

    log_denom = torch.logsumexp(x, dim=(len(x.shape) - 1), keepdim=True)
    log_softmax = x - log_denom

    return log_softmax