src/transformers/models/unispeech/modeling_unispeech.py/UniSpeechGumbelVectorQuantizer/_compute_perplexity
class UniSpeechGumbelVectorQuantizer:    def _compute_perplexity(probs):
        marginal_probs = probs.mean(dim=0)
        perplexity = torch.exp(-torch.sum(marginal_probs * torch.log(marginal_probs + 1e-7), dim=-1)).sum()
        return perplexity