code: def _text_model(
      name,
      train_data,
      preproc=None,
      multilabel=None,
      classification=True,
      metrics=None,
      verbose=1,
  ):
      """
      ```
      Build and return a text classification or text regression model.
  
      Args:
          name (string): one of:
                        - 'fasttext' for FastText model
                        - 'nbsvm' for NBSVM model
                        - 'logreg' for logistic regression
                        - 'bigru' for Bidirectional GRU with pretrained word vectors
                        - 'bert' for BERT Text Classification
                        - 'distilbert' for Hugging Face DistilBert model
          train_data (tuple): a tuple of numpy.ndarrays: (x_train, y_train) or ktrain.Dataset instance
                              returned from one of the texts_from_* functions
          preproc: a ktrain.text.TextPreprocessor instance.
                   As of v0.8.0, this is required.
          multilabel (bool):  If True, multilabel model will be returned.
                              If false, binary/multiclass model will be returned.
                              If None, multilabel will be inferred from data.
          classification(bool): If True, will build a text classificaton model.
                                Otherwise, a text regression model will be returned.
          metrics(list): List of metrics to use.  If None: 'accuracy' is used for binar/multiclassification,
                         'binary_accuracy' is used for multilabel classification, and 'mae' is used for regression.
          verbose (boolean): verbosity of output
      Return:
          model (Model): A Keras Model instance
      ```
      """
      # check arguments
      if not isinstance(
          train_data, tuple
      ) and not U.is_huggingface_from_data(train_data):
          err = """
              Please pass training data in the form of a tuple of numpy.ndarrays
              or data returned from a ktrain texts_from* function.
              """
          raise Exception(err)
  
      if not isinstance(preproc, tpp.TextPreprocessor):
          msg = "The preproc argument is required."
          msg += " The preproc arg should be an instance of TextPreprocessor, which is "
          msg += " the third return value from texts_from_folder, texts_from_csv, etc."
          # warnings.warn(msg, FutureWarning)
          raise ValueError(msg)
      if name == BIGRU and preproc.ngram_count() != 1:
          raise ValueError(
              "Data should be processed with ngram_range=1 for bigru model."
          )
      is_bert = U.bert_data_tuple(train_data)
      if (is_bert and name != BERT) or (not is_bert and name == BERT):
          raise ValueError(
              "if '%s' is selected model, then preprocess_mode='%s' should be used and vice versa"
              % (BERT, BERT)
          )
      is_huggingface = U.is_huggingface(data=train_data)
      if (is_huggingface and name not in HUGGINGFACE_MODELS) or (
          not is_huggingface and name in HUGGINGFACE_MODELS
      ):
          raise ValueError(
              "you are using a Hugging Face transformer model but did not preprocess as such (or vice versa)"
          )
      if is_huggingface and preproc.name != name:
          raise ValueError(
              "you preprocessed for %s but want to build a %s model"
              % (preproc.name, name)
          )
  
      if not classification:  # regression
          if metrics is None or metrics == ["accuracy"]:
              metrics = ["mae"]
          num_classes = 1
          multilabel = False
          loss_func = "mse"
          activation = None
          max_features = preproc.max_features
          features = None
          maxlen = U.shape_from_data(train_data)[1]
          U.vprint("maxlen is %s" % (maxlen), verbose=verbose)
      else:  # classification
          # set number of classes and multilabel flag
          num_classes = U.nclasses_from_data(train_data)
  
          # determine multilabel
          if multilabel is None:
              multilabel = U.is_multilabel(train_data)
          if multilabel and name in [NBSVM, LOGREG]:
              warnings.warn(
                  "switching to fasttext model, as data suggests "
                  "multilabel classification from data."
              )
              name = FASTTEXT
          U.vprint("Is Multi-Label? %s" % (multilabel), verbose=verbose)
  
          # set metrics
          if multilabel and metrics is None:
              metrics = ["binary_accuracy"]
          elif metrics is None:
              metrics = ["accuracy"]
  
          # set loss and activations
          loss_func = "categorical_crossentropy"
          activation = "softmax"
          if multilabel:
              loss_func = "binary_crossentropy"
              activation = "sigmoid"
  
          # determine number of classes, maxlen, and max_features
          max_features = (
              preproc.max_features if preproc is not None else None
          )
          features = set()
          if not is_bert and not is_huggingface:
              U.vprint("compiling word ID features...", verbose=verbose)
              x_train = train_data[0]
              y_train = train_data[1]
              if isinstance(y_train[0], int):
                  raise ValueError(
                      "train labels should not be in sparse format"
                  )
  
              for x in x_train:
                  features.update(x)
              # max_features = len(features)
              if max_features is None:
                  max_features = max(features) + 1
                  U.vprint(
                      "max_features is %s" % (max_features),
                      verbose=verbose,
                  )
          maxlen = U.shape_from_data(train_data)[1]
          U.vprint("maxlen is %s" % (maxlen), verbose=verbose)
  
      # return appropriate model
      if name in [LOGREG, LINREG]:
          model = _build_logreg(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
          )
  
      elif name == FASTTEXT:
          model = _build_fasttext(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
          )
      elif name == STANDARD_GRU:
          model = _build_standard_gru(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
          )
      elif name == NBSVM:
          model = _build_nbsvm(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
              train_data=train_data,
          )
  
      elif name == BIGRU:
          (tokenizer, tok_dct) = preproc.get_preprocessor()
          model = _build_bigru(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
              tokenizer=tokenizer,
              preproc=preproc,
          )
      elif name == BERT:
          model = _build_bert(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
              preproc=preproc,
          )
      elif name in HUGGINGFACE_MODELS:
          model = _build_transformer(
              num_classes,
              maxlen,
              max_features,
              features,
              loss_func=loss_func,
              activation=activation,
              metrics=metrics,
              verbose=verbose,
              preproc=preproc,
          )
  
      else:
          raise ValueError("name for textclassifier is invalid")
      U.vprint("done.", verbose=verbose)
      return model
  
file_path: ktrain/ktrain/text/models.py
imports: from ..None import utils
  from ..imports import *
  from .None import preprocessor
label_desc: Use image node_id 5 for calling a global function with example usage: _text_model(name, train_data, preproc, multilabel, classification, metrics, verbose) and returns: model