Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'dict' object has no attribute 'dataset' #21

Closed
ulfat191 opened this issue Aug 24, 2022 · 1 comment
Closed

AttributeError: 'dict' object has no attribute 'dataset' #21

ulfat191 opened this issue Aug 24, 2022 · 1 comment

Comments

@ulfat191
Copy link

I am getting this error while writing the following class code. The error message is attached below the code.

class GPReviewDataset(data.dataset):

def init(self, review, target, tokenizer, max_len):
self.review = review
self.target = target
self.tokenizer = tokenizer
self.max_len = max_len

def len(self):
# return the number of reviews we have
return len(self.reviews)

def getitem(self, item): # takes the index and the reviews
review = str(self.reviews[item])

encoding = self.tokenizer.encode_plus(
  review,
  add_special_tokens=True,
  max_length=self.max_len,
  return_token_type_ids=False,
  pad_to_max_length=True,
  return_attention_mask=True,
  return_tensors='pt'
)

return {
  'review_text': review,
  'input_ids': encoding['input_ids'].flatten(),
  'attention_mask': encoding['attention_mask'].flatten(),
  'targets': torch.tensor(self.target, dtype=torch.long)
}

image

@ulfat191
Copy link
Author

for those who are facing this error as you code while watching the video, the solution is as follows -

  1. class GPReviewDataset(data.dataset): -> change 'data.dataset' to 'Dataset' -> change is already made in the code but not in the video

  2. In the create dataloader function write
    return DataLoader instead of return data.DataLoader

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant