code: def _build_nbsvm(
      num_classes,
      maxlen,
      max_features,
      features,
      loss_func="categorical_crossentropy",
      activation="softmax",
      metrics=["accuracy"],
      verbose=1,
      train_data=None,
  ):
      if train_data is None:
          raise ValueError("train_data is required")
      x_train = train_data[0]
      y_train = train_data[1]
      Y = np.array([np.argmax(row) for row in y_train])
      num_columns = max(features) + 1
      num_rows = len(x_train)
  
      # set up document-term matrix
      X = csr_matrix((num_rows, num_columns), dtype=np.int8)
      # X = lil_matrix((num_rows, num_columns), dtype=np.int8)
      U.vprint(
          "building document-term matrix... this may take a few moments...",
          verbose=verbose,
      )
      r_ids = []
      c_ids = []
      data = []
      for row_id, row in enumerate(x_train):
          trigger = 10000
          trigger_end = min(row_id + trigger, num_rows)
          if row_id % trigger == 0:
              U.vprint(
                  "rows: %s-%s" % (row_id + 1, trigger_end),
                  verbose=verbose,
              )
          tmp_c_ids = [column_id for column_id in row if column_id > 0]
          num = len(tmp_c_ids)
          c_ids.extend(tmp_c_ids)
          r_ids.extend([row_id] * num)
          data.extend([1] * num)
      X = csr_matrix(
          (data, (r_ids, c_ids)), shape=(num_rows, num_columns)
      )
  
      # compute Naive Bayes log-count ratios
      U.vprint("computing log-count ratios...", verbose=verbose)
      nbratios = np.stack(
          [calc_r(i, X, Y).A1 for i in range(num_classes)]
      )
      nbratios = nbratios.T
      embedding_matrix = np.zeros((num_columns, num_classes))
      for i in range(1, num_columns):
          for j in range(num_classes):
              embedding_matrix[i, j] = nbratios[i, j]
  
      # set up the model
      inp = keras.layers.Input(shape=(maxlen,))
      r = keras.layers.Embedding(
          num_columns,
          num_classes,
          input_length=maxlen,
          weights=[embedding_matrix],
          trainable=False,
      )(inp)
      x = keras.layers.Embedding(
          num_columns,
          1,
          input_length=maxlen,
          embeddings_initializer="glorot_normal",
      )(inp)
      x = keras.layers.dot([r, x], axes=1)
      x = keras.layers.Flatten()(x)
      x = keras.layers.Activation(activation)(x)
      model = keras.Model(inputs=inp, outputs=x)
      model.compile(
          loss=loss_func, optimizer=U.DEFAULT_OPT, metrics=metrics
      )
      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 9 for calling a global function with example usage: _build_nbsvm(num_classes, maxlen, max_features, features, loss_func, activation, metrics, verbose, train_data) and returns: model