class_docstr: BERT masked LM using Huggingface Transformers and TensorFlow 2.
class_docstr_tok: ["BERT","masked","LM","using","Huggingface","Transformers","and","TensorFlow","2","."]
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."""
      # If input has a 'tokens' field, use that. Otherwise tokenize the text.
      tokenized_texts = [
          ex.get("tokens") or self.tokenizer.tokenize(ex["text"])
          for ex in inputs
      ]
      encoded_input = model_utils.batch_encode_pretokenized(
          self.tokenizer, tokenized_texts
      )
  
      # out.logits is a single tensor
      #    <float32>[batch_size, num_tokens, vocab_size]
      # out.hidden_states is a list of num_layers + 1 tensors, each
      #    <float32>[batch_size, num_tokens, h_dim]
      out: transformers.modeling_tf_outputs.TFMaskedLMOutput = (
          self.model(encoded_input)
      )
      batched_outputs = {
          "probas": tf.nn.softmax(out.logits, axis=-1).numpy(),
          "input_ids": encoded_input["input_ids"].numpy(),
          "ntok": tf.reduce_sum(
              encoded_input["attention_mask"], axis=1
          ).numpy(),
          # last layer, first token
          "cls_emb": out.hidden_states[-1][:, 0].numpy(),
      }
      # List of dicts, one per example.
      unbatched_outputs = utils.unbatch_preds(batched_outputs)
      # Postprocess to remove padding and decode predictions.
      return map(self._postprocess, unbatched_outputs)
  
imports: import re
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.examples.models import model_utils
  from lit_nlp.lib import file_cache
  from lit_nlp.lib import utils
  import numpy
  import tensorflow
  import transformers
label_desc: Use image node_id 7 for calling the BertMLM obj's underlying member method code with example usage: obj.predict_minibatch(inputs) and returns: map