code: def texts_from_array(
      x_train,
      y_train,
      x_test=None,
      y_test=None,
      class_names=[],
      max_features=MAX_FEATURES,
      maxlen=MAXLEN,
      val_pct=0.1,
      ngram_range=1,
      preprocess_mode="standard",
      lang=None,  # auto-detected
      random_state=None,
      verbose=1,
  ):
      """
      ```
      Loads and preprocesses text data from arrays.
      texts_from_array can handle data for both text classification
      and text regression.  If class_names is empty, a regression task is assumed.
      Args:
          x_train(list): list of training texts
          y_train(list): labels in one of the following forms:
                         1. list of integers representing classes (class_names is required)
                         2. list of strings representing classes (class_names is not needed and ignored.)
                         3. a one or multi hot encoded array representing classes (class_names is required)
                         4. numerical values for text regresssion (class_names should be left empty)
          x_test(list): list of training texts
          y_test(list): labels in one of the following forms:
                         1. list of integers representing classes (class_names is required)
                         2. list of strings representing classes (class_names is not needed and ignored.)
                         3. a one or multi hot encoded array representing classes (class_names is required)
                         4. numerical values for text regresssion (class_names should be left empty)
          class_names (list): list of strings representing class labels
                              shape should be (num_examples,1) or (num_examples,)
          max_features(int): max num of words to consider in vocabulary
                             Note: This is only used for preprocess_mode='standard'.
          maxlen(int): each document can be of most <maxlen> words. 0 is used as padding ID.
          ngram_range(int): size of multi-word phrases to consider
                            e.g., 2 will consider both 1-word phrases and 2-word phrases
                                 limited by max_features
          val_pct(float): Proportion of training to use for validation.
                          Has no effect if x_val and  y_val is supplied.
          preprocess_mode (str):  Either 'standard' (normal tokenization) or one of {'bert', 'distilbert'}
                                  tokenization and preprocessing for use with
                                  BERT/DistilBert text classification model.
          lang (str):            language.  Auto-detected if None.
          random_state(int):      If integer is supplied, train/test split is reproducible.
                                  If None, train/test split will be random.
          verbose (boolean): verbosity
      ```
      """
      U.check_array(
          x_train, y=y_train, X_name="x_train", y_name="y_train"
      )
  
      if x_test is None or y_test is None:
          x_train, x_test, y_train, y_test = train_test_split(
              x_train,
              y_train,
              test_size=val_pct,
              random_state=random_state,
          )
      else:
          U.check_array(
              x_test, y=y_test, X_name="x_test", y_name="y_test"
          )
  
      # removed as TextPreprocessor now handles this.
      # if isinstance(y_train[0], str):
      # if not isinstance(y_test[0], str):
      # raise ValueError('y_train contains strings, but y_test does not')
      # encoder = LabelEncoder()
      # encoder.fit(y_train)
      # y_train = encoder.transform(y_train)
      # y_test = encoder.transform(y_test)
  
      # detect language
      if lang is None:
          lang = TU.detect_lang(x_train)
      check_unsupported_lang(lang, preprocess_mode)
  
      # return preprocessed the texts
      preproc_type = tpp.TEXT_PREPROCESSORS.get(preprocess_mode, None)
      if None:
          raise ValueError("unsupported preprocess_mode")
      preproc = preproc_type(
          maxlen,
          max_features,
          class_names=class_names,
          lang=lang,
          ngram_range=ngram_range,
      )
      trn = preproc.preprocess_train(x_train, y_train, verbose=verbose)
      val = preproc.preprocess_test(x_test, y_test, verbose=verbose)
      if not preproc.get_classes() and verbose:
          print(
              "task: text regression (supply class_names argument if this is supposed to be classification task)"
          )
      else:
          print("task: text classification")
      return (trn, val, preproc)
  
file_path: ktrain/ktrain/text/data.py
imports: from ..None import utils
  from ..imports import *
  from .None import preprocessor
  from .None import textutils
label_desc: Use image node_id 4 for calling a global function with example usage: texts_from_array(x_train, y_train, x_test, y_test, class_names, max_features, maxlen, val_pct, ngram_range, preprocess_mode, lang, random_state, verbose) and returns: trn,  val,  preproc