import torch


def accuracy(logits: torch.FloatTensor, labels: torch.IntTensor, top_k: int = 5):
    """
    Compute the top-k accuracy.

    Args:
        logits: torch.FloatTensor[seq_len, batch_size, vocab_size]
        labels: torch.IntTensor[seq_len, batch_size]
        top_k: int

    Returns:
        float: the top-k accuracy
    """
    batch_size = logits.shape[1]
    _, indices = logits.topk(top_k, dim=1, largest=True, sorted=True)
    correct = indices.eq(labels.view(-1, 1).expand_as(indices))
    correct_total = correct.view(-1).float().sum()  # 0D tensor
    return correct_total.item() * (100.0 / batch_size)