我的数据是带有“标题”和“标签”列的熊猫数据框。我想用这个制作一个自定义数据集。所以我制作了如下数据集。我正在研究谷歌 colab
class newsDataset(torch.utils.data.Dataset):
def __init__(self,train=True,transform=None):
if train:
self.file = ttrain
else:
self.file= ttest
self.text_list = self.file['title'].values.tolist()
self.class_list=self.file['label'].values.tolist()
def __len__(self):
return len(self.text_list)
def __getitem__(self,idx):
label = self.class_list[idx]
text = self.text_list[idx]
if self.transform is not None:
text=self.transform(text)
return label, text
这就是我调用数据加载器的方式
trainset=newsDataset()
train_iter = DataLoader(trainset)
iter(train_iter).next()
它给了
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-153-9872744bc8a9> in <module>()
----> 1 iter(train_iter).next()
5 frames
/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataset.py in __getattr__(self, attribute_name)
81 return function
82 else:
---> 83 raise AttributeError
84
85 @classmethod
AttributeError:
没有确切的错误信息。有谁能够帮我?