class_docstr: GenerateText class
  
  Examples:
      >>> generatetext = GenerateText(
              lm_train_config="lm_config.yaml",
              lm_file="lm.pth",
              token_type="bpe",
              bpemodel="bpe.model",
          )
      >>> prompt = "I have travelled to many "
      >>> generatetext(prompt)
      [(text, token, token_int, hypothesis object), ...]
class_docstr_tok: ["GenerateText","class","Examples",":",">",">",">","generatetext","=","GenerateText","(","lm_train_config=","''","lm_config.yaml","''",",","lm_file=","''","lm.pth","''",",","token_type=","''","bpe","''",",","bpemodel=","''","bpe.model","''",",",")",">",">",">","prompt","=","``","I","have","travelled","to","many","``",">",">",">","generatetext","(","prompt",")","[","(","text",",","token",",","token_int",",","hypothesis","object",")",",","...","]"]
docstr: Inference
  
  Args:
      text: Input text used as condition for generation
          If text is str, it will be converted to token ids
          and a <sos> token will be added at the beginning.
          If text is Tensor or ndarray, it will be used directly.
  Returns:
      List of (text, token, token_int, hyp)
docstr_tok: ["Inference","Args",":","text",":","Input","text","used","as","condition","for","generation","If","text","is","str",",","it","will","be","converted","to","token","ids","and","a","<","sos",">","token","will","be","added","at","the","beginning",".","If","text","is","Tensor","or","ndarray",",","it","will","be","used","directly",".","Returns",":","List","of","(","text",",","token",",","token_int",",","hyp",")"]
code: def __call__(
      self, text: Optional[Union[str, torch.Tensor, np.ndarray]] = None
  ) -> ListOfHypothesis:
      """Inference
  
      Args:
          text: Input text used as condition for generation
              If text is str, it will be converted to token ids
              and a <sos> token will be added at the beginning.
              If text is Tensor or ndarray, it will be used directly.
      Returns:
          List of (text, token, token_int, hyp)
  
      """
      assert check_argument_types()
  
      if isinstance(text, str):
          tokens = self.tokenizer.text2tokens(text)
          token_ids = self.converter.tokens2ids(tokens)
      elif text is None:
          token_ids = []
      else:
          token_ids = text.tolist()
      hyp_primer = [self.lm.sos] + token_ids
      self.beam_search.set_hyp_primer(hyp_primer)
      logging.info(f"hyp primer: {hyp_primer}")
  
      nbest_hyps = self.beam_search(
          x=torch.zeros(
              1, 1, device=self.device
          ),  # only used to obtain device info
          maxlenratio=-self.maxlen,  # negative int means a constant max length
          minlenratio=-self.minlen,  # same for min length
      )
  
      nbest_hyps = nbest_hyps[: self.nbest]
  
      results = []
      for hyp in nbest_hyps:
          assert isinstance(hyp, Hypothesis), type(hyp)
  
          # remove sos/eos and convert to list
          token_int = hyp.yseq[1:-1]
          if not isinstance(token_int, list):
              token_int = token_int.tolist()
  
          # remove blank symbol id, which is assumed to be 0
          token_int = list(filter(lambda x: x != 0, token_int))
  
          # Change integer-ids to tokens
          token = self.converter.ids2tokens(token_int)
  
          text = None
          if self.tokenizer is not None:
              text = self.tokenizer.tokens2text(token)
          results.append((text, token, token_int, hyp))
  
      assert check_return_type(results)
      return results
  
imports: import argparse
  import logging
  import sys
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.quantization
  from typeguard import check_argument_types, check_return_type
  from espnet2.fileio.datadir_writer import DatadirWriter
  from espnet2.tasks.lm import LMTask
  from espnet2.text.build_tokenizer import build_tokenizer
  from espnet2.text.token_id_converter import TokenIDConverter
  from espnet2.text.whisper_token_id_converter import OpenAIWhisperTokenIDConverter
  from espnet2.torch_utils.device_funcs import to_device
  from espnet2.torch_utils.set_all_random_seed import set_all_random_seed
  from espnet2.utils import config_argparse
  from espnet2.utils.types import str2bool, str2triple_str, str_or_none
  from espnet.nets.batch_beam_search import BatchBeamSearch
  from espnet.nets.beam_search import BeamSearch, Hypothesis
  from espnet.nets.scorer_interface import BatchScorerInterface
  from espnet.nets.scorers.length_bonus import LengthBonus
  from espnet.utils.cli_utils import get_commandline_args
label_desc: Use image node_id 2 for calling the GenerateText obj's underlying member method code with example usage: obj.__call__(text) and returns: results