code: def test_type_validate_gentext_output(self):
      ds_spec = {
          "num": types.Scalar(),
          "text": types.TextSegment(),
      }
      out_spec = {
          "gentext": types.GeneratedText(parent="text"),
          "cands": types.GeneratedTextCandidates(parent="text"),
      }
      example = {"num": 1, "text": "hi"}
      output = {"gentext": "test", "cands": [("hi", 4), ("bye", None)]}
  
      gentext = types.GeneratedText(parent="text")
      gentextcands = types.GeneratedTextCandidates(parent="text")
      try:
          gentext.validate_output(
              "hi", out_spec, output, ds_spec, ds_spec, example
          )
          gentextcands.validate_output(
              [("hi", 4), ("bye", None)],
              out_spec,
              output,
              ds_spec,
              ds_spec,
              example,
          )
      except ValueError:
          self.fail("Raised unexpected error.")
  
      bad_gentext = types.GeneratedText(parent="num")
      self.assertRaises(
          ValueError,
          bad_gentext.validate_output,
          "hi",
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
  
      self.assertRaises(
          ValueError,
          gentextcands.validate_output,
          [("hi", "wrong"), ("bye", None)],
          out_spec,
          output,
          ds_spec,
          ds_spec,
          example,
      )
      bad_gentextcands = types.GeneratedTextCandidates(parent="num")
      self.assertRaises(
          ValueError,
          bad_gentextcands.validate_output,
          [("hi", 4), ("bye", None)],
          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 11 for calling the TypesTest obj's underlying member method code with example usage: obj.test_type_validate_gentext_output() without return types