code: def train(
      sc,
      data_path,
      batch_size,
      sequence_len,
      max_words,
      embedding_dim,
      training_split,
  ):
      print("Processing text dataset")
      texts = news20.get_news20(source_dir=data_path)
      data_rdd = sc.parallelize(texts, 2)
  
      word_to_ic = analyze_texts(data_rdd)
  
      # Only take the top wc between [10, sequence_len]
      word_to_ic = dict(word_to_ic[10:max_words])
      bword_to_ic = sc.broadcast(word_to_ic)
  
      w2v = news20.get_glove_w2v(
          source_dir=data_path, dim=embedding_dim
      )
      filtered_w2v = dict(
          (w, v) for w, v in w2v.items() if w in word_to_ic
      )
      bfiltered_w2v = sc.broadcast(filtered_w2v)
  
      tokens_rdd = data_rdd.map(
          lambda text_label: (
              [
                  w
                  for w in text_to_words(text_label[0])
                  if w in bword_to_ic.value
              ],
              text_label[1],
          )
      )
      padded_tokens_rdd = tokens_rdd.map(
          lambda tokens_label: (
              pad(tokens_label[0], "##", sequence_len),
              tokens_label[1],
          )
      )
      vector_rdd = padded_tokens_rdd.map(
          lambda tokens_label: (
              [
                  to_vec(w, bfiltered_w2v.value, embedding_dim)
                  for w in tokens_label[0]
              ],
              tokens_label[1],
          )
      )
      sample_rdd = vector_rdd.map(
          lambda vectors_label: to_sample(
              vectors_label[0], vectors_label[1], embedding_dim
          )
      )
  
      train_rdd, val_rdd = sample_rdd.randomSplit(
          [training_split, 1 - training_split]
      )
  
      optimizer = Optimizer.create(
          model=build_model(news20.CLASS_NUM),
          training_set=train_rdd,
          criterion=ClassNLLCriterion(),
          end_trigger=MaxEpoch(max_epoch),
          batch_size=batch_size,
          optim_method=Adagrad(
              learningrate=learning_rate, learningrate_decay=0.001
          ),
      )
  
      optimizer.set_validation(
          batch_size=batch_size,
          val_rdd=val_rdd,
          trigger=EveryEpoch(),
          val_method=[Top1Accuracy()],
      )
  
      logdir = "/tmp/.bigdl/"
      app_name = "adam-" + dt.datetime.now().strftime("%Y%m%d-%H%M%S")
  
      train_summary = TrainSummary(log_dir=logdir, app_name=app_name)
      train_summary.set_summary_trigger(
          "Parameters", SeveralIteration(50)
      )
      val_summary = ValidationSummary(log_dir=logdir, app_name=app_name)
      optimizer.set_train_summary(train_summary)
      optimizer.set_val_summary(val_summary)
  
      train_model = optimizer.optimize()
  
file_path: BigDL/python/dllib/src/bigdl/dllib/models/textclassifier/textclassifier.py
imports: import itertools
  import re
  from optparse import OptionParser
  from bigdl.dllib.feature.dataset import news20
  from bigdl.dllib.nn.layer import *
  from bigdl.dllib.nn.criterion import *
  from bigdl.dllib.optim.optimizer import *
  from bigdl.dllib.utils.common import *
  from bigdl.dllib.nncontext import *
  from bigdl.dllib.utils.utils import detect_conda_env_name
  import os
  import datetime
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 7 for calling a global function with example usage: train(sc, data_path, batch_size, sequence_len, max_words, embedding_dim, training_split) without return types