Getting ImportError when using torchtext

Viewed 10393

I'm getting the following error when I try to run this line of code:

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


ImportError: cannot import name 'Field' from 'torchtext.data' (C:\Users\user1\anaconda3\lib\site-packages\torchtext\data\__init__.py)

I was wondering if anyone knows what the issue might be and how to resolve it?

3 Answers

torchtext.data becomes torchtext.legacy.data

from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
conda install -c pytorch torchtext==0.8

This worked for me on Ubuntu 18.04.

I come up with this when using colab, then I update the torchtext version by

pip install -U torchtext

and it works for me

Related