flambe.metric.dev.bpc

Module Contents

class flambe.metric.dev.bpc.BPC[source]

Bases: flambe.metric.dev.perplexity.Perplexity

Bits per character. Computed as log_2(perplexity)

Inherits from Perplexity to share aggregate functionality.

compute(self, pred: torch.Tensor, target: torch.Tensor)[source]

Compute the bits per character given the input and target.

Parameters:
  • pred (torch.Tensor) – input logits of shape (B x N)
  • target (torch.LontTensor) – target tensor of shape (B)
Returns:

Output perplexity

Return type:

torch.float

finalize(self, state: Dict)[source]

Finalizes the metric computation

Parameters:state (dict) – the metric state
Returns:The final score.
Return type:float