class_docstr: GLUE benchmark model, using Keras/TF2 and Huggingface Transformers.
  
  This is a general-purpose classification or regression model. It works for
  one- or two-segment input, and predicts either a multiclass label or
  a regression score. See GlueModelConfig for available options.
  
  This implements the LIT API for inference (e.g. input_spec(), output_spec(),
  and predict()), but also provides a train() method to run fine-tuning.
  
  This is a full-featured implementation, which includes embeddings, attention,
  gradients, as well as support for the different input and output types above.
  For a more minimal example, see ../simple_tf2_demo.py.
class_docstr_tok: ["GLUE","benchmark","model",",","using","Keras\/TF2","and","Huggingface","Transformers",".","This","is","a","general-purpose","classification","or","regression","model",".","It","works","for","one-","or","two-segment","input",",","and","predicts","either","a","multiclass","label","or","a","regression","score",".","See","GlueModelConfig","for","available","options",".","This","implements","the","LIT","API","for","inference","(","e.g",".","input_spec","(",")",",","output_spec","(",")",",","and","predict","(",")",")",",","but","also","provides","a","train","(",")","method","to","run","fine-tuning",".","This","is","a","full-featured","implementation",",","which","includes","embeddings",",","attention",",","gradients",",","as","well","as","support","for","the","different","input","and","output","types","above",".","For","a","more","minimal","example",",","see","..","\/simple_tf2_demo.py","."]
docstr: Per-example postprocessing, on NumPy output.
docstr_tok: ["Per-example","postprocessing",",","on","NumPy","output","."]
code: def _postprocess(self, output: dict[str, Any]):
      """Per-example postprocessing, on NumPy output."""
      ntok = output.pop("ntok")
      output["tokens"] = self.tokenizer.convert_ids_to_tokens(
          output.pop("input_ids")[:ntok]
      )
  
      # Tokens for each segment, individually.
      slicer_a, slicer_b = self._segment_slicers(output["tokens"])
      output["tokens_" + self.config.text_a_name] = output["tokens"][
          slicer_a
      ]
      if self.config.text_b_name:
          output["tokens_" + self.config.text_b_name] = output[
              "tokens"
          ][slicer_b]
  
      # Embeddings for each segment, individually.
      if self.config.output_embeddings:
          output["input_embs_" + self.config.text_a_name] = output[
              "input_embs"
          ][slicer_a]
          if self.config.text_b_name:
              output["input_embs_" + self.config.text_b_name] = output[
                  "input_embs"
              ][slicer_b]
  
      # Gradients for each segment, individually.
      if self.config.compute_grads:
          # Gradients for the CLS token.
          output["cls_grad"] = output["input_emb_grad"][0]
          output["token_grad_" + self.config.text_a_name] = output[
              "input_emb_grad"
          ][slicer_a]
          if self.config.text_b_name:
              output["token_grad_" + self.config.text_b_name] = output[
                  "input_emb_grad"
              ][slicer_b]
  
          # TODO(b/294613507): remove output[self.config.label_name] once TCAV
          # is updated.
          if not self.is_regression:
              # Return the label corresponding to the class index used for gradients.
              output[self.config.label_name] = self.config.labels[
                  output[self.config.label_name]
              ]  # pytype: disable=container-type-mismatch
  
          # Remove "input_emb_grad" since it's not in the output spec.
          del output["input_emb_grad"]
  
      if not self.config.output_attention:
          return output
  
      # Process attention.
      for key in output:
          if not re.match(r"layer_(\d+)/attention", key):
              continue
          # Select only real tokens, since most of this matrix is padding.
          # <float32>[num_heads, max_seq_length, max_seq_length]
          # -> <float32>[num_heads, num_tokens, num_tokens]
          output[key] = output[key][:, :ntok, :ntok].transpose(
              (0, 2, 1)
          )
          # Make a copy of this array to avoid memory leaks, since NumPy otherwise
          # keeps a pointer around that prevents the source array from being GCed.
          output[key] = output[
              key
          ].copy()  # pytype: disable=attribute-error
  
      return output
  
imports: import os
  from collections.abc import Iterable, Sequence
  import re
  import threading
  from typing import Any, Optional
  import attr
  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 11 for calling the GlueModel obj's underlying member method code with example usage: obj._postprocess(output) and returns: output, output