Thank you for your reply. I tried your suggestion and now get the first error message again:

samples = [tokenized_traindata[i] for i in range(8)]
batch = data_collator(samples)



ValueError                                Traceback (most recent call last)
~\miniconda3\envs\BERTnew\lib\site-packages\transformers\tokenization_utils_base.py in convert_to_tensors(self, tensor_type, prepend_batch_axis)
698                 if not is_tensor(value):
 → 699                     tensor = as_tensor(value)
700
ValueError: expected sequence of length 40 at dim 1 (got 47)
During handling of the above exception, another exception occurred:
ValueError                                Traceback (most recent call last)
 in 
----> 1 batch = data_collator(samples)
~\miniconda3\envs\BERTnew\lib\site-packages\transformers\data\data_collator.py in call(self, features)
283                 )
284
 → 285         features = self.tokenizer.pad(
286             features,
287             padding=self.padding,
~\miniconda3\envs\BERTnew\lib\site-packages\transformers\tokenization_utils_base.py in pad(self, encoded_inputs, padding, max_length, pad_to_multiple_of, return_attention_mask, return_tensors, verbose)
2678                 batch_outputs[key].append(value)
2679
 → 2680         return BatchEncoding(batch_outputs, tensor_type=return_tensors)
2681
2682     def create_token_type_ids_from_sequences(
~\miniconda3\envs\BERTnew\lib\site-packages\transformers\tokenization_utils_base.py in init(self, data, encoding, tensor_type, prepend_batch_axis, n_sequences)
202         self._n_sequences = n_sequences
203
 → 204         self.convert_to_tensors(tensor_type=tensor_type, prepend_batch_axis=prepend_batch_axis)
205
206     @property
~\miniconda3\envs\BERTnew\lib\site-packages\transformers\tokenization_utils_base.py in convert_to_tensors(self, tensor_type, prepend_batch_axis)
713                         “Please see if a fast version of this tokenizer is available to have this feature available.”
714                     )
 → 715                 raise ValueError(
716                     "Unable to create tensor, you should probably activate truncation and/or padding "
717                     “with ‘padding=True’ ‘truncation=True’ to have batched tensors with the same length.”
ValueError: Unable to create tensor, you should probably activate truncation and/or padding with ‘padding=True’ ‘truncation=True’ to have batched tensors with the same length.

Do you have any suggestions as to why this happens again? Thank you very much in advance for your response and time!