import torch


def compute_metrics(ranking: torch.Tensor):
    """
    :param ranking: tensor of b x 1 with ranking of each evaluation triple. 1 is the highest rank.
    :return: dict with keys: ["MRR", "MR", "HR@1", "HR@3", "HR@10"], and float values
    """
    metrics = {"MR": ranking.mean().item(), "MRR": (1. / ranking).mean().item()}
    for k in (1, 3, 10):
        metrics[f'HR@{k}'] = (ranking <= k).float().mean().item()
    return metrics