Learning
Learning is handled by various classes :
The Learner is the main class that runs the full process
Listeners are used for validation or other monitoring tasks
Trainers that iterate over batches of data
Optimization deals with parameters (selecting, gradient descent, etc.)
Learner
The main class is the Learner task; when submitted to the scheduler,
returns a LearnerOutput
.
- XPM Taskxpmir.learning.learner.Learner(*, random, trainer, model, max_epochs, steps_per_epoch, use_fp16, optimizers, listeners, checkpoint_interval, device, hooks, use_pretasks)[source]
Bases:
Task
,EasyLogger
Submit type:
xpmir.learning.learner.LearnerOutput
Model Learner
The learner task is generic, and takes two main arguments: (1) the model defines the model (e.g. DRMM), and (2) the trainer defines how the model should be trained (e.g. pointwise, pairwise, etc.)
When submitted, it returns a dictionary based on the listeners
- random: xpmir.learning.base.Random
The random generator
- trainer: xpmir.learning.trainers.Trainer
Specifies how to train the model
- model: xpmir.learning.optim.Module
Defines the model to be learned. If multiple models are used, one can use MultipleModel.
- max_epochs: int = 1000
Maximum number of epochs
- steps_per_epoch: int = 128
Number of steps for one epoch (after each epoch results are logged)
- use_fp16: bool = False
Use mixed precision when training
- optimizers: List[xpmir.learning.optim.ParameterOptimizer]
The list of parameter optimizers
- listeners: List[xpmir.learning.learner.LearnerListener]
Listeners are in charge of handling the validation of the model, and saving the relevant checkpoints
- checkpoint_interval: int = 1
Number of epochs between each checkpoint
- logpath: Pathgenerated
The path to the tensorboard logs
- checkpointspath: Pathgenerated
The path to the checkpoints
- device: xpmir.learning.devices.Device = xpmir.learning.devices.Device.XPMValue()
The device(s) to be used for the model
- hooks: List[xpmir.context.Hook] = []
Global learning hooks
Initialization hooks
are called before and after the initialization of the trainer and listeners.
- use_pretasks: bool = False
Use deprected pre-tasks as the output
- namedtuple xpmir.learning.learner.LearnerOutput(listeners: Dict[str, Any], learned_model: ModuleLoader)[source]
Bases:
NamedTuple
- The data structure for the output of a learner. It contains a dictionary
where the key is the name of the listener and the value is the output of that listener
- Fields:
listeners (
Dict
[str
,Any
]) – Alias for field number 0learned_model (
ModuleLoader
) – Alias for field number 1
Trainers
Trainers are responsible for defining the the way to train a learnable scorer.
- XPM Configxpmir.learning.trainers.Trainer(*, hooks, model)[source]
Bases:
Config
,EasyLogger
Submit type:
xpmir.learning.trainers.Trainer
Generic trainer
- hooks: List[xpmir.learning.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
- model: xpmir.learning.optim.Module
If the model to optimize is different from the model passsed to Learn, this parameter can be used – initialization is still expected to be done at the learner level
- XPM Configxpmir.learning.trainers.multiple.MultipleTrainer(*, hooks, model, trainers)[source]
Bases:
Trainer
Submit type:
xpmir.learning.trainers.multiple.MultipleTrainer
This trainer can be used to combine various trainers
- hooks: List[xpmir.learning.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
- model: xpmir.learning.optim.Module
If the model to optimize is different from the model passsed to Learn, this parameter can be used – initialization is still expected to be done at the learner level
- trainers: Dict[str, xpmir.learning.trainers.Trainer]
The trainers
- XPM Configxpmir.letor.trainers.LossTrainer(*, hooks, model, batcher, sampler, batch_size)[source]
Bases:
Trainer
Submit type:
xpmir.letor.trainers.LossTrainer
Trainer based on a loss function
This trainer supposes that:
the sampler_iter is initialized – and is a serializable iterator over batches
- hooks: List[xpmir.learning.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
- model: xpmir.learning.optim.Module
If the model to optimize is different from the model passsed to Learn, this parameter can be used – initialization is still expected to be done at the learner level
- batcher: xpmir.learning.batchers.Batcher = xpmir.learning.batchers.Batcher.XPMValue()
How to batch samples together
- sampler: xpmir.learning.base.Sampler
The sampler to use
- batch_size: int = 16
Number of samples per batch
Listeners
Listeners can be used to monitor the learning process
- XPM Configxpmir.learning.learner.LearnerListener(*, id)[source]
Bases:
Config
Submit type:
Any
Hook for learner
Performs some operations after a learning epoch
- id: str
Unique ID to identify the listener (ignored for signature)
- XPM Configxpmir.learning.context.ValidationHook[source]
Bases:
Hook
Submit type:
xpmir.learning.context.ValidationHook
Base class for all the validation hooks