class_docstr: A model for restoring punctuation and capitalization in text. The model is usually used together with ASR model
  because ASR models often return text without punctuation and capitalization.
  
  The model consists of a language model and two multilayer perceptrons (MLP) on top the language model. The first
  MLP serves for punctuation prediction and the second is for capitalization prediction. You can use only BERT-like
  HuggingFace language models (model ``forward`` method accepts ``input_ids``, ``token_types_ids``,
  ``attention_mask`` arguments). See more about model config options :ref:`here<model-config-label>`.
  
  Use method :meth:`~add_punctuation_capitalization` for model inference.
  
  For training and testing use dataset
  :class:`~nemo.collections.nlp.data.token_classification.punctuation_capitalization_dataset.BertPunctuationCapitalizationDataset`,
  for training on huge amounts of data which cannot be loaded into memory simultaneously use
  :class:`~nemo.collections.nlp.data.token_classification.punctuation_capitalization_tarred_dataset.BertPunctuationCapitalizationTarredDataset`.
  
  Args:
      cfg: a model configuration. It should follow dataclass
          :class:`~nemo.collections.nlp.models.token_classification.punctuation_capitalization_config.PunctuationCapitalizationModelConfig`
          See an example of full config in
          `nemo/examples/nlp/token_classification/conf/punctuation_capitalization_config.yaml
          <https://github.com/NVIDIA/NeMo/blob/main/examples/nlp/token_classification/conf/punctuation_capitalization_config.yaml>`_
      trainer: an instance of a PyTorch Lightning trainer
class_docstr_tok: ["A","model","for","restoring","punctuation","and","capitalization","in","text",".","The","model","is","usually","used","together","with","ASR","model","because","ASR","models","often","return","text","without","punctuation","and","capitalization",".","The","model","consists","of","a","language","model","and","two","multilayer","perceptrons","(","MLP",")","on","top","the","language","model",".","The","first","MLP","serves","for","punctuation","prediction","and","the","second","is","for","capitalization","prediction",".","You","can","use","only","BERT-like","HuggingFace","language","models","(","model","``","forward","``","method","accepts","``","input_ids","``",",","``","token_types_ids","``",",","``","attention_mask","``","arguments",")",".","See","more","about","model","config","options",":","ref",":","`","here","<","model-config-label",">","`",".","Use","method",":","meth",":","`","~add_punctuation_capitalization","`","for","model","inference",".","For","training","and","testing","use","dataset",":","class",":","`","~nemo.collections.nlp.data.token_classification.punctuation_capitalization_dataset.BertPunctuationCapitalizationDataset","`",",","for","training","on","huge","amounts","of","data","which","can","not","be","loaded","into","memory","simultaneously","use",":","class",":","`","~nemo.collections.nlp.data.token_classification.punctuation_capitalization_tarred_dataset.BertPunctuationCapitalizationTarredDataset","`",".","Args",":","cfg",":","a","model","configuration",".","It","should","follow","dataclass",":","class",":","`","~nemo.collections.nlp.models.token_classification.punctuation_capitalization_config.PunctuationCapitalizationModelConfig","`","See","an","example","of","full","config","in","`","nemo\/examples\/nlp\/token_classification\/conf\/punctuation_capitalization_config.yaml","<","https",":","\/\/github.com\/NVIDIA\/NeMo\/blob\/main\/examples\/nlp\/token_classification\/conf\/punctuation_capitalization_config.yaml",">","`","_","trainer",":","an","instance","of","a","PyTorch","Lightning","trainer"]
docstr: Setup function for an infer data loader.
  
  Args:
      queries (:obj:`List[str]`): lower cased text without punctuation
      batch_size (:obj:`int`): batch size to use during inference
      max_seq_length (:obj:`int`): length of segments into which queries are split. ``max_seq_length`` includes
          ``[CLS]`` and ``[SEP]`` so every segment contains at most ``max_seq_length-2`` tokens from input a
          query.
      step (:obj:`int`): number of tokens by which a segment is offset to a previous segment. Parameter ``step``
          cannot be greater than ``max_seq_length-2``.
      margin (:obj:`int`): number of tokens near the edge of a segment which label probabilities are not used in
          final prediction computation.
      audio_queries (:obj:`List[str]`, `optional`): paths to audio files.
      target_sr (:obj:`int`, `optional`): target sample rate for audios.
  Returns:
      :obj:`torch.utils.data.DataLoader`: inference data loader
docstr_tok: ["Setup","function","for","an","infer","data","loader",".","Args",":","queries","(",":","obj",":","`","List","[","str","]","`",")",":","lower","cased","text","without","punctuation","batch_size","(",":","obj",":","`","int","`",")",":","batch","size","to","use","during","inference","max_seq_length","(",":","obj",":","`","int","`",")",":","length","of","segments","into","which","queries","are","split",".","``","max_seq_length","``","includes","``","[","CLS","]","``","and","``","[","SEP","]","``","so","every","segment","contains","at","most","``","max_seq_length-2","``","tokens","from","input","a","query",".","step","(",":","obj",":","`","int","`",")",":","number","of","tokens","by","which","a","segment","is","offset","to","a","previous","segment",".","Parameter","``","step","``","can","not","be","greater","than","``","max_seq_length-2","``",".","margin","(",":","obj",":","`","int","`",")",":","number","of","tokens","near","the","edge","of","a","segment","which","label","probabilities","are","not","used","in","final","prediction","computation",".","audio_queries","(",":","obj",":","`","List","[","str","]","`",",","`","optional","`",")",":","paths","to","audio","files",".","target_sr","(",":","obj",":","`","int","`",",","`","optional","`",")",":","target","sample","rate","for","audios",".","Returns",":",":","obj",":","`","torch.utils.data.DataLoader","`",":","inference","data","loader"]
code: def _setup_infer_dataloader(
      self,
      queries: List[str],
      batch_size: int,
      max_seq_length: int,
      step: int,
      margin: int,
      dataloader_kwargs: Optional[Dict[str, Any]],
      audio_queries: Optional[Union[List[bytes], List[str]]] = None,
      target_sr: Optional[int] = None,
  ) -> torch.utils.data.DataLoader:
      """
      Setup function for an infer data loader.
  
      Args:
          queries (:obj:`List[str]`): lower cased text without punctuation
          batch_size (:obj:`int`): batch size to use during inference
          max_seq_length (:obj:`int`): length of segments into which queries are split. ``max_seq_length`` includes
              ``[CLS]`` and ``[SEP]`` so every segment contains at most ``max_seq_length-2`` tokens from input a
              query.
          step (:obj:`int`): number of tokens by which a segment is offset to a previous segment. Parameter ``step``
              cannot be greater than ``max_seq_length-2``.
          margin (:obj:`int`): number of tokens near the edge of a segment which label probabilities are not used in
              final prediction computation.
          audio_queries (:obj:`List[str]`, `optional`): paths to audio files.
          target_sr (:obj:`int`, `optional`): target sample rate for audios.
      Returns:
          :obj:`torch.utils.data.DataLoader`: inference data loader
      """
      if dataloader_kwargs is None:
          dataloader_kwargs = {}
      dataset = BertPunctuationCapitalizationInferDataset(
          tokenizer=self.tokenizer,
          queries=queries,
          max_seq_length=max_seq_length,
          step=step,
          margin=margin,
          audio_queries=audio_queries,
          target_sr=target_sr,
      )
      return torch.utils.data.DataLoader(
          dataset=dataset,
          collate_fn=dataset.collate_fn,
          batch_size=batch_size,
          shuffle=False,
          drop_last=False,
          **dataloader_kwargs,
      )
  
imports: import copy
  import warnings
  from math import ceil
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from omegaconf import DictConfig, OmegaConf
  from pytorch_lightning import Trainer
  from tqdm import tqdm
  from nemo.collections.common.losses import AggregatorLoss, CrossEntropyLoss
  from nemo.collections.common.metrics import GlobalAverageLossMetric
  from nemo.collections.nlp.data.token_classification.punctuation_capitalization_dataset import BertPunctuationCapitalizationDataset, PunctuationCapitalizationEvalDataConfig, PunctuationCapitalizationTrainDataConfig, load_label_ids, raise_not_equal_labels_error
  from nemo.collections.nlp.data.token_classification.punctuation_capitalization_infer_dataset import BertPunctuationCapitalizationInferDataset
  from nemo.collections.nlp.data.token_classification.punctuation_capitalization_tarred_dataset import BertPunctuationCapitalizationTarredDataset
  from nemo.collections.nlp.metrics.classification_report import ClassificationReport
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.collections.nlp.models.token_classification.punctuation_capitalization_config import is_legacy_model_config, legacy_model_config_to_new_model_config
  from nemo.collections.nlp.modules.common import TokenClassifier
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.classes.exportable import Exportable
  from nemo.core.neural_types import LogitsType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 23 for calling the PunctuationCapitalizationModel obj's underlying member method code with example usage: obj._setup_infer_dataloader(queries, batch_size, max_seq_length, step, margin, dataloader_kwargs, audio_queries, target_sr) and returns: torch