0
I want to fine-tune the modern BERT and I have the following error. Please let me know how to overcome it.
I am using the modern greek bert from here nlpaueb/bert-base-greek-uncased-v1 · Hugging Face and the fine-tuning approach from here https://www.analyticsvidhya.com/blog/2020/07/transfer-learning-for-nlp-fine-tuning-bert-for-text-classification/.
Thus my code for the model is the following:
# Import the modern Greek BERT
tokenizer = AutoTokenizer.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")
bert = AutoModel.from_pretrained("nlpaueb/bert-base-greek-uncased-v1")

Then I am using the code from the previous link to train and evaluate the model
# set initial loss to infinite
best_valid_loss = float('inf')
epochs = 5

# empty lists to store training and validation loss of each epoch
train_losses = []
valid_losses = []

#for each epoch
for epoch in tqdm.tqdm(range(epochs)):
     
    print('\n Epoch {:} / {:}'.format(epoch + 1, epochs))
    
    #train model
    train_loss, _ = train()
    
    #evaluate model
    valid_loss, _ = evaluate()
    
    #save the best model
    if valid_loss < best_valid_loss:
        best_valid_loss = valid_loss
        torch.save(model.state_dict(), 'saved_weights.pt')
    
    # append training and validation loss
    train_losses.append(train_loss)
    valid_losses.append(valid_loss)
    
    print(f'\nTraining Loss: {train_loss:.3f}')
    print(f'Validation Loss: {valid_loss:.3f}')

and I have the following error
RuntimeError: weight tensor should be defined either for all 2 classes or no classes but got weight tensor of shape: [5]

Update: Full error