# DataCollatorWithPadding: TypeError

**URL:** <https://discuss.huggingface.co/t/datacollatorwithpadding-typeerror/12093>\
**Category:** Course\
**Created:** [November 20, 2021, 7:17am UTC](https://discuss.huggingface.co/t/datacollatorwithpadding-typeerror/12093 "2021-11-20T07:17:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajkumar](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rajkumar/32/3072_2.png) [@rajkumar](https://discuss.huggingface.co/u/rajkumar)\
**Post date:** [November 20, 2021, 7:17am UTC](https://discuss.huggingface.co/t/datacollatorwithpadding-typeerror/12093/1 "2021-11-20T07:17:37Z")

</div>

Hi,  
I am following the course. I am now at Fine-tuning [Fine-tuning a pretrained model - Hugging Face Course](https://huggingface.co/course/chapter3/3?fw=tf). When I set up `DataCollatorWithPadding` as following I got an error while trying to reproduce the course code in Kaggle. This error occurs with either a CPU-only-device or a GPU-device.

Input:  
`checkpoint = 'bert-base-uncased' tokenizer = AutoTokenizer.from_pretrained(checkpoint) data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors="tf")`

Output:  
`---------------------------------------------------------------------------  
TypeError Traceback (most recent call last)  
/tmp/ipykernel\_42/1563280798.py in   
1 checkpoint = ‘bert-base-uncased’  
2 tokenizer = AutoTokenizer.from\_pretrained(checkpoint)  
----\> 3 data\_collator = DataCollatorWithPadding(tokenizer=tokenizer, return\_tensors=“pt”)

TypeError: **init** () got an unexpected keyword argument ‘return\_tensors’`

When I call `help` method, it too confirms that there is no argument `return_tensors`.  
Input:  
`help(DataCollatorWithPadding. __init__ )`  
Output:  
`Help on function **init** in module transformers.data.data\_collator:

**init** (self, tokenizer: transformers.tokenization\_utils\_base.PreTrainedTokenizerBase, padding: Union[bool, str, transformers.file\_utils.PaddingStrategy] = True, max\_length: Union[int, NoneType] = None, pad\_to\_multiple\_of: Union[int, NoneType] = None) → None`

But, the source file [Data Collator — transformers 4.12.5 documentation](https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorwithpadding) says that there is such an argument. By default, it returns Pytorch tensors while I need TF tensors.

Where do I miss?  
Please help me.

---

<div class="post-metadata">

**Author:** ![rajkumar](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rajkumar/32/3072_2.png) [@rajkumar](https://discuss.huggingface.co/u/rajkumar)\
**Post date:** [November 21, 2021, 6:56am UTC](https://discuss.huggingface.co/t/datacollatorwithpadding-typeerror/12093/2 "2021-11-21T06:56:25Z")

</div>

Hi all, this issue is due to the older version of transformers library. When I upgraded it, problems are resolved.

```auto
# upgrade transformers and datasets to latest versions
!pip install --upgrade transformers
!pip install --upgrade datasets

```

Best Regards.
