default value for default_label_names incorrectly causes has_label in trainer.py to be true
Author: seirasto
Pull request: no

### System Info

- `transformers` version: 4.24.0
- Platform: Linux-4.18.0-372.26.1.el8_6.x86_64-x86_64-with-glibc2.17
- Python version: 3.8.13
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.11.0+cu113 (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed

### Who can help?

@sgugger This is a bug in `trainer.py`

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

I've upgraded transformers from 4.17.0 to 4.24.0. In the earlier version(s), the default value for `default_label_names` was set to `["labels"]`. In the current version the default is set to an empty array `[]`

4.17.0:
```python
default_label_names = (
            ["start_positions", "end_positions"]
            if type(self.model).__name__ in MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES.values()
            else ["labels"]
        )
``` 

4.24.0:
```python
default_label_names = find_labels(self.model.__class__)
```

`default_label_names` is used to set `self.label_names` if no labels are supplied:

```python
self.label_names = default_label_names if self.args.label_names is None else self.args.label_names
```

 It will then be used to decide the value of `has_labels` as `True` or `False`:

```python
        has_labels = all(inputs.get(k) is not None for k in self.label_names)
```

In 4.17.0 with the default value of `["labels"]` has_labels was `False`. In 4.24.0 with the default value of `[]` has_labels is `True` causing the program to fail in `compute_loss` during eval:

```
E               ValueError: The model did not return a loss from the inputs, only the following keys: start_logits,end_logits,target_type_logits. For reference, the inputs it received are input_ids,attention_mask.
```

### Expected behavior

The default behavior when no labels are provided should cause `has_labels` to be `False`

Comments:
Thanks for opening this issue. Could you please explain which code sample stopped working for you with this change?

This is using `do_eval` in our own code `run_mrc.py` in our PrimeQA code base: https://github.com/primeqa/primeqa/tree/main/primeqa/mrc However, I believe this issue will happen in any instance where labels are not provided through `self.arg.label_names` and `label` is not found in `self.model.__class__`

This is too vague for us to act upon. Do you have a reproducer of the problem?

I'm not sure what the best way is to reproduce it for you. It occurs because we have our own model wrapper. I see that in the signature parameters there is a `labels` parameter, but this does not exist in our signature. Perhaps it is expected to always be there? 

Using AutoModelForSequenceClassification:
```
mappingproxy(OrderedDict([('self', <Parameter "self">), ('input_ids', <Parameter "input_ids: Union[torch.LongTensor, NoneType] = None">), ('attention_mask', <Parameter "attention_mask: Union[torch.FloatTensor, NoneType] = None">), ('token_type_ids', <Parameter "token_type_ids: Union[torch.LongTensor, NoneType] = None">), ('position_ids', <Parameter "position_ids: Union[torch.LongTensor, NoneType] = None">), ('head_mask', <Parameter "head_mask: Union[torch.FloatTensor, NoneType] = None">), ('inputs_embeds', <Parameter "inputs_embeds: Union[torch.FloatTensor, NoneType] = None">), ('labels', <Parameter "labels: Union[torch.LongTensor, NoneType] = None">), ('output_attentions', <Parameter "output_attentions: Union[bool, NoneType] = None">), ('output_hidden_states', <Parameter "output_hidden_states: Union[bool, NoneType] = None">), ('return_dict', <Parameter "return_dict: Union[bool, NoneType] = None">)]))
```

Our model wrapper: 

```
mappingproxy(OrderedDict([('self', <Parameter "self">), ('input_ids', <Parameter "input_ids=None">), ('attention_mask', <Parameter "attention_mask=None">), ('token_type_ids', <Parameter "token_type_ids=None">), ('position_ids', <Parameter "position_ids=None">), ('head_mask', <Parameter "head_mask=None">), ('inputs_embeds', <Parameter "inputs_embeds=None">), ('output_attentions', <Parameter "output_attentions=None">), ('output_hidden_states', <Parameter "output_hidden_states=None">), ('return_dict', <Parameter "return_dict=None">), ('kwargs', <Parameter "**kwargs">)]))
```

Can you try if the PR above would solve your problem?

That did not work. Our model inherits from PreTrainedModel so it is still an instance of it.

Ah in this case, it will need to have the label names in the signature like the models in the library. Or you can always pass along the `label_names` you want in the training arguments to override the defaults.

Thanks! I am using the training arg to override the default right now. I'm just wondering whether when `self.label_names=[]` causes `has_labels` to be `True` is the expected behavior.

```
has_labels = all(inputs.get(k) is not None for k in self.label_names)
``` 

Ah yes, I understand your concern better, thanks! Will adapt the PR.

Can you try again the PR above?

This worked! Thank you!!

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Fixed by #20113