class_docstr: Test individual Metric classes.
class_docstr_tok: ["Test","individual","Metric","classes","."]
code: def test_ppl_metric_from_mask(self) -> None:
      # batchsize=3, num_tokens=10
      token_values = torch.FloatTensor(
          [
              [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9],
              [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
              [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1],
          ]
      )
      token_mask = torch.LongTensor(
          [
              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
              [1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
              [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
          ]
      )
      output = [
          PPLMetric(4.5, 10),
          PPLMetric(0.6, 6),
          PPLMetric(0, 0),
      ]
      actual_output = PPLMetric.from_mask(token_values, token_mask)
  
      self.assertEqual(len(actual_output), len(output))
      # Because Metric.from_mask() calls Metric.many(), which in turn converts tensors to lists,
      # it possible for the actual and expected outputs to be close to each other but not exactly equal.
      for a, o in zip(actual_output, output):
          self.assertIsInstance(a, type(o))
          self.assertAlmostEqual(a.value(), o.value(), places=6)
  
imports: import unittest
  from typing import Dict
  import torch
  import random
  from parlai.core.metrics import AverageMetric, SumMetric, FixedMetric, Metrics, GlobalAverageMetric, MacroAverageMetric, TimerMetric, aggregate_unnamed_reports, aggregate_named_reports, InterDistinctMetric, IntraDistinctMetric, FairseqBleuMetric
  from parlai.core.torch_classifier_agent import ConfusionMatrixMetric, WeightedF1Metric, AUCMetrics
  from parlai.core.torch_generator_agent import PPLMetric
  import parlai.utils.testing
label_desc: Use image node_id 8 for calling the TestMetric obj's underlying member method code with example usage: obj.test_ppl_metric_from_mask() without return types