TypeError with Dataloader
i used a very large dataset for testing my model. to make the testing samples fast, I would like to construct a data loader. but I'm getting errors. I couldn't solve it for two days. Here is my code:

 PRE_TRAINED_MODEL_NAME = 'bert-base-cased'
 tokenizer = BertTokenizer.from_pretrained(PRE_TRAINED_MODEL_NAME)

 class GPReviewDataset(Dataset):
    def __init__(self, Paragraph, target, tokenizer, max_len):
       self.Paragraph = Paragraph
       self.target= target
       self.tokenizer = tokenizer
       self.max_len = max_len
    
    def __len__(self):
       return len(self.Paragraph)

    def __getitem__(self, item):
       Paragraph = str(self.Paragraph[item])
       target = self.target[item]
       encoding = self.tokenizer.encode_plus(
       Paragraph,
       add_special_tokens=True,
       max_length=self.max_len,
       return_token_type_ids=False,
       pad_to_max_length=True,
       return_attention_mask=True,
       return_tensors='pt',
       )
       return {
       'review_text': Paragraph,
       'input_ids': encoding['input_ids'].flatten(),
       'attention_mask': encoding['attention_mask'].flatten(),
       'targets': torch.tensor(target, dtype=torch.long)
       }


def create_data_loader(df, tokenizer, max_len, batch_size):
    ds = GPReviewDataset(
    Paragraph=df.Paragraph.to_numpy(),
    target=df.target.to_numpy(),
    tokenizer=tokenizer,
    max_len=max_len
    )
   return DataLoader(
     ds,
    batch_size=batch_size,
    num_workers=4
    )

 # Main function
 paragraph=['Image to PDF Converter. ', 'Test Test']
 target=['0','1']
 df = pd.DataFrame({'Paragraph': paragraph, 'target': target})


 MAX_LEN='512'
 BATCH_SIZE = 1
 train_data_loader1 = create_data_loader(df, tokenizer, MAX_LEN, BATCH_SIZE)
 for d in train_data_loader1:
      print(d)

When I iterate over the dataloader  I got this error:
  TypeError: Caught TypeError in DataLoader worker process 0.
  Original Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py&quot;, 
  line 178, in _worker_loop
   data = fetcher.fetch(index)
  File &quot;/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py&quot;, line 44, in fetch
  data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py&quot;, line 44, in &lt;listcomp&gt;
  data = [self.dataset[idx] for idx in possibly_batched_index]
  File &quot;&lt;ipython-input-3-c4f87a4dbb48&gt;&quot;, line 20, in __getitem__
  return_tensors='pt',
  File &quot;/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils.py&quot;, line 1069, in encode_plus
    return_special_tokens_mask=return_special_tokens_mask,
  File &quot;/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils.py&quot;, line 1365, in prepare_for_model
    if max_length and total_len &gt; max_length:
   TypeError: '&gt;' not supported between instances of 'int' and 'str'

Can anyone help me? and Also, Can you give tips on how I can test my model on a large dataset? I mean what the faster way to test my model on 3M samples of data is?

The error is as it stated
File &quot;/usr/local/lib/python3.7/dist-packages/transformers/tokenization_utils.py&quot;, line 1365, in prepare_for_model
    if max_length and total_len &gt; max_length:
   TypeError: '&gt;' not supported between instances of 'int' and 'str'

You should change your MAX_LEN from string to int:
# MAX_LEN='512'
MAX_LEN=512

