NoneType error when using Trainer
## System Info
Pop!_OS 20.04
Pytorch: 1.5.1
Transformers: 2.11.0
Python: 3.7.6

## Background Info
I wasn't sure what the `training_dataset` parameter of `Trainer` was so I opted to create a custom Pytorch `DataSet` using this [tutorial](https://pytorch.org/tutorials/beginner/data_loading_tutorial.html).
```python
from torch.utils.data import Dataset
import pandas as pd
import torch

class SDAbstractsDataset(Dataset):
    def __init__(self, csv_file):
        self.sd_abstracts_df = pd.read_csv(csv_file, encoding='ISO-8859-1')

    def __len__(self):
        return len(self.sd_abstracts_df)

    def __getitem__(self, idx):
        if torch.is_tensor(idx):
            idx = idx.tolist()
        sample = {'abstract_text': self.sd_abstracts_df.iloc[idx, 1]}
        return sample
```


I instantiate the `SDAbstractsDataset` object, create the `TrainingArguments` object, create an object based of a customized model, then instantiate the `Trainer` object with `sd_dataset`.

```python
from text_gen_w_transformers.finetune_gpt2 import GPT2FinetunedWithNgrams
from text_gen_w_transformers.custom_dataset import SDAbstractsDataset
from transformers import TrainingArguments, Trainer

sd_dataset = SDAbstractsDataset('/path/to/samples_64.csv')

training_args = TrainingArguments(
    output_dir='/path/to/output/dir',
    do_train=True,
    per_device_train_batch_size=4,
    learning_rate=1e-3,
    num_train_epochs=1
)

model = GPT2FinetunedWithNgrams.from_pretrained('gpt2')

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=sd_dataset
)

trainer.train()
```

Whenever I run the `trainer.train()` command, I get the following error:
```python
Epoch:   0%|          | 0/1 [00:00<?, ?it/s]
Iteration:   0%|          | 0/16 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/path/to/project/finetune_test.py", line 37, in <module>
    trainer.train()
  File "/path/to/anaconda3/lib/python3.7/site-packages/transformers/trainer.py", line 499, in train
    tr_loss += self._training_step(model, inputs, optimizer)
  File "/path/to/anaconda3/lib/python3.7/site-packages/transformers/trainer.py", line 622, in _training_step
    outputs = model(**inputs)
  File "/path/to/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in __call__
    result = self.forward(*input, **kwargs)
  File "/path/to/project/finetune_gpt2.py", line 42, in forward
    orig_input_str = self.tokenizer.decode(input_ids[0], skip_special_tokens=True)
TypeError: 'NoneType' object is not subscriptable

Epoch:   0%|          | 0/1 [00:00<?, ?it/s]
Iteration:   0%|          | 0/16 [00:00<?, ?it/s]
```

I did a little debugging and found that `inputs` in the line `tr_loss += self._training_step(model, inputs, optimizer)` was empty. Any thoughts on how to fix this?

Thanks in advance!
@aclifton314 just wondering if your custom dataset `__getitem__` is configured correctly? 
i.e I'm thinking it should be returning `return {'data': x, 'target': y}` or `return x, y`<|||||>@danieldiamond Thank you for the response. That's a good point about  `__getitem__`. The data in my csv file is structured in the following way:
```
Title, Raw
DistillBERT a distilled version of BERT smaller faster cheaper and lighter, As transfer learning from large-scale pretrained models becomes more prevalent in Natural Language Processing (NLP) blah blah blah.
``` 
I'm using the `Raw` columns in the csv as training data for my model, which inherits from `GPT2LMHeadModel`. I had assumed that there wouldn't be any need for targets for this model. But maybe there's something in `Trainer` that expects this particular type of format? In which case, I presume I could always set `y` to `None`?

I was reading [this post](https://discuss.huggingface.co/t/dataset-expected-by-trainer/148/2) on the HF forum and there is the following mention:
```
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)
```

I also looked through the debugger again. `inputs` for `tr_loss += self._training_step(model, inputs, optimizer)` looks like it is created in `for step, inputs in enumerate(epoch_iterator):` (this is in `trainer.py`). Looking at `epoch_iterator`, the `iterable` attribute contains the data from `sd_dataset` (i.e. `epoch_iterator -> iterable -> dataset`).

It looks like the data is being carried through `trainer.py`, but I can't seem to figure out why `inputs` would be empty.<|||||>Your dataset returns keys that are not known to the model. Also, it doesn't seem to tokenize your texts?
It should return a dict with the expected argument of your models, including the labels (that way the model will return the loss for the trainer). I have no idea what the code of `GPT2FinetunedWithNgrams` looks like, so that will depend on that.

Note that `Trainer` is not an abstract training loop for all DL problems, it's customized to work with the transformers models, so your model should behave the same way as HF models if you want to use it.<|||||>@sgugger incorporating your changes and upgrading to Transformers 3.0.2 solved the problem for me. I've got a long thread about it [here](https://discuss.huggingface.co/t/finetuning-gpt2-with-user-defined-loss/163/30).

Thanks for the help!