BertForSequenceClassification.forward() got an unexpected keyword argument 'length'

#540
by tusharagashe - opened

I am currently finetuning a model for cell classification. When running the validate() method with my input data I get this error during the trainer.train() step:

TypeError: BertForSequenceClassification.forward() got an unexpected keyword argument 'length'

Now initially to work around this I removed the length column from my data before training but then it is needed in the evaluation steps later and I get new errors during that portion of the code (during evaluate_model() in classifier.py). Wondering if I am just setting up my dataset wrong or is there something that needs to be changed in how I am calling the functions? I can provide more information if this isn't trivial. Here is my dataset_info.json:

Screenshot 2025-06-15 at 8.10.39 PM.png

Also to avoid the issue in discussion #528 I have downgraded to transformers==4.46 and am using the latest version of the Geneformer codebase. Appreciate any help and insight on this!

Thank you for your question! Could you provide the error that you get with the evaluation if you don't have the length column? Also it would be helpful to share what code you are running (how you've set up the classifier) and the full error traceback.

In the process of trying to answer your questions I figured out what I was doing wrong. I was incorrectly setting this parameter in TrainingArguments 'remove_unused_columns=False'. By default it is True and thus doesn't result in this error when it isn't included or set to True. My fine-tuning is working as intended now. Thanks!

Thank you for following up with the solution!

ctheodoris changed discussion status to closed

Sign up or log in to comment