docstr: Checks TFLite conversion and inference.
docstr_tok: ["Checks","TFLite","conversion","and","inference","."]
code: def testTrimTfLite(self):
      """Checks TFLite conversion and inference."""
  
      class Model(tf.keras.Model):
          def __init__(self, **kwargs):
              super().__init__(**kwargs)
              self.trimmer_ = tf_text.RoundRobinTrimmer(3)
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(
                      shape=[None], dtype=tf.int32, name="in1vals"
                  ),
                  tf.TensorSpec(
                      shape=[None], dtype=tf.int64, name="in1splits"
                  ),
                  tf.TensorSpec(
                      shape=[None], dtype=tf.int32, name="in2vals"
                  ),
                  tf.TensorSpec(
                      shape=[None], dtype=tf.int64, name="in2splits"
                  ),
              ]
          )
          def call(self, in1vals, in1splits, in2vals, in2splits):
              in1 = tf.RaggedTensor.from_row_splits(in1vals, in1splits)
              in2 = tf.RaggedTensor.from_row_splits(in2vals, in2splits)
              [out1, out2] = self.trimmer_.trim([in1, in2])
              return {
                  "output_1": out1.flat_values,
                  "output_2": out2.flat_values,
              }
  
      # Test input data.
      in1vals = np.array([1, 2, 3, 4, 5], dtype=np.intc)
      in2vals = np.array([10, 20, 30, 40, 50, 60], dtype=np.intc)
      in1splits = np.array([0, 3, 5])
      in2splits = np.array([0, 3, 6])
  
      # Define a model.
      model = Model()
      # Do TF inference.
      tf_result = model(
          tf.constant(in1vals, dtype=tf.int32),
          tf.constant(in1splits, dtype=tf.int64),
          tf.constant(in2vals, dtype=tf.int32),
          tf.constant(in2splits, dtype=tf.int64),
      )
  
      # Convert to TFLite.
      converter = tf.lite.TFLiteConverter.from_keras_model(model)
      converter.target_spec.supported_ops = [
          tf.lite.OpsSet.TFLITE_BUILTINS
      ]
      converter.allow_custom_ops = True
      tflite_model = converter.convert()
  
      # Do TFLite inference.
      interp = interpreter.InterpreterWithCustomOps(
          model_content=tflite_model,
          custom_op_registerers=tf_text.tflite_registrar.SELECT_TFTEXT_OPS,
      )
      print(interp.get_signature_list())
      trimmer = interp.get_signature_runner("serving_default")
      tflite_result = trimmer(
          in1vals=in1vals,
          in1splits=in1splits,
          in2vals=in2vals,
          in2splits=in2splits,
      )
  
      # Assert the results are identical.
      self.assertAllEqual(
          tflite_result["output_1"], tf_result["output_1"]
      )
      self.assertAllEqual(
          tflite_result["output_2"], tf_result["output_2"]
      )
  
imports: from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_text
  from tensorflow.lite.python import interpreter
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops.ragged import ragged_factory_ops
  from tensorflow.python.platform import test
  from tensorflow_text.python.ops import trimmer_ops
label_desc: Use image node_id 4 for calling the RoundRobinTrimmerOpsTest obj's underlying member method code with example usage: obj.testTrimTfLite() and returns: dict