class_docstr: This is the automatic template search implementation for `LM-BFF <https://arxiv.org/pdf/2012.15723.pdf>`_. It uses a generation model to generate multi-part text to fill in the template. By jointly considering all samples in the dataset, it uses beam search decoding method to generate a designated number of templates with the highest probability. The generated template may be uniformly used for all samples in the dataset.
  
  Args:
      model (:obj:`PretrainedModel`): A pretrained model for generation.
      tokenizer (:obj:`PretrainedTokenizer`): A corresponding type tokenizer.
      tokenizer_wrapper (:obj:`TokenizerWrapper`): A corresponding type tokenizer wrapper class.
      max_length (:obj:`Optional[int]`): The maximum length of total generated template. Defaults to 20.
      target_number (:obj:`Optional[int]`): The number of separate parts to generate, e.g. in T5, every <extra_id_{}> token stands for one part. Defaults to 2.
      beam_width (:obj:`Optional[int]`): The beam search width.  Defaults to 100.
      length_limit (:obj:`Optional[List[int]]`): The length limit for each part of content, if None, there is no limit. If not None, the list should have a length equal to `target_number`. Defaults to None.
      forbidden_word_ids (:obj:`Optional[List[int]]`): Any tokenizer-specific token_id you want to prevent from generating. Defaults to `[]`, i.e. all tokens in the vocabulary are allowed in the generated template.
class_docstr_tok: ["This","is","the","automatic","template","search","implementation","for","`","LM-BFF","<","https",":","\/\/arxiv.org\/pdf\/2012.15723.pdf",">","`","_",".","It","uses","a","generation","model","to","generate","multi-part","text","to","fill","in","the","template",".","By","jointly","considering","all","samples","in","the","dataset",",","it","uses","beam","search","decoding","method","to","generate","a","designated","number","of","templates","with","the","highest","probability",".","The","generated","template","may","be","uniformly","used","for","all","samples","in","the","dataset",".","Args",":","model","(",":","obj",":","`","PretrainedModel","`",")",":","A","pretrained","model","for","generation",".","tokenizer","(",":","obj",":","`","PretrainedTokenizer","`",")",":","A","corresponding","type","tokenizer",".","tokenizer_wrapper","(",":","obj",":","`","TokenizerWrapper","`",")",":","A","corresponding","type","tokenizer","wrapper","class",".","max_length","(",":","obj",":","`","Optional","[","int","]","`",")",":","The","maximum","length","of","total","generated","template",".","Defaults","to","20.","target_number","(",":","obj",":","`","Optional","[","int","]","`",")",":","The","number","of","separate","parts","to","generate",",","e.g",".","in","T5",",","every","<","extra_id_","{","}",">","token","stands","for","one","part",".","Defaults","to","2.","beam_width","(",":","obj",":","`","Optional","[","int","]","`",")",":","The","beam","search","width",".","Defaults","to","100.","length_limit","(",":","obj",":","`","Optional","[","List","[","int","]","]","`",")",":","The","length","limit","for","each","part","of","content",",","if","None",",","there","is","no","limit",".","If","not","None",",","the","list","should","have","a","length","equal","to","`","target_number","`",".","Defaults","to","None",".","forbidden_word_ids","(",":","obj",":","`","Optional","[","List","[","int","]","]","`",")",":","Any","tokenizer-specific","token_id","you","want","to","prevent","from","generating",".","Defaults","to","`","[","]","`",",","i.e",".","all","tokens","in","the","vocabulary","are","allowed","in","the","generated","template","."]
docstr: Args:
      dataset (:obj:`List[InputExample]`): The dataset based on which template it to be generated.
  Returns:
      template_text (:obj:`List[str]`): The generated template text
docstr_tok: ["Args",":","dataset","(",":","obj",":","`","List","[","InputExample","]","`",")",":","The","dataset","based","on","which","template","it","to","be","generated",".","Returns",":","template_text","(",":","obj",":","`","List","[","str","]","`",")",":","The","generated","template","text"]
code: def generate(self, dataset: List[InputExample]):
      r"""
      Args:
          dataset (:obj:`List[InputExample]`): The dataset based on which template it to be generated.
      Returns:
          template_text (:obj:`List[str]`): The generated template text
      """
      template_for_auto_t = LMBFFTemplateGenerationTemplate.from_config(
          config=self.config.template,
          tokenizer=self.tokenizer,
          verbalizer=self.verbalizer,
      )
  
      dataloader = PromptDataLoader(
          dataset,
          template_for_auto_t,
          tokenizer=self.tokenizer,
          tokenizer_wrapper_class=self.tokenizer_wrapper,
          batch_size=len(dataset),
          decoder_max_length=128,
      )  # register all data at once
      for data in dataloader:
          data = data.to(self.device)
          self._register_buffer(data)
  
      self.model.eval()
      with torch.no_grad():
          self.templates_text = self._get_templates()  # List[str]
          original_template = template_for_auto_t.text
          self.templates_text = [
              self.convert_template(template_text, original_template)
              for template_text in self.templates_text
          ]
          self._show_template()
      return self.templates_text
  
imports: from abc import abstractmethod
  from builtins import ValueError
  from typing import List, Optional, Dict, Union
  from tokenizers import Tokenizer
  import json
  import torch
  import torch.nn.functional
  from yacs.config import CfgNode
  from openprompt.data_utils.utils import InputExample, InputFeatures
  from openprompt.pipeline_base import PromptDataLoader, PromptModel
  from openprompt.prompt_base import Template, Verbalizer
  from openprompt.prompts import ManualTemplate, ManualVerbalizer
  from ..utils import logger
  from transformers import T5Tokenizer, T5ForConditionalGeneration, BertForMaskedLM, RobertaForMaskedLM, RobertaTokenizer, PreTrainedModel, PreTrainedTokenizer
  from tqdm import tqdm
  from typing import List, Optional, Dict
  import itertools
  import numpy
  from ..utils import signature
  from ..config import convert_cfg_to_dict
  from torch.nn.parallel import DataParallel
label_desc: Use image node_id 10 for calling the TemplateGenerator obj's underlying member method code with example usage: obj.generate(dataset) and returns: self