Getting Importerror When Using Torchtext

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?

5

3 Answers

torchtext.data becomes torchtext.legacy.data

from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
3
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest