Trainers

Trainers are responsible for defining the the way to train a learnable scorer.

XPM Configxpmir.letor.trainers.Trainer(*, hooks)

Bases: experimaestro.core.objects.Config, xpmir.utils.EasyLogger

Generic trainer

hooks: List[xpmir.letor.context.TrainingHook] = []

Hooks for this trainer: this includes the losses, but can be adapted for other uses The specific list of hooks depends on the specific trainer

XPM Configxpmir.letor.trainers.LossTrainer(*, hooks, batcher, sampler, batch_size)

Bases: xpmir.letor.trainers.Trainer

Trainer based on a loss function

hooks: List[xpmir.letor.context.TrainingHook] = []

Hooks for this trainer: this includes the losses, but can be adapted for other uses The specific list of hooks depends on the specific trainer

batcher: xpmir.letor.batchers.Batcher = xpmir.letor.batchers.Batcher()

How to batch samples together

sampler: xpmir.letor.samplers.Sampler

The sampler to use

batch_size: int = 16

Number of samples per batch (the notion of sample depends on the sampler)

process_microbatch(records: xpmir.letor.records.BaseRecords)

Combines a forward and backard

This method can be implemented by specific trainers that use the gradient. In that case the regularizer losses should be taken into account with self.add_losses.

XPM Configxpmir.letor.trainers.pointwise.PointwiseTrainer(*, hooks, batcher, sampler, batch_size, lossfn)

Bases: xpmir.letor.trainers.LossTrainer

Pointwise trainer

hooks: List[xpmir.letor.context.TrainingHook] = []

Hooks for this trainer: this includes the losses, but can be adapted for other uses The specific list of hooks depends on the specific trainer

batcher: xpmir.letor.batchers.Batcher = xpmir.letor.batchers.Batcher()

How to batch samples together

sampler: xpmir.letor.samplers.Sampler

The sampler to use

batch_size: int = 16

Number of samples per batch (the notion of sample depends on the sampler)

lossfn: xpmir.letor.trainers.pointwise.PointwiseLoss = xpmir.letor.trainers.pointwise.MSELoss(weight=1.0)

Loss function to use (mse, mse-nil, l1, l1pos, smoothl1, cross_entropy, cross_entropy_logits, softmax, mean)

Pointwise

Trainer

XPM Configxpmir.letor.trainers.pointwise.PointwiseTrainer(*, hooks, batcher, sampler, batch_size, lossfn)

Bases: xpmir.letor.trainers.LossTrainer

Pointwise trainer

hooks: List[xpmir.letor.context.TrainingHook] = []

Hooks for this trainer: this includes the losses, but can be adapted for other uses The specific list of hooks depends on the specific trainer

batcher: xpmir.letor.batchers.Batcher = xpmir.letor.batchers.Batcher()

How to batch samples together

sampler: xpmir.letor.samplers.Sampler

The sampler to use

batch_size: int = 16

Number of samples per batch (the notion of sample depends on the sampler)

lossfn: xpmir.letor.trainers.pointwise.PointwiseLoss = xpmir.letor.trainers.pointwise.MSELoss(weight=1.0)

Loss function to use (mse, mse-nil, l1, l1pos, smoothl1, cross_entropy, cross_entropy_logits, softmax, mean)

Losses

XPM Configxpmir.letor.trainers.pointwise.PointwiseLoss(*, weight)

Bases: experimaestro.core.objects.Config

weight: float = 1.0
XPM Configxpmir.letor.trainers.pointwise.MSELoss(*, weight)

Bases: xpmir.letor.trainers.pointwise.PointwiseLoss

weight: float = 1.0
XPM Configxpmir.letor.trainers.pointwise.BinaryCrossEntropyLoss(*, weight)

Bases: xpmir.letor.trainers.pointwise.PointwiseLoss

Computes binary cross-entropy

Uses a BCE with logits if the scorer output type is not a probability

weight: float = 1.0

Pairwise

Trainer

XPM Configxpmir.letor.trainers.pairwise.PairwiseTrainer(*, hooks, batcher, sampler, batch_size, lossfn)

Bases: xpmir.letor.trainers.LossTrainer

Pairwise trainer uses samples of the form (query, positive, negative)

hooks: List[xpmir.letor.context.TrainingHook] = []

Hooks for this trainer: this includes the losses, but can be adapted for other uses The specific list of hooks depends on the specific trainer

batcher: xpmir.letor.batchers.Batcher = xpmir.letor.batchers.Batcher()

How to batch samples together

sampler: xpmir.letor.samplers.PairwiseSampler

The pairwise sampler

batch_size: int = 16

Number of samples per batch (the notion of sample depends on the sampler)

lossfn: xpmir.letor.trainers.pairwise.PairwiseLoss

The loss function

Losses

XPM Configxpmir.letor.trainers.pairwise.PairwiseLoss(*, weight)

Bases: experimaestro.core.objects.Config, TorchModule

weight: float = 1.0
XPM Configxpmir.letor.trainers.pairwise.CrossEntropyLoss(*, weight)

Bases: xpmir.letor.trainers.pairwise.PairwiseLoss

weight: float = 1.0
XPM Configxpmir.letor.trainers.pairwise.SoftmaxLoss(*, weight)

Bases: xpmir.letor.trainers.pairwise.PairwiseLoss

Contrastive loss

weight: float = 1.0
XPM Configxpmir.letor.trainers.pairwise.LogSoftmaxLoss(*, weight)

Bases: xpmir.letor.trainers.pairwise.PairwiseLoss

RankNet loss or log-softmax loss

Classification loss (relevant vs non-relevant) where the logit is equal to the difference between the relevant and the non relevant document (or equivalently, softmax then mean log probability of relevant documents)

Reference: C. Burges et al., “Learning to rank using gradient descent,” 2005.

weight: float = 1.0
XPM Configxpmir.letor.trainers.pairwise.HingeLoss(*, weight, margin)

Bases: xpmir.letor.trainers.pairwise.PairwiseLoss

weight: float = 1.0
margin: float = 1.0