perplexity¶
-
class
Perplexity(name='Perplexity', *args, **kwargs)[source]¶ Bases:
paddle.metric.metrics.MetricPerplexity is calculated using cross entropy. It supports both padding data and no padding data.
If data is not padded, users should provide
seq_lenforMetricinitialization. If data is padded, your label should containseq_mask, which indicates the actual length of samples.This Perplexity requires that the output of your network is prediction, label and sequence length (opitonal). If the Perplexity here doesn’t meet your needs, you could override the
computeorupdatemethod for caculating Perplexity.- Parameters
seq_len (int) – Sequence length of each sample, it must be provided while data is not padded. Default: 20.
name (str) – Name of
Metricinstance. Default: ‘Perplexity’.
-
compute(pred, label, seq_mask=None)[source]¶ This API is advanced usage to accelerate metric calculating, calulations from outputs of model to the states which should be updated by Metric can be defined here, where Paddle OPs is also supported. Outputs of this API will be the inputs of “Metric.update”.
If
computeis defined, it will be called with outputs of model and labels from data as arguments, all outputs and labels will be concatenated and flatten and each filed as a separate argument as follows:compute(output1, output2, ..., label1, label2,...)If
computeis not defined, default behaviour is to pass input to output, so output format will be:return output1, output2, ..., label1, label2,...see
Metric.update