text
text copied to clipboard
module 'torchtext.data' has no attribute 'Iterator'
❓ Questions and Help
Description
class MyIterator(data.Iterator): def create_batches(self): if self.train: def pool(d, random_shuffler): for p in data.batch(d, self.batch_size * 100): p_batch = data.batch( sorted(p, key=self.sort_key), self.batch_size, self.batch_size_fn) for b in random_shuffler(list(p_batch)): yield b self.batches = pool(self.data(), self.random_shuffler)
else:
self.batches = []
for b in data.batch(self.data(), self.batch_size,
self.batch_size_fn):
self.batches.append(sorted(b, key=self.sort_key))
File "C:\Users\mcpej\ResnetGPT\Batch.py", line 32, in
cc @parmeet
@learnJunWei Could you please provide torchtext version you are using? We have retired bunch of code into legacy in the recent release of torchtext. Please refer to the release notes
Yes, torchtext.data indeed have no attribute 'Iterator' in the latest release (https://github.com/pytorch/text/blob/release/0.9/torchtext/data/init.py#L9).
To make use of the legacy code, you would need to use torchtext.legacy instead of torchtext. You may also find migration tutorial useful. Please note that as stated in the release notes, we may plan to complete remove legacy code in upcoming releases. If you have any questions to adapt to latest torchtext library, please do not hesitate to open issue.
@learnJunWei I guess you can access it using torchtext.legacy.data.Iterator instead of torchtext.data.Iterator
Try code below:
from torchtext.legacy.data import Iterator