code: def preprocess_texts(
      text_docs: Iterable[str],
      lem: bool = False,
      stem: bool = False,
      custom_pipeline: List = None,
  ) -> Iterable[Any]:
      """Pre-process a text corpus.
  
      Cleans list of documents by running through a customizable text-preprocessing
      pipeline.
  
      Args:
          text_docs: A list of strings of text documents (also accepts arrays and
              Pandas series)
          lem: If True, lemmatization becomes part of the pre-processing. Recommended to
              set as False and run user-created lemmatization function if pipeline is
              customized. Default is False.
          stem: If True, stemming becomes part of the pre-processing. Recommended to
              set as False and run user-created stemming function if pipeline is
              customized. Default is False.
          custom_pipeline: A custom list of strings and/or function objects which are
              the function names that text_docs_bow will run through. Default is None,
              which uses the pipeline: ['tokenize', 'to_lower', 'remove_punct',
              'remove_digits', 'remove_single_char_and_spaces', 'remove_stopwords']
  
      Returns:
          text_docs: List of lists of words for each document which have undergone a
              pre-processing pipeline
      """
      if not custom_pipeline:
          pipeline = [
              "tokenize",
              "to_lower",
              "remove_punct",
              "remove_digits",
              "remove_single_char_and_spaces",
              "remove_stopwords",
          ]
      else:
          pipeline = custom_pipeline
  
      if lem:
          pipeline.append("lemmatize")
      if stem:
          pipeline.append("stem")
  
      for function in pipeline:
          if isinstance(function, str):
              current_method = getattr(text_preprocessing, function)
              text_docs = current_method(text_docs)
          else:
              text_docs = function(text_docs)
  
      return to_list(text_docs)
  
imports: import re
  import string
  import warnings
  from types import GeneratorType
  from typing import List, Optional, Any, Iterable, TYPE_CHECKING
  import pandas
  from sklearn.feature_extraction.text import TfidfVectorizer, CountVectorizer
  from data_describe.text import text_preprocessing
  from data_describe.compat import _requires, _compat
label_desc: Use image node_id 12 for calling a global function with example usage: preprocess_texts(text_docs, lem, stem, custom_pipeline) and returns: to_list