Skip to content

Latest commit

 

History

History
61 lines (42 loc) · 1.36 KB

tasks.rst

File metadata and controls

61 lines (42 loc) · 1.36 KB
.. module:: fairseq.tasks

Tasks

Tasks store dictionaries and provide helpers for loading/iterating over Datasets, initializing the Model/Criterion and calculating the loss.

Tasks can be selected via the --task command-line argument. Once selected, a task may expose additional command-line arguments for further configuration.

Example usage:

# setup the task (e.g., load dictionaries)
task = fairseq.tasks.setup_task(args)

# build model and criterion
model = task.build_model(args)
criterion = task.build_criterion(args)

# load datasets
task.load_dataset('train')
task.load_dataset('valid')

# iterate over mini-batches of data
batch_itr = task.get_batch_iterator(
    task.dataset('train'), max_tokens=4096,
)
for batch in batch_itr:
    # compute the loss
    loss, sample_size, logging_output = task.get_loss(
        model, criterion, batch,
    )
    loss.backward()

Translation

.. autoclass:: fairseq.tasks.translation.TranslationTask

Language Modeling

.. autoclass:: fairseq.tasks.language_modeling.LanguageModelingTask


Adding new tasks

.. autofunction:: fairseq.tasks.register_task
.. autoclass:: fairseq.tasks.FairseqTask
    :members:
    :undoc-members: