python代码报错

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
for  batch_idx, batch in enumerate(train_dataloader, 0): #枚举类型
    x_p,x_c,y=map(lambda x: x.to(device), batch)
    print("*********")
    print("punchline shape: ",x_p.shape)
    print("context shape: ",x_c.shape)
    print("humor labels: ",y)
    if batch_idx==5:
    break

第二行代码报错
IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

错误不在这里,要把程序贴全。
数据类型不对,先检查 train_dataloader 内容对不对。

说明train_dataloader不是一个可迭代对象
或者它是可迭代对象但是不可序列化
错误信息已经很明确,只有列出的这些类型是可以进行这个操作的,其他类型都不行