import torch from torchmetrics.text import Perplexity metric = Perplexity() metric.update(torch.rand(2, 8, 5), torch.randint(5, (2, 8))) fig_, ax_ = metric.plot()