code: def test_tf_keras_imdb_lstm(random_seed):
      """Basic LSTM example using the keras API defined in tensorflow"""
      tf = pytest.importorskip("tensorflow")
      rs = np.random.RandomState(random_seed)
      tf.compat.v1.random.set_random_seed(random_seed)
  
      # this fails right now for new TF versions (there is a warning in the code for this)
      if version.parse(tf.__version__) >= version.parse("2.5.0"):
          pytest.skip()
  
      from tensorflow.keras.datasets import imdb
      from tensorflow.keras.layers import LSTM, Dense, Embedding
      from tensorflow.keras.models import Sequential
      from tensorflow.keras.preprocessing import sequence
  
      tf.compat.v1.disable_eager_execution()
  
      # load the data from keras
      max_features = 1000
      try:
          (X_train, _), (X_test, _) = imdb.load_data(
              num_words=max_features
          )
      except Exception:
          return  # this hides a bug in the most recent version of keras that prevents data loading
      X_train = sequence.pad_sequences(X_train, maxlen=100)
      X_test = sequence.pad_sequences(X_test, maxlen=100)
  
      # create the model. note that this is model is very small to make the test
      # run quick and we don't care about accuracy here
      mod = Sequential()
      mod.add(Embedding(max_features, 8))
      mod.add(LSTM(10, dropout=0.2, recurrent_dropout=0.2))
      mod.add(Dense(1, activation="sigmoid"))
      mod.compile(
          loss="binary_crossentropy",
          optimizer="adam",
          metrics=["accuracy"],
      )
  
      # select the background and test samples
      inds = rs.choice(X_train.shape[0], 3, replace=False)
      background = X_train[inds]
      testx = X_test[10:11]
  
      # explain a prediction and make sure it sums to the difference between the average output
      # over the background samples and the current output
      sess = tf.compat.v1.keras.backend.get_session()
      sess.run(tf.compat.v1.global_variables_initializer())
      # For debugging, can view graph:
      # writer = tf.compat.v1.summary.FileWriter("c:\\tmp", sess.graph)
      # writer.close()
      e = shap.DeepExplainer(
          (mod.layers[0].input, mod.layers[-1].output), background
      )
      shap_values = e.shap_values(testx)
      sums = np.array(
          [shap_values[i].sum() for i in range(len(shap_values))]
      )
      diff = sess.run(
          mod.layers[-1].output, feed_dict={mod.layers[0].input: testx}
      )[0, :] - sess.run(
          mod.layers[-1].output,
          feed_dict={mod.layers[0].input: background},
      ).mean(
          0
      )
      assert np.allclose(
          sums, diff, atol=1e-02
      ), "Sum of SHAP values does not match difference!"
  
file_path: shap/tests/explainers/test_deep.py
imports: import numpy
  import pandas
  import pytest
  from packaging import version
  import shap
  from shap import DeepExplainer
label_desc: Use image node_id 4 for calling a global function with example usage: test_tf_keras_imdb_lstm(random_seed) without return types