Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion chapters/en/chapter2/3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,17 @@ encoded_sequences = [
]
```

This is a list of encoded sequences: a list of lists. Tensors only accept rectangular shapes (think matrices). This "array" is already of rectangular shape, so converting it to a tensor is easy:
This is a list of encoded sequences: a list of lists. Tensors only accept rectangular shapes.
Because these lists have different lengths, we can **pad** the shorter ones with zeros so they all have the same size:

```py
import torch

encoded_sequences = [
[101, 1045, 1005, 2310, 2042, 3403, 2005, 1037, 17662, 12172, 2607, 2026, 2878, 2166, 1012, 102],
[101, 1045, 5223, 2023, 2061, 2172, 999, 102, 0, 0, 0, 0, 0, 0, 0, 0],
]

model_inputs = torch.tensor(encoded_sequences)
```

Expand Down
Loading