diff --git a/chapters/en/chapter2/3.mdx b/chapters/en/chapter2/3.mdx index cf6309eb1..c39e7a761 100644 --- a/chapters/en/chapter2/3.mdx +++ b/chapters/en/chapter2/3.mdx @@ -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) ```