class_docstr: Produces BERT inputs and answer spans for Squad.
class_docstr_tok: ["Produces","BERT","inputs","and","answer","spans","for","Squad","."]
code: def numberize(self, row):
      question_column, doc_column = self.columns
      doc_tokens, start_idx, end_idx = self._lookup_tokens(
          row[doc_column], seq_len=self.max_subseq_len
      )
      question_tokens, _, _ = self._lookup_tokens(
          row[question_column], seq_len=self.max_subseq_len
      )
      question_tokens = [self.vocab.get_bos_index()] + question_tokens
      seq_lens = (len(question_tokens), len(doc_tokens))
      segment_labels = (
          [i] * seq_len for i, seq_len in enumerate(seq_lens)
      )
      tokens = list(itertools.chain(question_tokens, doc_tokens))
      segment_labels = list(itertools.chain(*segment_labels))
      offset = len(question_tokens)
  
      # apply max_seq_len to each final seq
      tokens = tokens[: self.max_seq_len]
      segment_labels = segment_labels[: self.max_seq_len]
      if tokens[-1] != self.vocab.get_eos_index():
          # if the doc seq was truncated,
          # update final token to EoS
          tokens[-1] = self.vocab.get_eos_index()
          # adjust the start_idx and end_idx seqs
          spl_start_idx = start_idx[-1]
          spl_end_idx = end_idx[-1]
          start_idx = start_idx[: self.max_seq_len - offset - 1] + (
              spl_start_idx,
          )
          end_idx = end_idx[: self.max_seq_len - offset - 1] + (
              spl_end_idx,
          )
  
      seq_len = len(tokens)
      positions = list(range(seq_len))
  
      # important to make sure labels are always aligned
      assert len(row[self.answers_column]) == len(
          row[self.answer_starts_column]
      ), f"Answer Starts({row[self.answer_starts_column]}) and Answers({row[self.answer_column]}) columns misaligned."
      (
          answer_start_indices,
          answer_end_indices,
      ) = self._calculate_answer_indices(
          row, offset, start_idx, end_idx
      )
      return (
          tokens,
          segment_labels,
          seq_len,
          positions,
          answer_start_indices,
          answer_end_indices,
      )
  
imports: import itertools
  from typing import List
  import torch
  from pytext.data.bert_tensorizer import BERTTensorizer
  from pytext.data.roberta_tensorizer import RoBERTaTensorizer
  from pytext.data.tensorizers import lookup_tokens
  from pytext.data.utils import pad_and_tensorize
  from pytext.torchscript.tensorizer import ScriptRoBERTaTensorizerWithIndices
  from pytext.torchscript.vocab import ScriptVocabulary
label_desc: Use image node_id 5 for calling the SquadForBERTTensorizer obj's underlying member method code with example usage: obj.numberize(row) and returns: tokens,  segment_labels,  seq_len,  positions,  answer_start_indices,  answer_end_indices