class_docstr: Methods numberize() and tensorize() implement https://fburl.com/an4fv7m1.
class_docstr_tok: ["Methods","numberize","(",")","and","tensorize","(",")","implement","https",":","\/\/fburl.com\/an4fv7m1","."]
docstr: Works off of a batch that's numerized.
docstr_tok: ["Works","off","of","a","batch","that","'s","numerized","."]
code: def tensorize(self, batch):
      """Works off of a batch that's numerized."""
      all_ctx_tokens_2d = []
      all_ctx_segment_labels_2d = []
      all_ctx_seq_lens_1d = []
      all_ctx_positions_2d = []
      for (
          positive_ctx_token_ids,
          positive_ctx_segment_labels,
          positive_ctx_seq_len,
          positive_ctx_positions,
          negative_ctx_token_ids,
          negative_ctx_segment_labels,
          negative_ctx_seq_len,
          negative_ctx_positions,
      ) in batch:
          # Make sure the positive and hard negative context for a given
          # question are one after another in the batch.
          all_ctx_tokens_2d.append(positive_ctx_token_ids)
          all_ctx_segment_labels_2d.append(positive_ctx_segment_labels)
          all_ctx_seq_lens_1d.append(positive_ctx_seq_len)
          all_ctx_positions_2d.append(positive_ctx_positions)
  
          if negative_ctx_seq_len > 0:
              all_ctx_tokens_2d.append(negative_ctx_token_ids)
              all_ctx_segment_labels_2d.append(
                  negative_ctx_segment_labels
              )
              all_ctx_seq_lens_1d.append(negative_ctx_seq_len)
              all_ctx_positions_2d.append(negative_ctx_positions)
  
      return self.tensorizer_script_impl.tensorize_wrapper(
          all_ctx_tokens_2d,
          all_ctx_segment_labels_2d,
          all_ctx_seq_lens_1d,
          all_ctx_positions_2d,
      )
  
imports: from typing import Any, Dict, List, Optional, Tuple
  from pytext.common.constants import SpecialTokens
  from pytext.config.component import ComponentType, create_component
  from pytext.data.bert_tensorizer import BERTTensorizer, build_fairseq_vocab
  from pytext.data.roberta_tensorizer import RoBERTaTensorizer
  from pytext.data.tensorizers import LabelTensorizer
  from pytext.data.tokenizers import Tokenizer
  from pytext.data.utils import Vocabulary
  from pytext.utils.file_io import PathManager
label_desc: Use image node_id 2 for calling the BERTContextTensorizerForDenseRetrieval obj's underlying member method code with example usage: obj.tensorize(batch) and returns: self