class_docstr: Class to manage the selection and use of templates.
docstr: Randomly sample a template from the collection of available templates and apply it to the sample.
  If collection of templates is empty return original sample.
  
  Parameters
  ---------------
  example
      A data sample, i.e. a dictionary of text columns.
  
  Returns
  ------------------
  A tuple consisting of the selected tuple and the sample after the template has been applied to it.
docstr_tok: ["Randomly","sample","a","template","from","the","collection","of","available","templates","and","apply","it","to","the","sample",".","If","collection","of","templates","is","empty","return","original","sample",".","Parameters","--","--","--","--","--","--","--","-","example","A","data","sample",",","i.e",".","a","dictionary","of","text","columns",".","Returns","--","--","--","--","--","--","--","--","--","A","tuple","consisting","of","the","selected","tuple","and","the","sample","after","the","template","has","been","applied","to","it","."]
code: def sample_and_apply_template(self, example: dict):
      """
      Randomly sample a template from the collection of available templates and apply it to the sample.
      If collection of templates is empty return original sample.
  
      Parameters
      ---------------
      example
          A data sample, i.e. a dictionary of text columns.
  
      Returns
      ------------------
      A tuple consisting of the selected tuple and the sample after the template has been applied to it.
      """
      if not self.templates:
          return [None, example]
      template = np.random.choice(self.templates)
      return [
          template,
          template.apply(
              example, truncation_length=self.template_length
          ),
      ]
  
file_path: autogluon/multimodal/src/autogluon/multimodal/data/template_engine.py
imports: import logging
  import numpy
  from omegaconf import OmegaConf
  from autogluon.multimodal.data.templates import DatasetTemplates, Template, TemplateCollection
  from ..constants import AUTOMM
label_desc: Use image node_id 5 for calling the TemplateEngine obj's underlying member method code with example usage: obj.sample_and_apply_template(example) and returns: list, list