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
14 changes: 11 additions & 3 deletions chapters/en/chapter2/3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,20 @@ 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 (think matrices). Since these sequences have different lengths, they must be padded before they can be converted into a tensor.


```py
import torch
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")

model_inputs = tokenizer(
sequences,
padding=True,
return_tensors="pt"
)["input_ids"]

model_inputs = torch.tensor(encoded_sequences)
```

### Using the tensors as inputs to the model[[using-the-tensors-as-inputs-to-the-model]]
Expand Down
Loading