docstr: Convert instance level vectors into batch level tensors.
code: def tensorize(
      self,
      tokens_2d: List[List[int]],
      segment_labels_2d: List[List[int]],
      seq_lens_1d: List[int],
      positions_2d: List[List[int]],
  ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]:
      """
      Convert instance level vectors into batch level tensors.
      """
      tokens, pad_mask = pad_2d_mask(
          tokens_2d,
          pad_value=self.vocab.pad_idx,
          seq_padding_control=self.seq_padding_control,
          max_seq_pad_len=self.max_seq_len,
          batch_padding_control=self.batch_padding_control,
      )
      segment_labels = torch.tensor(
          pad_2d(
              segment_labels_2d,
              seq_lens=seq_lens_1d,
              pad_idx=0,
              max_len=self.max_seq_len,
          ),
          dtype=torch.long,
      )
      positions = torch.tensor(
          pad_2d(
              positions_2d,
              seq_lens=seq_lens_1d,
              pad_idx=0,
              max_len=self.max_seq_len,
          ),
          dtype=torch.long,
      )
      if self.device == "":
          return tokens, pad_mask, segment_labels, positions
      else:
          return (
              tokens.to(self.device),
              pad_mask.to(self.device),
              segment_labels.to(self.device),
              positions.to(self.device),
          )
  
imports: from typing import Any, Dict, List, Optional, Tuple
  import torch
  from fairseq.data.dictionary import Dictionary
  from fairseq.data.legacy.masked_lm_dictionary import BertDictionary
  from pytext import resources
  from pytext.common.constants import Token
  from pytext.config.component import ComponentType, create_component
  from pytext.data.tensorizers import Tensorizer, TensorizerScriptImpl
  from pytext.data.tokenizers import Tokenizer, WordPieceTokenizer
  from pytext.data.utils import BOS, EOS, MASK, PAD, UNK, Vocabulary
  from pytext.torchscript.tensorizer.tensorizer import VocabLookup
  from pytext.torchscript.utils import pad_2d_mask, ScriptBatchInput
  from pytext.torchscript.vocab import ScriptVocabulary
  from pytext.utils.file_io import PathManager
  from pytext.utils.lazy import lazy_property
  from pytorch.text.fb.utils.transform_utils import pad_2d
label_desc: Use image node_id 5 for calling the BERTTensorizerBaseScriptImpl obj's underlying member method code with example usage: obj.tensorize(tokens_2d, segment_labels_2d, seq_lens_1d, positions_2d) and returns: tokens,  pad_mask,  segment_labels,  positions, tokens,  pad_mask,  segment_labels,  positions