torchrecurrent.benchmarks.copy_memory#

torchrecurrent.benchmarks.copy_memory(seq_len, n_samples, num_classes=10, *, memory_length=10, return_dataloader=True, one_hot=False, generator=None, device=None, **dataloader_kwargs)[source]#

Generate the canonical copy-memory benchmark.

The first memory_length tokens are sampled from the content classes. They are followed by seq_len - 1 blank tokens, a delimiter, and another memory_length blanks. Targets are blank until the final segment, where they reproduce the initial tokens. This follows Arjovsky et al. (2016), Section 5.1 (https://proceedings.mlr.press/v48/arjovsky16.html).

Parameters:
  • seq_len – Time lag T in the paper. Must be positive. The complete sequence length is seq_len + 2 * memory_length.

  • n_samples – Number of independent sequences to generate.

  • num_classes – Alphabet size. The last two classes are reserved for the blank and delimiter tokens, respectively.

  • memory_length – Number of content tokens to remember.

  • return_dataloader – Return a data loader when true, otherwise tensors.

  • one_hot – Convert inputs to floating-point one-hot vectors so they can be passed directly to recurrent layers. Targets remain integer class indices suitable for torch.nn.CrossEntropyLoss.

  • generator – Optional random number generator used for reproducibility. Only forwarded to the returned data loader’s shuffling when it is a CPU generator; a non-CPU generator is still used for tensor generation but the loader falls back to its own seeding.

  • device – Device on which to create the tensors.

  • **dataloader_kwargs – Arguments passed to torch.utils.data.DataLoader.

Returns:

A data loader, or (inputs, targets) when return_dataloader=False. Integer inputs and targets have shape (n_samples, total_length). With one_hot=True, inputs have an additional final dimension of size num_classes.