code: def test_tokentopk(self):
      ds_spec = {
          "text": types.TextSegment(),
      }
      out_spec = {
          "tokens": types.Tokens(),
          "preds": types.TokenTopKPreds(align="tokens"),
      }
      example = {"text": "hi"}
      output = {
          "tokens": ["hi"],
          "preds": [[("one", 0.9), ("two", 0.4)]],
      }
  
      preds = types.TokenTopKPreds(align="tokens")
      try:
          preds.validate_output(
              [[("one", 0.9), ("two", 0.4)]],
              out_spec,
              output,
              ds_spec,
              ds_spec,
              example,
          )
      except ValueError:
          self.fail("Raised unexpected error.")
  
      self.assertRaises(
          ValueError,
          preds.validate_output,
          [[("one", 0.2), ("two", 0.4)]],
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
      self.assertRaises(
          ValueError,
          preds.validate_output,
          [["one", "two"]],
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
      self.assertRaises(
          ValueError,
          preds.validate_output,
          ["wrong"],
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
  
      bad_preds = types.TokenTopKPreds(align="preds")
      self.assertRaises(
          ValueError,
          bad_preds.validate_output,
          [[("one", 0.9), ("two", 0.4)]],
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
  
imports: from collections.abc import Callable
  import os
  from typing import Any, Optional, Union
  from absl.testing import absltest
  from absl.testing import parameterized
  from etils import epath
  from lit_nlp.api import dtypes
  from lit_nlp.api import types
  import numpy
label_desc: Use image node_id 13 for calling the TypesTest obj's underlying member method code with example usage: obj.test_tokentopk() without return types