This error occurs when DataCollator is unable to collate the data as expected. There are multiple possible solutions, but I think the smartest thing to do would be to either use an existing DataCollator or write a new one.
Alternatively, you could leave tokenization entirely to the Trainer, but that would mean a significant change to the current code, so I’m not sure what to do in that case…