code: def build_model(input_size, hidden_size, output_size, model_type):
      # Model Type is simple RNN
      if model_type == "rnn":
          model = Sequential()
          model.add(
              Recurrent().add(RnnCell(input_size, hidden_size, Tanh()))
          ).add(TimeDistributed(Linear(hidden_size, output_size)))
          model.reset()
  
          # Simple RNN with MKL-DNN backend is unsupported for now.
          if get_bigdl_engine_type() == "MklDnn":
              invalidInputError(
                  False,
                  "Simple RNN is unsupported with MKL-DNN backend",
              )
  
      # Model Type is LSTM
      elif model_type == "lstm":
          model = Sequential()
          model.add(Recurrent().add(LSTM(input_size, hidden_size))).add(
              TimeDistributed(Linear(hidden_size, output_size))
          )
          model.reset()
  
          # LSTM with MKL-DNN backend
          if get_bigdl_engine_type() == "MklDnn":
              # To use MKL-DNN backend, the model has to be a graph model with
              # input and output formats set. Sequential model cannot be used in
              # this case, so we convert it to a graph model.
              model = model.to_graph()
  
              # The format index of input or output format can be checked
              # in: ${BigDL-core}/native-dnn/src/main/java/com/intel/analytics/bigdl/mkl/Memory.java
              model.set_input_formats([27])  # Set input format to ntc
              model.set_output_formats([27])  # Set output format to ntc
  
      return model
  
file_path: BigDL/python/dllib/src/bigdl/dllib/models/rnn/rnnexample.py
imports: import itertools
  import re
  from optparse import OptionParser
  from bigdl.dllib.feature.dataset import base
  from bigdl.dllib.feature.dataset import sentence
  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.utils.common import Sample
label_desc: Use image node_id 3 for calling a global function with example usage: build_model(input_size, hidden_size, output_size, model_type) and returns: model