code: def test_tf_optimizer_with_sparse_gradient(self):
      ids = np.random.randint(0, 10, size=[40])
      labels = np.random.randint(0, 5, size=[40])
      id_rdd = self.sc.parallelize(ids)
      label_rdd = self.sc.parallelize(labels)
      training_rdd = id_rdd.zip(label_rdd).map(lambda x: [x[0], x[1]])
      with tf.Graph().as_default():
          dataset = TFDataset.from_rdd(
              training_rdd,
              names=["ids", "labels"],
              shapes=[[], []],
              types=[tf.int32, tf.int32],
              batch_size=8,
          )
          id_tensor, label_tensor = dataset.tensors
          embedding_table = tf.get_variable(
              name="word_embedding", shape=[10, 5]
          )
  
          embedding = tf.nn.embedding_lookup(embedding_table, id_tensor)
          loss = tf.reduce_mean(
              tf.losses.sparse_softmax_cross_entropy(
                  logits=embedding, labels=label_tensor
              )
          )
          optimizer = TFOptimizer.from_loss(loss, Adam(1e-3))
          optimizer.optimize(end_trigger=MaxEpoch(1))
          optimizer.sess.close()
  
file_path: analytics-zoo/pyzoo/test/zoo/tfpark/test_tfpark_tfoptimizer.py
imports: import pytest
  from bigdl.optim.optimizer import Adam, SGD, MaxEpoch
  from zoo.pipeline.api.keras.metrics import Accuracy
  from test.zoo.pipeline.utils.test_utils import ZooTestCase
  import tensorflow
  import numpy
  import tempfile
  import os
  from zoo.tfpark import TFDataset, TFOptimizer
label_desc: Use image node_id 2 for calling the TestTFParkTFOptimizer obj's underlying member method code with example usage: obj.test_tf_optimizer_with_sparse_gradient() without return types