class_docstr: The basic pretrained model for QA. It is used in the original BERT paper for SQuAD 1.1.
  
  Here, we directly use the backbone network to extract the contextual embeddings and use
  another dense layer to map the contextual embeddings to the start scores and end scores.
  
  use_segmentation is used to mark whether we segment the input sentence. In RoBERTa and XLMR,
  this flag is set to True, then the QA model no longer accept `token_types` as valid input.
  
  - use_segmentation=True:
      tokens :      <CLS> Question <SEP> Context <SEP>
      token_typess:  0       0       0      1      1
  
  - use_segmentation=False:
      tokens :      <CLS> Question <SEP> Context <SEP>
      token_typess:  None
class_docstr_tok: ["The","basic","pretrained","model","for","QA",".","It","is","used","in","the","original","BERT","paper","for","SQuAD","1.1",".","Here",",","we","directly","use","the","backbone","network","to","extract","the","contextual","embeddings","and","use","another","dense","layer","to","map","the","contextual","embeddings","to","the","start","scores","and","end","scores",".","use_segmentation","is","used","to","mark","whether","we","segment","the","input","sentence",".","In","RoBERTa","and","XLMR",",","this","flag","is","set","to","True",",","then","the","QA","model","no","longer","accept","`","token_types","`","as","valid","input",".","-","use_segmentation=True",":","tokens",":","<","CLS",">","Question","<","SEP",">","Context","<","SEP",">","token_typess",":","0","0","0","1","1","-","use_segmentation=False",":","tokens",":","<","CLS",">","Question","<","SEP",">","Context","<","SEP",">","token_typess",":","None"]
docstr: Parameters
  ----------
  tokens
      Shape (batch_size, seq_length)
      The merged input tokens
  token_types
      Shape (batch_size, seq_length)
      Token types for the sequences, used to indicate whether the word belongs to the
      first sentence or the second one.
  valid_length
      Shape (batch_size,)
      Valid length of the sequence. This is used to mask the padded tokens.
  p_mask
      The mask that is associated with the tokens.
  
  Returns
  -------
  start_logits
      Shape (batch_size, sequence_length)
      The log-softmax scores that the position is the start position.
  end_logits
      Shape (batch_size, sequence_length)
      The log-softmax scores that the position is the end position.
docstr_tok: ["Parameters","--","--","--","--","--","tokens","Shape","(","batch_size",",","seq_length",")","The","merged","input","tokens","token_types","Shape","(","batch_size",",","seq_length",")","Token","types","for","the","sequences",",","used","to","indicate","whether","the","word","belongs","to","the","first","sentence","or","the","second","one",".","valid_length","Shape","(","batch_size",",",")","Valid","length","of","the","sequence",".","This","is","used","to","mask","the","padded","tokens",".","p_mask","The","mask","that","is","associated","with","the","tokens",".","Returns","--","--","--","-","start_logits","Shape","(","batch_size",",","sequence_length",")","The","log-softmax","scores","that","the","position","is","the","start","position",".","end_logits","Shape","(","batch_size",",","sequence_length",")","The","log-softmax","scores","that","the","position","is","the","end","position","."]
code: def forward(self, tokens, token_types, valid_length, p_mask):
      """
  
      Parameters
      ----------
      tokens
          Shape (batch_size, seq_length)
          The merged input tokens
      token_types
          Shape (batch_size, seq_length)
          Token types for the sequences, used to indicate whether the word belongs to the
          first sentence or the second one.
      valid_length
          Shape (batch_size,)
          Valid length of the sequence. This is used to mask the padded tokens.
      p_mask
          The mask that is associated with the tokens.
  
      Returns
      -------
      start_logits
          Shape (batch_size, sequence_length)
          The log-softmax scores that the position is the start position.
      end_logits
          Shape (batch_size, sequence_length)
          The log-softmax scores that the position is the end position.
      """
      # Get contextual embedding with the shape (batch_size, sequence_length, C)
      if self.use_segmentation:
          contextual_embeddings = self.backbone(
              tokens, token_types, valid_length
          )
      else:
          contextual_embeddings = self.backbone(tokens, valid_length)
      scores = self.qa_outputs(contextual_embeddings)
      start_scores = scores[:, :, 0]
      end_scores = scores[:, :, 1]
      start_logits = masked_logsoftmax(
          start_scores, mask=p_mask, axis=-1
      )
      end_logits = masked_logsoftmax(end_scores, mask=p_mask, axis=-1)
      return start_logits, end_logits
  
file_path: gluon-nlp/docs/model_zoo/question_answering/models.py
imports: import mxnet
  from mxnet import np, npx
  from mxnet.gluon import nn, HybridBlock
  from mxnet.util import use_np
  from gluonnlp.layers import get_activation
  from gluonnlp.op import select_vectors_by_position
  from gluonnlp.attention_cell import masked_logsoftmax, masked_softmax
label_desc: Use image node_id 2 for calling the ModelForQABasic obj's underlying member method code with example usage: obj.forward(tokens, token_types, valid_length, p_mask) and returns: start_logits,  end_logits