code: def _to_spans(x):
      
      if isinstance(x, Candidate):
          return [_to_span(m) for m in x]
      elif isinstance(x, Mention):
          return [x.context]
      elif isinstance(x, TemporarySpanMention):
          return [x]
      else:
          raise ValueError(f"{type(x)} is an invalid argument type")
docs: Convert a Candidate, Mention, or Span to a list of spans.