nlp-with-transformers / notebooks

Jupyter notebooks for the Natural Language Processing with Transformers book
https://transformersbook.com/
Apache License 2.0
3.91k stars 1.22k forks source link

Chap 3: Fault about TransformerForSequenceClassification #144

Open S3nnyK opened 3 months ago

S3nnyK commented 3 months ago

Information

The question or comment is about chapter:

Question or comment

In TransformerForSequenceClassification, x = self.encoder(x)[:, 0, :] means [CLS] token is included in the inputs. However, in the beginning of this chapter, inputs is defined as tokenizer(text, return_tensors="pt", add_special_tokens=False), without special_tokens. Hence, the 0-th is "time", not "[CLS]".