class_docstr: Tests fast WordPiece when used in a Keras model.
class_docstr_tok: ["Tests","fast","WordPiece","when","used","in","a","Keras","model","."]
docstr: Checks TFLite conversion and inference.
code: def testTfLiteWordpieceTokenizer(
      self, no_pretokenization, text_inputs
  ):
      """Checks TFLite conversion and inference."""
  
      class TokenizerModel(tf.keras.Model):
          def __init__(
              self,
              vocab,
              max_bytes_per_word=100,
              suffix_indicator="##",
              unknown_token="<unk>",
              no_pretokenization=True,
              support_detokenization=False,
              **kwargs,
          ):
              super().__init__(**kwargs)
              self.wp = FastWordpieceTokenizer(
                  vocab=vocab,
                  max_bytes_per_word=max_bytes_per_word,
                  suffix_indicator=suffix_indicator,
                  unknown_token=unknown_token,
                  no_pretokenization=no_pretokenization,
                  support_detokenization=support_detokenization,
              )
  
          def call(self, input_tensor, **kwargs):
              return self.wp.tokenize(input_tensor).flat_values
  
          @tf.function(
              input_signature=[
                  tf.TensorSpec(shape=[None], dtype=dtypes.int64)
              ]
          )
          def detokenize(self, input_tensor):
              return self.wp.detokenize(input_tensor)
  
      # Test input data.
      input_data = np.array(text_inputs)
  
      # Define a Keras model.
      model = TokenizerModel(
          _TEST_VOCAB,
          _TEST_MAX_BYTES_PER_WORD,
          _TEST_SUFFIX_INDICATOR,
          _TEST_UNKNOWN_TOKEN,
          no_pretokenization,
          support_detokenization=True,
      )
      # Test tokenization.
      # Do TF.Text inference.
      tf_result = model(input_data)
  
      # 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,
      )
      interp.allocate_tensors()
      input_details = interp.get_input_details()
      interp.set_tensor(input_details[0]["index"], input_data)
      interp.invoke()
      output_details = interp.get_output_details()
      tflite_result = interp.get_tensor(output_details[0]["index"])
  
      # Assert the results are identical.
      self.assertAllEqual(tflite_result, tf_result)
  
      # Test detokenization.
      # Do TF.Text detokenization.
      tf_detokenization_result = model.detokenize(tf_result)
      # Convert to TFLite.
      converter = tf.lite.TFLiteConverter.from_concrete_functions(
          [model.detokenize.get_concrete_function()], model
      )
      converter.target_spec.supported_ops = [
          tf.lite.OpsSet.TFLITE_BUILTINS
      ]
      converter.allow_custom_ops = True
      tflite_model = converter.convert()
  
      # Do TFLite detokenization.
      interp = interpreter.InterpreterWithCustomOps(
          model_content=tflite_model,
          custom_op_registerers=tf_text.tflite_registrar.SELECT_TFTEXT_OPS,
      )
      interp.allocate_tensors()
      detokenize = interp.get_signature_runner("serving_default")
      tflite_detokenization_result = detokenize(input_tensor=tf_result)[
          "output_0"
      ]
  
      # Assert the results are identical.
      self.assertAllEqual(
          tf_detokenization_result, tflite_detokenization_result
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl import flags
  from absl.testing import parameterized
  import numpy
  import tensorflow
  import tensorflow_text
  from tensorflow.lite.python import interpreter
  from tensorflow.python.data.kernel_tests import test_base
  from tensorflow.python.data.ops import dataset_ops
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops.ragged import ragged_factory_ops
  from tensorflow.python.platform import gfile
  from tensorflow.python.platform import test
  from tensorflow_text.python.ops.fast_wordpiece_tokenizer import FastWordpieceTokenizer
label_desc: Use image node_id 1 for calling the FastWordpieceInKerasModelTest obj's underlying member method code with example usage: obj.testTfLiteWordpieceTokenizer(no_pretokenization, text_inputs) and returns: self, self