code: def basic_extractor(document, train_set):
      """A basic document feature extractor that returns a dict indicating
      what words in ``train_set`` are contained in ``document``.
  
      :param document: The text to extract features from. Can be a string or an iterable.
      :param list train_set: Training data set, a list of tuples of the form
          ``(words, label)`` OR an iterable of strings.
      """
  
      try:
          el_zero = next(
              iter(train_set)
          )  # Infer input from first element.
      except StopIteration:
          return {}
      if isinstance(el_zero, basestring):
          word_features = [w for w in chain([el_zero], train_set)]
      else:
          try:
              assert isinstance(el_zero[0], basestring)
              word_features = _get_words_from_dataset(
                  chain([el_zero], train_set)
              )
          except Exception:
              raise ValueError("train_set is probably malformed.")
  
      tokens = _get_document_tokens(document)
      features = dict(
          (
              ("contains({0})".format(word), (word in tokens))
              for word in word_features
          )
      )
      return features
  
imports: from __future__ import absolute_import
  from itertools import chain
  import nltk
  from textblob.compat import basestring
  from textblob.decorators import cached_property
  from textblob.exceptions import FormatError
  from textblob.tokenizers import word_tokenize
  from textblob.utils import strip_punc, is_filelike
  import textblob.formats
label_desc: Use image node_id 3 for calling a global function with example usage: basic_extractor(document, train_set) and returns: features, dict