ValueError: The model did not return a loss from the inputs, only the following keys: logits. For reference, the inputs it received are input_ids,token_type_ids,attention_mask.
Code which I use for "bert-base-uncased" :
from transformers import Trainer
trainer = Trainer( model, training_args, train_dataset=tokenized_datasets["train"], eval_dataset=tokenized_datasets["test"], data_collator=data_collator, tokenizer=tokenizer, )
trainer.train()
Error:
ValueError Traceback (most recent call last) in <cell line: 1>() ----> 1 trainer.train()
3 frames /usr/local/lib/python3.10/dist-packages/transformers/trainer.py in compute_loss(self, model, inputs, return_outputs) 2690 else: 2691 if isinstance(outputs, dict) and "loss" not in outputs: -> 2692 raise ValueError( 2693 "The model did not return a loss from the inputs, only the following keys: " 2694 f"{','.join(outputs.keys())}. For reference, the inputs it received are {','.join(inputs.keys())}."
ValueError: The model did not return a loss from the inputs, only the following keys: logits. For reference, the inputs it received are input_ids,token_type_ids,attention_mask.
As suggested in a stack I have changed the columns into text and labels and I still facing this error.
Help me rectify
Where you able to solve it?
I have the same problem.
3354 else:
3355 if isinstance(outputs, dict) and "loss" not in outputs:
-> 3356 raise ValueError(
3357 "The model did not return a loss from the inputs, only the following keys: "
3358 f"{','.join(outputs.keys())}. For reference, the inputs it received are {','.join(inputs.keys())}."
ValueError: The model did not return a loss from the inputs, only the following keys: logits. For reference, the inputs it received are input_ids,attention_mask.