code: def _get_doc_weighted_spans(
      doc,
      vec,
      feature_weights,  # type: FeatureWeights
      feature_fn=None,  # type: Optional[Callable[[str], str]]
  ):
      # type: (...) -> Optional[Tuple[FoundFeatures, DocWeightedSpans]]
      if isinstance(vec, InvertableHashingVectorizer):
          vec = vec.vec
  
      if hasattr(vec, "get_doc_weighted_spans"):
          return vec.get_doc_weighted_spans(
              doc, feature_weights, feature_fn
          )
  
      if not isinstance(vec, VectorizerMixin):
          return None
  
      span_analyzer, preprocessed_doc = build_span_analyzer(doc, vec)
      if span_analyzer is None:
          return None
  
      feature_weights_dict = _get_feature_weights_dict(
          feature_weights, feature_fn
      )
      spans = []
      found_features = {}
      for f_spans, feature in span_analyzer(preprocessed_doc):
          if feature not in feature_weights_dict:
              continue
          weight, key = feature_weights_dict[feature]
          spans.append((feature, f_spans, weight))
          # XXX: this assumes feature names are unique
          found_features[key] = weight
  
      return found_features, DocWeightedSpans(
          document=preprocessed_doc,
          spans=spans,
          preserve_density=vec.analyzer.startswith("char"),
      )
  
file_path: eli5/eli5/sklearn/text.py
imports: from __future__ import absolute_import
  from typing import Any, Union, Callable, Dict, List, Optional, Set, Tuple
  from sklearn.pipeline import FeatureUnion
  from eli5.base import DocWeightedSpans, WeightedSpans, FeatureWeights, FeatureWeight, TargetExplanation
  from eli5.formatters import FormattedFeatureName
  from eli5.sklearn.unhashing import InvertableHashingVectorizer
  from eli5.sklearn._span_analyzers import build_span_analyzer
label_desc: Use image node_id 3 for calling a global function with example usage: _get_doc_weighted_spans(doc, vec, feature_weights, feature_fn) and returns: found_features,  DocWeightedSpans, vec, None, None