finetuner.tuner.paddle package


Module contents

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

Bases: finetuner.tuner.base.BaseTuner[paddle.nn.Layer,, paddle.optimizer.Optimizer]

Create the tuner instance.

  • 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.

  • 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

  • learning_rate (float) – Learning rate to use in training

  • 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 – 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


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 path key).

  • args – Arguments to pass to function

  • kwargs – Keyword arguments to pass to function


Get Paddle compute device.


device (str) – device name