Search code examples
pythonnlppytorch

I am trying to import:from torchtext.legacy.data import Field, BucketIterator,Iterator,data, but get error 'No module named 'torchtext.legacy'


I am trying to execute the following code for a nlp proj

import torchtext
from torchtext.legacy.data import Field, BucketIterator, Iterator
from torchtext.legacy import data


----> 6 from torchtext.legacy.data import Field, BucketIterator, Iterator
      7 from torchtext.legacy import data
      8 

ModuleNotFoundError: No module named 'torchtext.legacy'.

I have tried it on both kaggle notebook and jupyter notebook and found the same error in both. i even tried to install !pip install -qqq deepmatcher==0.1.1 in kaggle to solve the issue but it still gives the same error. is there any solution to this?


Solution

  • Before you import torchtext.legacy, you need to !pip install torchtext==0.10.0.

    Maybe legacy was removed in version 0.11.0.