tflite_model_maker.recommendation.Recommendation

Recommendation task class.

model_spec recommendation model spec.
model_dir str, path to export model checkpoints and summaries.
shuffle boolean, whether the training data should be shuffled.
max_history_length int, max history length as model input for inference.
learning_rate float, learning rate.
gradient_clip_norm float, clip threshold (<= 0 meaning no clip).

Methods

create

Loads data and train the model for recommendation.

Args
train_data Training data.
model_spec Specification for the model.
model_spec_options dict, additional options to creat a model.
model_dir str, path to export model checkpoints and summaries.
validation_data Validation data.
batch_size Batch size for training.
steps_per_epoch int, Number of step per epoch.
epochs int, Number of epochs for training.
learning_rate float, learning rate.
gradient_clip_norm float, clip threshold (<= 0 meaning no clip).
shuffle boolean, whether the training data should be shuffled.
do_train boolean, whether to run training.
max_history_length int, max history length as model input (for inference).

Returns
An instance based on Recommendation.

create_model

Creates a model.

Args
do_train boolean. Whether to train the model.

Returns
Keras model.

create_serving_model

Returns the underlining Keras model for serving.

evaluate

Evaluate the model.

Args
data Evaluation data.
batch_size int, batch size for evaluation.

Returns
History from model.evaluate().

evaluate_tflite

Evaluates the tflite model.

The data is padded to required length, and multiple metrics are evaluated.

Args
tflite_filepath File path to the TFLite model.
data Data to be evaluated.

Returns
Dict of (metric, value), evaluation result of TFLite model.

export

Converts the retrained model based on export_format.

Args
export_dir The directory to save exported files.
tflite_filename File name to save tflite model. The full export path is {export_dir}/{tflite_filename}.
label_filename File name to save labels. The full export path is {export_dir}/{label_filename}.
vocab_filename File name to save vocabulary. The full export path is {export_dir}/{vocab_filename}.
saved_model_filename Path to SavedModel or H5 file to save the model. The full export path is {export_dir}/{saved_model_filename}/{saved_model.pb|assets|variables}.
tfjs_folder_name Folder name to save tfjs model. The full export path is {export_dir}/{tfjs_folder_name}.
export_format List of export format that could be saved_model, tflite, label, vocab.
**kwargs Other parameters like quantized for TFLITE model.

summary

train

Feeds the training data for training.

Args
train_data Training dataset.
validation_data Validation data. If None, skips validation process.
batch_size int, the batch size.
steps_per_epoch int, the step of each epoch.
epochs int, number of epochs.

Returns
History from model.fit().

ALLOWED_EXPORT_FORMAT (<ExportFormat.LABEL: 'LABEL'>, <ExportFormat.TFLITE: 'TFLITE'>, <ExportFormat.SAVED_MODEL: 'SAVED_MODEL'>)
DEFAULT_EXPORT_FORMAT (<ExportFormat.TFLITE: 'TFLITE'>,)
OOV_ID 0