# DataCollatorWithPadding: TypeError

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatacollatorwithpadding-typeerror%2F12093%3E%5C
**Category:** Course\
**Created:** [November 20, 2021, 7:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatacollatorwithpadding-typeerror%2F12093 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frajkumar)%5C
**Post date:** [November 20, 2021, 7:17am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatacollatorwithpadding-typeerror%2F12093%2F1 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Frajkumar)%5C
**Post date:** [November 21, 2021, 6:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdatacollatorwithpadding-typeerror%2F12093%2F2 "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.
