# Dataset expected by Trainer

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdataset-expected-by-trainer%2F148%3E%5C
**Category:** Beginners\
**Created:** [July 9, 2020, 3:31pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdataset-expected-by-trainer%2F148 "2020-07-09T15:31:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![prajjwal1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/prajjwal1/32/2246_2.png) [@prajjwal1](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fprajjwal1)%5C
**Post date:** [July 9, 2020, 3:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdataset-expected-by-trainer%2F148%2F2 "2020-07-09T15:54:03Z")

</div>

I’ll give you the full picture.

### The workflow:

You create an instance of `GlueDataset(data_args, tokenizer)`. Then you pass it to `Trainer(...)` class. In trainer, you also pass in `default_data_collator`. The reason is that `GlueDataset` return `InputExample` which is HF specific and cannot be used by Pytorch dataloader directly. So the `default_data_collator` takes in `List[InputExamples]` and returns a dict. This dict is then used by the dataloader.

So in trainer, if you pass `default_data_collator` with `TensorDataset`, it won’t work directly (That’s why you’re getting the error). This error is raised when dataloader will pass the batch to `default_data_collator`. I’d suggest using the default Pytorch `collate_fn` with your `TensorDataset`, it would work just fine.

#### One more additional thing:

Make sure the dataloader returns the dict with same key values `forward` method expects.  
Inside `_training_step`, you’ll pass `inputs` to the function, and then after the inputs are passed kept on gpu, the function does:  
`output = model(**inputs)`  
In this case, the keyword arguments have to match. In case, they don’t, you can inherit from `Trainer` and redefine your own method.

I hope this answers your question.

---

_[View the full topic](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fdataset-expected-by-trainer%2F148)._
