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.

#49
by Aravinth-Megnath - opened

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.

loss bert.png

Help me rectify

Aravinth-Megnath changed discussion status to closed

Where you able to solve it?

Sign up or log in to comment