class_docstr: Abstract base class for QA Datasets with common utility methods 
class_docstr_tok: ["Abstract","base","class","for","QA","Datasets","with","common","utility","methods"]
docstr: Filters out doc_spans, which might not be relevant to answering question, 
  which can be helpful when document is extremely long leading to many doc_spans with no answers
  
  Args:
      doc_spans: all possible doc_spans
      tok_start_position: start position of answer in document
      tok_end_position: end position of answer in document
      mode:
          all: do not filter
          only_positive: only keep doc_spans containing the answer
          limited_negative: only keep 10 doc_spans that are nearest to answer
  
  Returns:
      doc_spans: doc_spans after filtering
docstr_tok: ["Filters","out","doc_spans",",","which","might","not","be","relevant","to","answering","question",",","which","can","be","helpful","when","document","is","extremely","long","leading","to","many","doc_spans","with","no","answers","Args",":","doc_spans",":","all","possible","doc_spans","tok_start_position",":","start","position","of","answer","in","document","tok_end_position",":","end","position","of","answer","in","document","mode",":","all",":","do","not","filter","only_positive",":","only","keep","doc_spans","containing","the","answer","limited_negative",":","only","keep","10","doc_spans","that","are","nearest","to","answer","Returns",":","doc_spans",":","doc_spans","after","filtering"]
code: def keep_relevant_docspans(
      doc_spans, tok_start_position, tok_end_position, mode
  ):
      """
      Filters out doc_spans, which might not be relevant to answering question,
      which can be helpful when document is extremely long leading to many doc_spans with no answers
  
      Args:
          doc_spans: all possible doc_spans
          tok_start_position: start position of answer in document
          tok_end_position: end position of answer in document
          mode:
              all: do not filter
              only_positive: only keep doc_spans containing the answer
              limited_negative: only keep 10 doc_spans that are nearest to answer
  
      Returns:
          doc_spans: doc_spans after filtering
      """
  
      if mode == "all":
          return doc_spans
      elif mode == "only_positive":
          if tok_start_position in [-1, None] or tok_end_position in [
              -1,
              None,
          ]:
              return []
          else:
              return [
                  doc_span
                  for doc_span in doc_spans
                  if tok_start_position >= doc_span.start
                  and tok_end_position
                  <= doc_span.start + doc_span.length - 1
              ]
      elif mode == "limited_negative":
          n_candidates = 10
          if tok_start_position in [-1, None] or tok_end_position in [
              -1,
              None,
          ]:
              pass
          else:
              doc_spans.sort(
                  key=lambda doc_span: QADataset.get_average_dist_to_tok_start_and_end(
                      doc_span, tok_start_position, tok_end_position
                  )
              )
          return doc_spans[:n_candidates]
      else:
          raise ValueError(
              "mode can only be in {all, only_positive and limited_negative"
          )
  
imports: import collections
  import pickle
  from functools import lru_cache
  from typing import List
  import psutil
  import torch
  from nemo.collections.nlp.data.data_utils import is_whitespace
  from nemo.collections.nlp.data.question_answering.data_processor.qa_processing import EVALUATION_MODE, INFERENCE_MODE, TRAINING_MODE
  from nemo.core.classes import Dataset
  from nemo.utils import logging
label_desc: Use image node_id 11 for calling the QADataset obj's underlying member method code with example usage: obj.keep_relevant_docspans(doc_spans, tok_start_position, tok_end_position, mode) and returns: doc_spans, list, unknown, doc_spans