# Error in model.prepare\_tf\_dataset

**URL:** <https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825>\
**Category:** Beginners\
**Created:** [May 27, 2024, 6:06pm UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825 "2024-05-27T18:06:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavithra-devi](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pavithra-devi](https://discuss.huggingface.co/u/pavithra-devi)\
**Post date:** [May 27, 2024, 6:06pm UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825/1 "2024-05-27T18:06:59Z")

</div>

I used the following model for summarization task,

```auto
from transformers import AutoTokenizer, TFAutoModelForSeq2SeqLM

model_checkpoint = "google/mt5-small"
# model_checkpoint = "google/pegasus-cnn_dailymail"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = TFAutoModelForSeq2SeqLM.from_pretrained(model_checkpoint, from_pt=True)

```

tokenization is done and my data has these columns

```auto
DatasetDict({
    train: Dataset({
        features: ['input_ids', 'attention_mask', 'labels'],
        num_rows: 1000
    })
    validation: Dataset({
        features: ['input_ids', 'attention_mask', 'labels'],
        num_rows: 1000
    })
})

```

data collator function returns somehting like this

```auto
from transformers import DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model, return_tensors="tf")
features = [tokenized_data["train"][i] for i in range(2)]
data_collator(features)

{'input_ids': <tf.Tensor: shape=(2, 900), dtype=int32, numpy=
array([[5139, 259, 15241, ..., 0, 0, 0],
       [259, 23129, 259, ..., 2454, 2841, 1]], dtype=int32)>, 'attention_mask': <tf.Tensor: shape=(2, 900), dtype=int32, numpy=
array([[1, 1, 1, ..., 0, 0, 0],
       [1, 1, 1, ..., 1, 1, 1]], dtype=int32)>, 'labels': <tf.Tensor: shape=(2, 124), dtype=int64, numpy=
array([[ 322, 486, 335, 59128, 12733, 331, 102270, 288,

```

prepare\_tf\_dataset gives the error

```auto
tf_train_dataset = model.prepare_tf_dataset(
    tokenized_data["train"],
    collate_fn=data_collator,
    shuffle=True,
    batch_size=8,
)

TypeError: Cannot convert [array([3.22000e+02, 2.98000e+02, 3.82260e+04, 1.86600e+03, 5.69000e+02,])] to EagerTensor of dtype int64

```

please help i am stuck here,

---

<div class="post-metadata">

**Author:** ![sibiakash](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sibiakash](https://discuss.huggingface.co/u/sibiakash)\
**Post date:** [June 14, 2024, 6:00am UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825/2 "2024-06-14T06:00:07Z")

</div>

the same is happening to me , found a fix?

---

<div class="post-metadata">

**Author:** ![pavithra-devi](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pavithra-devi](https://discuss.huggingface.co/u/pavithra-devi)\
**Post date:** [June 14, 2024, 6:28am UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825/3 "2024-06-14T06:28:16Z")

</div>

Yep i fixed it and my MR got merged.

---

<div class="post-metadata">

**Author:** ![sibiakash](https://avatars.discourse-cdn.com/v4/letter/s/87869e/32.png) [@sibiakash](https://discuss.huggingface.co/u/sibiakash)\
**Post date:** [June 14, 2024, 6:42am UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825/4 "2024-06-14T06:42:11Z")

</div>

can you pls share MR link?

---

<div class="post-metadata">

**Author:** ![pavithra-devi](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@pavithra-devi](https://discuss.huggingface.co/u/pavithra-devi)\
**Post date:** [June 14, 2024, 5:28pm UTC](https://discuss.huggingface.co/t/error-in-model-prepare-tf-dataset/88825/5 "2024-06-14T17:28:37Z")

</div>

[https://github.com/huggingface/transformers/pull/31109](https://github.com/huggingface/transformers/pull/31109)
