You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapters/en/chapter3/3.mdx
+4-4
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ model = AutoModelForSequenceClassification.from_pretrained(checkpoint, num_label
58
58
59
59
You will notice that unlike in [Chapter 2](/course/chapter2), you get a warning after instantiating this pretrained model. This is because BERT has not been pretrained on classifying pairs of sentences, so the head of the pretrained model has been discarded and a new head suitable for sequence classification has been added instead. The warnings indicate that some weights were not used (the ones corresponding to the dropped pretraining head) and that some others were randomly initialized (the ones for the new head). It concludes by encouraging you to train the model, which is exactly what we are going to do now.
60
60
61
-
Once we have our model, we can define a `Trainer` by passing it all the objects constructed up to now — the `model`, the `training_args`, the training and validation datasets, our `data_collator`, and our `tokenizer`:
61
+
Once we have our model, we can define a `Trainer` by passing it all the objects constructed up to now — the `model`, the `training_args`, the training and validation datasets, our `data_collator`, and our `processing_class` (e.g., a tokenizer, feature extractor, or processor):
62
62
63
63
```py
64
64
from transformers import Trainer
@@ -69,11 +69,11 @@ trainer = Trainer(
69
69
train_dataset=tokenized_datasets["train"],
70
70
eval_dataset=tokenized_datasets["validation"],
71
71
data_collator=data_collator,
72
-
tokenizer=tokenizer,
72
+
processing_class=tokenizer,
73
73
)
74
74
```
75
75
76
-
Note that when you pass the `tokenizer` as we did here, the default `data_collator` used by the `Trainer` will be a `DataCollatorWithPadding`as defined previously, so you can skip the line `data_collator=data_collator` in this call. It was still important to show you this part of the processing in section 2!
76
+
Note that when you pass a tokenizer as the `processing_class`, as we did here, the default `data_collator` used by the `Trainer` will be a `DataCollatorWithPadding`if the `processing_class` is a tokenizer or feature extractor, so you can skip the line `data_collator=data_collator` in this call. It was still important to show you this part of the processing in section 2!
77
77
78
78
To fine-tune the model on our dataset, we just have to call the `train()` method of our `Trainer`:
0 commit comments