class_docstr: Construct a LayoutLMv2 tokenizer. Based on WordPiece. [`LayoutLMv2Tokenizer`] can be used to turn words, word-level
  bounding boxes and optional word labels to token-level `input_ids`, `attention_mask`, `token_type_ids`, `bbox`, and
  optional `labels` (for token classification).
  
  This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
  this superclass for more information regarding those methods.
  
  [`LayoutLMv2Tokenizer`] runs end-to-end tokenization: punctuation splitting and wordpiece. It also turns the
  word-level bounding boxes into token-level bounding boxes.
class_docstr_tok: ["Construct","a","LayoutLMv2","tokenizer",".","Based","on","WordPiece",".","[","`","LayoutLMv2Tokenizer","`","]","can","be","used","to","turn","words",",","word-level","bounding","boxes","and","optional","word","labels","to","token-level","`","input_ids","`",",","`","attention_mask","`",",","`","token_type_ids","`",",","`","bbox","`",",","and","optional","`","labels","`","(","for","token","classification",")",".","This","tokenizer","inherits","from","[","`","PreTrainedTokenizer","`","]","which","contains","most","of","the","main","methods",".","Users","should","refer","to","this","superclass","for","more","information","regarding","those","methods",".","[","`","LayoutLMv2Tokenizer","`","]","runs","end-to-end","tokenization",":","punctuation","splitting","and","wordpiece",".","It","also","turns","the","word-level","bounding","boxes","into","token-level","bounding","boxes","."]
docstr: Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
  
  Args:
      encoded_inputs:
          Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
      max_length: maximum length of the returned list and optionally padding length (see below).
          Will truncate by taking into account the special tokens.
      padding_strategy: PaddingStrategy to use for padding.
  
          - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
          - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
          - PaddingStrategy.DO_NOT_PAD: Do not pad
          The tokenizer padding sides are defined in self.padding_side:
  
              - 'left': pads on the left of the sequences
              - 'right': pads on the right of the sequences
      pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
          This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
          >= 7.5 (Volta).
      return_attention_mask:
          (optional) Set to False to avoid returning attention mask (default: set to model specifics)
docstr_tok: ["Pad","encoded","inputs","(","on","left\/right","and","up","to","predefined","length","or","max","length","in","the","batch",")","Args",":","encoded_inputs",":","Dictionary","of","tokenized","inputs","(","`","List","[","int","]","`",")","or","batch","of","tokenized","inputs","(","`","List","[","List","[","int","]","]","`",")",".","max_length",":","maximum","length","of","the","returned","list","and","optionally","padding","length","(","see","below",")",".","Will","truncate","by","taking","into","account","the","special","tokens",".","padding_strategy",":","PaddingStrategy","to","use","for","padding",".","-","PaddingStrategy.LONGEST","Pad","to","the","longest","sequence","in","the","batch","-","PaddingStrategy.MAX_LENGTH",":","Pad","to","the","max","length","(","default",")","-","PaddingStrategy.DO_NOT_PAD",":","Do","not","pad","The","tokenizer","padding","sides","are","defined","in","self.padding_side",":","-","'left","'",":","pads","on","the","left","of","the","sequences","-","'right","'",":","pads","on","the","right","of","the","sequences","pad_to_multiple_of",":","(","optional",")","Integer","if","set","will","pad","the","sequence","to","a","multiple","of","the","provided","value",".","This","is","especially","useful","to","enable","the","use","of","Tensor","Core","on","NVIDIA","hardware","with","compute","capability",">","=","7.5","(","Volta",")",".","return_attention_mask",":","(","optional",")","Set","to","False","to","avoid","returning","attention","mask","(","default",":","set","to","model","specifics",")"]
code: def _pad(
      self,
      encoded_inputs: Union[Dict[str, EncodedInput], BatchEncoding],
      max_length: Optional[int] = None,
      padding_strategy: PaddingStrategy = PaddingStrategy.DO_NOT_PAD,
      pad_to_multiple_of: Optional[int] = None,
      return_attention_mask: Optional[bool] = None,
  ) -> dict:
      """
      Pad encoded inputs (on left/right and up to predefined length or max length in the batch)
  
      Args:
          encoded_inputs:
              Dictionary of tokenized inputs (`List[int]`) or batch of tokenized inputs (`List[List[int]]`).
          max_length: maximum length of the returned list and optionally padding length (see below).
              Will truncate by taking into account the special tokens.
          padding_strategy: PaddingStrategy to use for padding.
  
              - PaddingStrategy.LONGEST Pad to the longest sequence in the batch
              - PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
              - PaddingStrategy.DO_NOT_PAD: Do not pad
              The tokenizer padding sides are defined in self.padding_side:
  
                  - 'left': pads on the left of the sequences
                  - 'right': pads on the right of the sequences
          pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
              This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
              >= 7.5 (Volta).
          return_attention_mask:
              (optional) Set to False to avoid returning attention mask (default: set to model specifics)
      """
      # Load from model defaults
      if return_attention_mask is None:
          return_attention_mask = (
              "attention_mask" in self.model_input_names
          )
  
      required_input = encoded_inputs[self.model_input_names[0]]
  
      if padding_strategy == PaddingStrategy.LONGEST:
          max_length = len(required_input)
  
      if (
          max_length is not None
          and pad_to_multiple_of is not None
          and (max_length % pad_to_multiple_of != 0)
      ):
          max_length = (
              (max_length // pad_to_multiple_of) + 1
          ) * pad_to_multiple_of
  
      needs_to_be_padded = (
          padding_strategy != PaddingStrategy.DO_NOT_PAD
          and len(required_input) != max_length
      )
  
      # Initialize attention mask if not present.
      if (
          return_attention_mask
          and "attention_mask" not in encoded_inputs
      ):
          encoded_inputs["attention_mask"] = [1] * len(required_input)
  
      if needs_to_be_padded:
          difference = max_length - len(required_input)
          if self.padding_side == "right":
              if return_attention_mask:
                  encoded_inputs["attention_mask"] = (
                      encoded_inputs["attention_mask"]
                      + [0] * difference
                  )
              if "token_type_ids" in encoded_inputs:
                  encoded_inputs["token_type_ids"] = (
                      encoded_inputs["token_type_ids"]
                      + [self.pad_token_type_id] * difference
                  )
              if "bbox" in encoded_inputs:
                  encoded_inputs["bbox"] = (
                      encoded_inputs["bbox"]
                      + [self.pad_token_box] * difference
                  )
              if "labels" in encoded_inputs:
                  encoded_inputs["labels"] = (
                      encoded_inputs["labels"]
                      + [self.pad_token_label] * difference
                  )
              if "special_tokens_mask" in encoded_inputs:
                  encoded_inputs["special_tokens_mask"] = (
                      encoded_inputs["special_tokens_mask"]
                      + [1] * difference
                  )
              encoded_inputs[self.model_input_names[0]] = (
                  required_input + [self.pad_token_id] * difference
              )
          elif self.padding_side == "left":
              if return_attention_mask:
                  encoded_inputs["attention_mask"] = [
                      0
                  ] * difference + encoded_inputs["attention_mask"]
              if "token_type_ids" in encoded_inputs:
                  encoded_inputs["token_type_ids"] = [
                      self.pad_token_type_id
                  ] * difference + encoded_inputs["token_type_ids"]
              if "bbox" in encoded_inputs:
                  encoded_inputs["bbox"] = [
                      self.pad_token_box
                  ] * difference + encoded_inputs["bbox"]
              if "labels" in encoded_inputs:
                  encoded_inputs["labels"] = [
                      self.pad_token_label
                  ] * difference + encoded_inputs["labels"]
              if "special_tokens_mask" in encoded_inputs:
                  encoded_inputs["special_tokens_mask"] = [
                      1
                  ] * difference + encoded_inputs["special_tokens_mask"]
              encoded_inputs[self.model_input_names[0]] = [
                  self.pad_token_id
              ] * difference + required_input
          else:
              raise ValueError(
                  "Invalid padding strategy:" + str(self.padding_side)
              )
  
      return encoded_inputs
  
imports: import collections
  import os
  import sys
  import unicodedata
  from typing import Dict, List, Optional, Tuple, Union
  from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
  from ...tokenization_utils_base import BatchEncoding, EncodedInput, PreTokenizedInput, TextInput, TextInputPair, TruncationStrategy
  from ...utils import PaddingStrategy, TensorType, add_end_docstrings, logging
label_desc: Use image node_id 22 for calling the LayoutLMv2Tokenizer obj's underlying member method code with example usage: obj._pad(encoded_inputs, max_length, padding_strategy, pad_to_multiple_of, return_attention_mask) and returns: encoded_inputs