Yiğit Yılmaz
Yiğit Yılmaz

Reputation: 77

Error: AttributeError: module 'torchtext.data' has no attribute 'Field'

Actually I saw couple of same questions in the forum but i still don't have the right solution.
here's my code block:

import torchtext as data
import torchtext.datasets as datasets
...
...
text_field = data.Field(lower=True)
...
...

I have the following issue when I run the program:

Traceback (most recent call last):
  File "C:\Users\emre.sinoforoglu\Desktop\cnn-text-classification-pytorch-master\main.py", line 71, in <module>
    text_field = data.Field(lower=True)
                 ^^^^^^^^^^
AttributeError: module 'torchtext.data' has no attribute 'Field'

I tried each answers for the past questions one by one but still I still have te same issue.
here's my pip list:

torch                        2.0.0
torchtext                    0.15.0

I changed "import torchtext as data" with "import torchtext.legacy.data as data" then I got the following issue:

ModuleNotFoundError: No module named 'torchtext.legacy'

I uninstalled the torchtext with "pip uninstall torchtext" command and install the older version with "pip install torchtext==0.8.0" command and then i got this following issue:

ERROR: Could not find a version that satisfies the requirement torchtext==0.8.0 (from versions: 0.1.1, 0.2.0, 0.2.1, 0.2.3, 0.3.1, 0.4.0, 0.5.0, 0.6.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1)
ERROR: No matching distribution found for torchtext==0.8.0

Upvotes: 2

Views: 1851

Answers (1)

Biplab
Biplab

Reputation: 11

Please try using:

torch==2.0.1 torchtext==0.5.0

This is working for me.

Upvotes: 1

Related Questions