finetuner.tuner.base module

class finetuner.tuner.base.BaseLoss(*args, **kwds)[source]

Bases: Generic[finetuner.helper.AnyTensor]

distance: str
miner: Optional[finetuner.tuner.miner.base.BaseMiner]

Base loss class.

The subclasses should, in addition to implementing the abstract methods defined here, also implement the framework-specific “forward” method, where they need to first use the miner to mine indices, and then output the loss by running compute on embeddings and outputs of the miner.

abstract compute(embeddings, indices)[source]

Compute the loss using embeddings and indices that the miner outputs

Return type

~AnyTensor

abstract get_default_miner(is_session_dataset)[source]

Get the default miner for this loss, given the dataset type

Return type

BaseMiner

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

Bases: abc.ABC, Generic[finetuner.helper.AnyDNN, finetuner.helper.AnyDataLoader, finetuner.helper.AnyOptimizer]

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

property embed_model: finetuner.helper.AnyDNN

Get the base model of this object.

Return type

~AnyDNN

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

Fit the embed_model on labeled data.

Note that fitting changes the weights in embed_model in-place. This allows one to consecutively call fit() multiple times with different configs or data to get better models.

Return type

Summary

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

Save the weights of the embed_model.