# Quick Tour: "Train using Tensorflow" gives \`Dataset argument should be a datasets.Dataset\` error

**URL:** <https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657>\
**Category:** Beginners\
**Created:** [March 12, 2023, 10:47pm UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657 "2023-03-12T22:47:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeBethersonton](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@JoeBethersonton](https://discuss.huggingface.co/u/JoeBethersonton)\
**Post date:** [March 12, 2023, 10:47pm UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657/1 "2023-03-12T22:47:03Z")

</div>

The end of the 🤗Hugging Face [Quick Tour](https://huggingface.co/docs/transformers/quicktour) guide has a section on how to [Train with Tensorflow](https://huggingface.co/docs/transformers/quicktour#train-with-tensorflow). The code amounts to:

```auto
# Load a data set
from datasets import load_dataset
dataset = load_dataset("rotten_tomatoes")

# Load a classifier
from transformers import TFAutoModelForSequenceClassification
model = TFAutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")

# Load the corresponding tokenizer
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")

# Apply the tokenizer over the data set
def tokenize_dataset(dataset):
    return tokenizer(dataset["text"])

dataset = dataset.map(tokenize_dataset)

# Prepare the data set for use
tf_dataset = model.prepare_tf_dataset(
    dataset, batch_size=16, shuffle=True, tokenizer=tokenizer
)

from tensorflow.keras.optimizers import Adam

model.compile(optimizer=Adam(3e-5))
model.fit(dataset)

```

The final line - preparing the dataset:

```
tf_dataset = model.prepare_tf_dataset(dataset, ...

```

throws the error:

> TypeError: Dataset argument should be a datasets.Dataset!

## Research Effort

The only mention of this exception **anywhere** on the Internet is in the 🤗Hugging Face github source:

```
if not isinstance(dataset, datasets.Dataset):
    raise TypeError("Dataset argument should be a datasets.Dataset!")

```

So what am i doing wrong? Or, alternatively, what do i have to do differently.

# Bonus Chatter

I tried looking at the **TFAutoModelForSequenceClassification.from\_pretrained** documentation says that it will return a **TFDistilBertForSequenceClassification** class.

I wanted to try to figure out what kind of type that the method supports, but the documentation for **TFDistilBertForSequenceClassification** doesn’t include any documentation of the methods (e.g. no `compile`, `fit`, `prepare_tf_dataset`).

---

<div class="post-metadata">

**Author:** ![jeff1948](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/jeff1948/32/15322_2.png) [@jeff1948](https://discuss.huggingface.co/u/jeff1948)\
**Post date:** [April 11, 2023, 6:37pm UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657/2 "2023-04-11T18:37:14Z")

</div>

I got the same issue, do you figure it out the solution?

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](https://discuss.huggingface.co/u/mariosasko)\
**Post date:** [April 13, 2023, 2:18pm UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657/3 "2023-04-13T14:18:50Z")

</div>

Hi! To avoid this error, you need to pass a single split (a `Dataset` object) instead of all the splits at once (`DatasetDict`):

```python
tf_dataset = model.prepare_tf_dataset(
    dataset["train"], batch_size=16, shuffle=True, tokenizer=tokenizer
)

```

cc @Rocketknight1 for fixing this in the docs

---

<div class="post-metadata">

**Author:** ![Rocketknight1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rocketknight1/32/21055_2.png) [@Rocketknight1](https://discuss.huggingface.co/u/Rocketknight1)\
**Post date:** [April 24, 2023, 12:54pm UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657/4 "2023-04-24T12:54:55Z")

</div>

Sorry for the delay! Thanks for pointing this out - we’ve opened a PR to fix this in the docs now: [Fix TF example in quicktour by Rocketknight1 · Pull Request #22960 · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/pull/22960)

---

<div class="post-metadata">

**Author:** ![jonbirge](https://avatars.discourse-cdn.com/v4/letter/j/a4c791/32.png) [@jonbirge](https://discuss.huggingface.co/u/jonbirge)\
**Post date:** [May 29, 2023, 2:48am UTC](https://discuss.huggingface.co/t/quick-tour-train-using-tensorflow-gives-dataset-argument-should-be-a-datasets-dataset-error/33657/5 "2023-05-29T02:48:24Z")

</div>

The PyTorch version doesn’t work, either, giving a different error. Hopefully you can fix this one, too. It doesn’t inspire confidence when the “QuickStart” doesn’t actually work!
