class_docstr: Pytorch Hub interface for generating sequences from a pre-trained
  multichannel language model.
class_docstr_tok: ["Pytorch","Hub","interface","for","generating","sequences","from","a","pre-trained","multichannel","language","model","."]
code: def generate(
      self,
      tokenized_sentences: List[Dict[str, torch.LongTensor]],
      beam: int = 5,
      verbose: bool = False,
      skip_invalid_size_inputs=False,
      inference_step_args=None,
      **kwargs,
  ) -> List[List[Dict[str, torch.Tensor]]]:
      if isinstance(tokenized_sentences, dict):
          return self.generate(
              [tokenized_sentences],
              beam=beam,
              verbose=verbose,
              **kwargs,
          )[0]
  
      # build generator using current args as well as any kwargs
      gen_args = copy.deepcopy(self.cfg.generation)
      with open_dict(gen_args):
          gen_args.beam = beam
          for k, v in kwargs.items():
              setattr(gen_args, k, v)
      generator = self.task.build_generator(self.models, gen_args)
  
      inference_step_args = inference_step_args or {}
      results = []
      for batch in tqdm(
          self._build_batches(
              tokenized_sentences, skip_invalid_size_inputs
          )
      ):
          batch = utils.apply_to_sample(
              lambda t: t.to(self.device), batch
          )
          translations = self.task.inference_step(
              generator, self.models, batch, **inference_step_args
          )
          for id, hypos in zip(batch["id"].tolist(), translations):
              # The output of the generator is supposed to be a tensor of size (bsz x max_len x n_channels)
              # So we need to convert it to dictionary form
              for i in range(len(hypos)):
                  hypos[i]["tokens"] = {
                      channel: hypos[i]["tokens"][..., j]
                      for j, channel in enumerate(self.channels)
                  }
              results.append((id, hypos))
  
      # sort output to match input order
      outputs = [
          hypos for _, hypos in sorted(results, key=lambda x: x[0])
      ]
  
      if verbose:
  
          def getarg(name, default):
              return getattr(
                  gen_args, name, getattr(self.cfg, name, default)
              )
  
          for source_tokens, target_hypotheses in zip(
              tokenized_sentences, outputs
          ):
              src_str_with_unk = {
                  channel: self.string(source_tokens[channel], channel)
                  for channel in source_tokens
              }
              logger.info("S\t{}".format(src_str_with_unk))
              for hypo in target_hypotheses:
                  hypo_str = self.decode(hypo["tokens"])
                  logger.info(
                      "H\t{}\t{}".format(hypo["score"], hypo_str)
                  )
                  # hypo["positional_scores"]: T x n_channels
                  pos_scores = {}
                  for c, channel in enumerate(source_tokens):
                      pos_scores[channel] = " ".join(
                          map(
                              lambda x: "{:.4f}".format(x),
                              hypo["positional_scores"][:, c].tolist(),
                          )
                      )
                  logger.info("P\t{}".format(pos_scores))
  
      return outputs
  
file_path: fairseq/fairseq/models/speech_dlm/hub_interface.py
imports: import copy
  import logging
  from typing import Any, Dict, Iterator, List
  import torch
  from fairseq import utils
  from omegaconf import open_dict
  from torch import nn
  from tqdm import tqdm
  from fairseq.hub_utils import GeneratorHubInterface
label_desc: Use image node_id 4 for calling the MultichannelGeneratorHubInterface obj's underlying member method code with example usage: obj.generate(tokenized_sentences, beam, verbose, skip_invalid_size_inputs, inference_step_args) and returns: outputs, self, getattr