class_docstr: BERT encoder for pre-tokenized text.
class_docstr_tok: ["BERT","encoder","for","pre-tokenized","text","."]
docstr: Predict on a single minibatch of examples.
docstr_tok: ["Predict","on","a","single","minibatch","of","examples","."]
code: def predict_minibatch(self, inputs):
      """Predict on a single minibatch of examples."""
      tokens_and_offsets = [
          retokenize.subtokenize(ex["tokens"], self.tokenizer.tokenize)
          for ex in inputs
      ]
      tokenized_texts, offsets = zip(*tokens_and_offsets)
      # Process to ids, add special tokens, and compute segment ids and masks.
      encoded_input = self.tokenizer.batch_encode_plus(
          list(tokenized_texts),
          is_split_into_words=True,
          return_tensors="tf",
          add_special_tokens=True,
          max_length=self.max_seq_length,
          padding="longest",
          truncation="longest_first",
      )
  
      out: transformers.modeling_tf_outputs.TFMaskedLMOutput = (
          self.model(encoded_input)
      )
      batched_outputs = {
          "input_ids": encoded_input["input_ids"].numpy(),
          "ntok": tf.reduce_sum(
              encoded_input["attention_mask"], axis=1
          ).numpy(),
          "top_layer_embs": out.hidden_states[
              -1
          ].numpy(),  # last layer, all tokens
      }
      # List of dicts, one per example.
      unbatched_outputs = list(utils.unbatch_preds(batched_outputs))
      # Postprocess to remove padding and add offsets.
      ret = [self._postprocess(ubo) for ubo in unbatched_outputs]
      for preds, offset_indices in zip(ret, offsets):
          preds["offsets"] = offset_indices
      return ret
  
file_path: lit/lit_nlp/examples/coref/encoders.py
imports: import os
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.coref import retokenize
  from lit_nlp.examples.models import model_utils
  from lit_nlp.lib import utils
  import numpy
  import tensorflow
  import transformers
label_desc: Use image node_id 6 for calling the BertEncoderWithOffsets obj's underlying member method code with example usage: obj.predict_minibatch(inputs) and returns: ret