allennlp.data.dataloader#

DataLoader#

DataLoader(
    self,
    dataset: torch.utils.data.dataset.Dataset,
    batch_size: int = 1,
    shuffle: bool = False,
    sampler: allennlp.data.samplers.samplers.Sampler = None,
    batch_sampler: allennlp.data.samplers.samplers.BatchSampler = None,
    num_workers: int = 0,
    collate_fn = <function allennlp_collate at 0x7f432421ec80>,
    pin_memory: bool = False,
    drop_last: bool = False,
    timeout: int = 0,
    worker_init_fn = None,
    multiprocessing_context: str = None,
)

A registrable version of the pytorch DataLoader. The only reason this class exists is so that we can construct a DataLoader from a configuration file and have a different default collate_fn. You can use this class directly in python code, but it is identical to using pytorch dataloader with allennlp's custom collate function:

from torch.utils.data import DataLoader

from allennlp.data.samplers import allennlp_collate
# Construct a dataloader directly for a dataset which contains allennlp
# Instances which have _already_ been indexed.
my_loader = DataLoader(dataset, batch_size=32, collate_fn=allennlp_collate)

default_implementation#

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.