text icon indicating copy to clipboard operation
text copied to clipboard

module 'torchtext.data' has no attribute 'Iterator'

Open learnJunWei opened this issue 4 years ago • 4 comments

❓ 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 class MyIterator(data.Iterator): AttributeError: module 'torchtext.data' has no attribute 'Iterator'

learnJunWei avatar Apr 04 '21 23:04 learnJunWei

cc @parmeet

cpuhrsch avatar Apr 23 '21 02:04 cpuhrsch

@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.

parmeet avatar May 03 '21 14:05 parmeet

@learnJunWei I guess you can access it using torchtext.legacy.data.Iterator instead of torchtext.data.Iterator

JVedant avatar Jun 01 '21 21:06 JVedant

Try code below:

from torchtext.legacy.data import Iterator

liyc-ai avatar Aug 19 '21 09:08 liyc-ai