data_collator error: AttributeError: 'dict' object has no attribute 'size'
Author: gungor2
Pull request: no
Labels: name: wontfix

# ❓ Questions & Help

<!-- The GitHub issue tracker is primarly intended for bugs, feature requests,
     new models and benchmarks, and migration questions. For all other questions,
     we direct you to the Hugging Face forum: https://discuss.huggingface.co/ .
     You can also try Stack Overflow (SO) where a whole community of PyTorch and
     Tensorflow enthusiast can help you out. In this case, make sure to tag your
     question with the right deep learning framework as well as the
     huggingface-transformers tag: 
     https://stackoverflow.com/questions/tagged/huggingface-transformers 
     -->

## Details
<!-- Description of your issue -->

<!-- You should first ask your question on the forum or SO, and only if
     you didn't get an answer ask it here on GitHub. -->
**A link to original question on the forum/Stack Overflow**:

I am trying to run a language model that is very similar to the [tutorial ](https://huggingface.co/blog/how-to-train). I have a custom dataset class that returns a dict with fields: dict_keys(['input_ids', 'token_type_ids', 'attention_mask']). When I run the training I get this error message:
```  File "prod2vec/train-from-scratch.py", line 289, in <module>
    sys.exit(main())
  File "prod2vec/train-from-scratch.py", line 265, in main
    trainer.train(model_path=model_path)
  File "/usr/local/lib/python3.6/site-packages/transformers/trainer.py", line 456, in train
    for step, inputs in enumerate(epoch_iterator):
  File "/usr/local/lib/python3.6/site-packages/tqdm/std.py", line 1127, in __iter__
    for obj in iterable:
  File "/usr/local/lib64/python3.6/site-packages/torch/utils/data/dataloader.py", line 345, in __next__
    data = self._next_data()
  File "/usr/local/lib64/python3.6/site-packages/torch/utils/data/dataloader.py", line 385, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/usr/local/lib64/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 35, in fetch
    return self.collate_fn(data)
  File "/usr/local/lib/python3.6/site-packages/transformers/data/data_collator.py", line 79, in __call__
    batch = self._tensorize_batch(examples)
  File "/usr/local/lib/python3.6/site-packages/transformers/data/data_collator.py", line 91, in _tensorize_batch
    length_of_first = examples[0].size(0)
AttributeError: 'dict' object has no attribute 'size'
```

The error message is not surprising as examples[0] is a dictionary with previously mentioned three fields. I am curious what and where i am doing a mistake.


Comments:
It looks like you're not using the latest version of transformers (from the stack trace). This bug as been fixed, so you shouldn't have the problems with transformers 3.1.1.
In general, when reporting a bug/asking a question, make sure you include your version of transformers so we can help more efficiently. You can get it by running the command `transformers-cli env` and pasting the results.

I will add the version from now on. Your suggestion worked, thanks a lot!

i use the transformer 3.4.0, and met the same error

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.