finetuner.tuner.keras package

Submodules

Module contents

class finetuner.tuner.keras.KerasTuner(embed_model=None, loss='SiameseLoss', **kwargs)[source]

Bases: finetuner.tuner.base.BaseTuner[tensorflow.keras.layers.Layer, keras.engine.data_adapter.KerasSequenceAdapter, tensorflow.keras.optimizers.Optimizer]

Create the tuner instance.

Parameters
  • embed_model (Optional[~AnyDNN]) – Model that produces embeddings from inputs

  • loss (Union[BaseLoss, str]) – Either the loss object instance, or the name of the loss function. Currently available losses are SiameseLoss and TripletLoss

fit(train_data, eval_data=None, epochs=10, batch_size=256, num_items_per_class=None, optimizer=None, learning_rate=0.001, device='cpu', preprocess_fn=None, collate_fn=None, **kwargs)[source]

Finetune the model on the training data.

Parameters
  • train_data (DocumentSequence) – Data on which to train the model

  • eval_data (Optional[ForwardRef]) – Data on which to evaluate the model at the end of each epoch

  • preprocess_fn (Optional[ForwardRef]) – A pre-processing function. It should take as input the content of an item in the dataset and return the pre-processed content

  • collate_fn (Optional[ForwardRef]) – The collation function to merge the content of individual items into a batch. Should accept a list with the content of each item, and output a tensor (or a list/dict of tensors) that feed directly into the embedding model

  • epochs (int) – Number of epochs to train the model

  • batch_size (int) – The batch size to use for training and evaluation

  • num_items_per_class (Optional[int]) – Number of items from a single class to include in the batch. Only relevant for class datasets

  • optimizer (Optional[Optimizer]) – The optimizer to use for training. If none is passed, an Adam optimizer is used by default, with learning rate specified by the learning_rate parameter.

  • learning_rate (float) – Learning rate for the default optimizer. If you provide a custom optimizer, this learning rate will not apply.

  • device (str) – The device to which to move the model. Supported options are "cpu" and "cuda" (for GPU)

Return type

Summary

save(*args, **kwargs)[source]

Save the embedding model.

You need to pass the path where to save the model in either args or kwargs (for filepath key).

Parameters
  • args – Arguments to pass to save method of the embedding model

  • kwargs – Keyword arguments to pass to save method of the embedding model

finetuner.tuner.keras.get_device(device)[source]

Get tensorflow compute device.

Parameters

device (str) – device name