A specification of BERT model for text classification.

uri TF-Hub path/url to Bert module.
model_dir The location of the model checkpoint files.
seq_len Length of the sequence to feed into the model.
dropout_rate The rate for dropout.
initializer_range The stdev of the truncated_normal_initializer for initializing all weight matrices.
learning_rate The initial learning rate for Adam.
distribution_strategy A string specifying which distribution strategy to use. Accepted values are 'off', 'one_device', 'mirrored', 'parameter_server', 'multi_worker_mirrored', and 'tpu' -- case insensitive. 'off' means not to use Distribution Strategy; 'tpu' means to use TPUStrategy using tpu_address.
num_gpus How many GPUs to use at each worker with the DistributionStrategies API. The default is -1, which means utilize all available GPUs.
tpu TPU address to connect to.
trainable boolean, whether pretrain layer is trainable.
do_lower_case boolean, whether to lower case the input text. Should be True for uncased models and False for cased models.
is_tf2 boolean, whether the hub module is in TensorFlow 2.x format.
name The name of the object.
tflite_input_name Dict, input names for the TFLite model.
default_batch_size Default batch size for training.
index_to_label List of labels in the training data. e.g. ['neg', 'pos'].



View source

Builds the class. Used for lazy initialization.


View source

Converts examples to features and write them into TFRecord file.


View source

Creates the keras model.


View source

Gets the configuration.


View source

Gets the default quantization configuration.


View source

Gets the dictionary describing the features.


View source

Reorders the tflite input details to map the order of keras model.


View source

Creates classifier and runs the classifier training.

train_ds, training data to be fed in
validation_ds, validation data to be fed in
epochs Integer, training epochs.
steps_per_epoch Integer or None. Total number of steps (batches of samples) before declaring one epoch finished and starting the next epoch. If steps_per_epoch is None, the epoch will run until the input dataset is exhausted.
num_classes Interger, number of classes.
**kwargs Other parameters used in the

tf.keras.Model, the keras model that's already trained.


View source

Prints the file path to the vocabulary.


View source

Dispatches records to features and labels.

compat_tf_versions [2]
convert_from_saved_model_tf2 True
need_gen_vocab False