import torch


def Accuracy(y_hat, y, top_k=(1,)):
    """Compute top-k accuracy
    :arg
        y_hat(tensor): prediction shaped as (B, C)
        y(tensor): label shaped as (B)
        top_k(tuple): how exactly model should predict in each metric

    :return
        list of metric scores
    """
    prediction = torch.argsort(y_hat, dim=-1, descending=True)
    accuracy = [(prediction[:, :min(k, y_hat.size(1))] == y.unsqueeze(-1)).float().sum(dim=-1).mean() * 100 for k in top_k]
    return accuracy