You have to change your class labels to [0,1,2]. Check BertForSequenceClassification Index Error for more details.