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: Run fine-tuning.
docstr_tok: ["Run","fine-tuning","."]
code: def train(
      self,
      train_inputs: list[JsonDict],
      validation_inputs: list[JsonDict],
      learning_rate=2e-5,
      batch_size=32,
      num_epochs=3,
      keras_callbacks=None,
  ):
      """Run fine-tuning."""
      train_dataset = (
          self._make_dataset(train_inputs)
          .shuffle(128)
          .batch(batch_size)
          .repeat(-1)
      )
      # Use larger batch for validation since inference is about 1/2 memory usage
      # of backprop.
      eval_batch_size = 2 * batch_size
      validation_dataset = self._make_dataset(validation_inputs).batch(
          eval_batch_size
      )
  
      # Prepare model for training.
      opt = tf.keras.optimizers.Adam(
          learning_rate=learning_rate, epsilon=1e-08
      )
      if self.is_regression:
          loss = tf.keras.losses.MeanSquaredError()
          metric = tf.keras.metrics.RootMeanSquaredError("rmse")
      else:
          loss = tf.keras.losses.SparseCategoricalCrossentropy(
              from_logits=True
          )
          metric = tf.keras.metrics.SparseCategoricalAccuracy(
              "accuracy"
          )
      self.model.compile(optimizer=opt, loss=loss, metrics=[metric])
  
      steps_per_epoch = len(train_inputs) // batch_size
      validation_steps = len(validation_inputs) // eval_batch_size
      history = self.model.fit(
          train_dataset,
          epochs=num_epochs,
          steps_per_epoch=steps_per_epoch,
          validation_data=validation_dataset,
          validation_steps=validation_steps,
          callbacks=keras_callbacks,
          verbose=2,
      )
      return history
  
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 8 for calling the GlueModel obj's underlying member method code with example usage: obj.train(train_inputs, validation_inputs, learning_rate, batch_size, num_epochs, keras_callbacks) and returns: history