Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 660
QMan5 Avatar asked Mar 09 '21 15:03

QMan5


3 Answers

torchtext.data becomes torchtext.legacy.data

from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
like image 189
niek tuytel Avatar answered Oct 17 '22 15:10

niek tuytel


conda install -c pytorch torchtext==0.8

This worked for me on Ubuntu 18.04.

like image 4
okoksal Avatar answered Oct 17 '22 15:10

okoksal


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

pip install -U torchtext

and it works for me

like image 1
bamboo Zhang Avatar answered Oct 17 '22 15:10

bamboo Zhang