原始代码片段
def process_raw_pred(raw_question_matrix, raw_pred, num_questions: int) -> tuple:
questions = torch.nonzero(raw_question_matrix)[1:, 1] % num_questions # torch.Size([49])
length = questions.shape[0] #49
pred = raw_pred[:length] # torch.Size([49, 123])
pred = pred.gather(1, questions.view(-1, 1)).flatten() # torch.Size([49])
# pred = raw_pred[questions] # 从 raw_pred 中选择与 questions 索引对应的列
# pred = pred.flatten() # 展平为一维张量
truth = torch.nonzero(raw_question_matrix)[1:, 1] // num_questions # torch.Size([49])
return pred, truth
[Epoch 999] LogisticLoss: 0.330749
INFO:root:save parameters to dkt.params
INFO:root:load parameters from dkt.params
evaluating: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████| 371/371 [00:00<00:00, 3192.52it/s]
auc: 0.692966
总觉得预测值和真实值在维度上对应不上
进行修改之后的代码片段
def process_raw_pred(raw_question_matrix, raw_pred, num_questions: int) -> tuple:
questions = torch.nonzero(raw_question_matrix)[:, 1] % num_questions
length = questions.shape[0]
pred = raw_pred[:length]
pred = pred.gather(1, questions.view(-1, 1)).flatten()
# pred = raw_pred[questions] # 从 raw_pred 中选择与 questions 索引对应的列
# pred = pred.flatten() # 展平为一维张量
truth = torch.nonzero(raw_question_matrix)[:, 1] // num_questions # torch.Size([49])
return pred, truth
修改点:[1:, 1]–>[:, 1]
出现异常:epoch = 1000
是我修改之后,出现标签泄露的问题了吗?
哪位大神可以给我解释一下
[Epoch 999] LogisticLoss: 0.003886
INFO:root:save parameters to dkt.params
INFO:root:load parameters from dkt.params
evaluating: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:00<00:00, 86.96it/s]
auc: 0.999979