Skip to content
← Learn PyTorch

Batching and the Data Path

PyTorch

Assemble batches with stack, cat, padding and masks. Write collation logic and make shuffling reproducible while preserving the intended shapes.

5 exercises

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Adding an axis, or extending one Practice · Easy
  2. 2 Not solved yet. Pad, and then say where you padded Practice · Medium
  3. 3 Not solved yet. Weight batch losses by the number of examples Practice · Medium
  4. 4 Not solved yet. Split without copying Practice · Easy
  5. 5 Not solved yet. Shuffle the same way twice Practice · Medium

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

What does setting num_workers=2 change in this DataLoader?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

from torch.utils.data import DataLoader

# Run as a script; the guard supports platforms that spawn worker processes.
if __name__ == "__main__":
    loader = DataLoader(list(range(6)), batch_size=2, num_workers=2)
    print([batch.tolist() for batch in loader])
Question 1 of 4