728x90
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.
이 오류는 모델이 손실(loss) 값을 반환하지 않았을 때 발생합니다.
일반적으로 모델이 훈련 중에 손실 값을 계산하도록 구성되어야 합니다.
Hugging Face Transformers의 Trainer
클래스는 모델이 손실 값을 반환하도록 설정되어 있어야 합니다.
손실을 반환하려면 모델 클래스에 forward
메서드를 구현하여 손실을 계산하고 반환해야 합니다.
예를 들어, 다음과 같이 모델 클래스를 정의하고 손실을 반환하는 forward
메서드를 추가할 수 있습니다.
from transformers import AutoModelForSequenceClassification
class CustomModel(AutoModelForSequenceClassification):
def forward(self, input_ids, attention_mask, token_type_ids, labels=None):
outputs = self(input_ids=input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, labels=labels)
loss = outputs.loss # Get the loss from the model's output
return loss # Return the loss
그런 다음 이러한 모델을 사용하여 Trainer
를 초기화하고 훈련할 수 있습니다.
이 모델은 손실을 반환하므로 Trainer
가 손실 값을 사용하여 모델을 훈련할 것입니다.
이를 통해 모델이 올바르게 손실을 반환하고 훈련이 진행될 것입니다.
728x90
LIST