我看到一些 github 评论说 model() 调用的损失的输出是困惑的形式: https ://github.com/huggingface/transformers/issues/473
但是当我查看相关代码时...... https://huggingface.co/transformers/_modules/transformers/modeling_openai.html#OpenAIGPTLMHeadModel.forward
if labels is not None:
# Shift so that tokens < n predict n
shift_logits = lm_logits[..., :-1, :].contiguous()
shift_labels = labels[..., 1:].contiguous()
# Flatten the tokens
loss_fct = CrossEntropyLoss()
loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.view(-1))
outputs = (loss,) + outputs
return outputs # (loss), lm_logits, (all hidden states), (all attentions)
我看到交叉熵正在计算,但没有转化为困惑。损失最终在哪里转化?还是已经有我不理解的转变?