2

I am trying to import these libraries - data, Field, LabelField, TabularDataset, BucketIterator from torchtext but I have this error. Could anyone suggest how to solve this problem please? Thank you so much.

from torchtext.legacy import data
from torchtext.legacy import Field, LabelField, TabularDataset, BucketIterator
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 from torchtext.legacy import data
      2 from torchtext.legacy import Field, LabelField, TabularDataset, BucketIterator

File /opt/anaconda3/lib/python3.8/site-packages/torchtext/legacy/__init__.py:1, in <module>
----> 1 from . import data
      2 from .. import nn  # Not in the legacy folder
      3 from . import datasets

File /opt/anaconda3/lib/python3.8/site-packages/torchtext/legacy/data/__init__.py:3, in <module>
      1 from .batch import Batch
      2 from .example import Example
----> 3 from .field import RawField, Field, ReversibleField, SubwordField, NestedField, LabelField
      4 from .iterator import (batch, BucketIterator, Iterator, BPTTIterator, pool)
      5 from .pipeline import Pipeline

File /opt/anaconda3/lib/python3.8/site-packages/torchtext/legacy/data/field.py:6, in <module>
      4 import torch
      5 from tqdm import tqdm
----> 6 from .dataset import Dataset
      7 from .pipeline import Pipeline
      8 from torchtext.data.utils import get_tokenizer, dtype_to_attr, is_tokenizer_serializable

File /opt/anaconda3/lib/python3.8/site-packages/torchtext/legacy/data/dataset.py:13, in <module>
     11 from torchtext.data.utils import RandomShuffler
     12 from .example import Example
---> 13 from torchtext.utils import download_from_url, unicode_csv_reader
     16 class Dataset(torch.utils.data.Dataset):
     17     """Defines a dataset composed of Examples along with its Fields.
     18 
     19     Attributes:
   (...)
     25             will have a shared vocabulary.
     26     """

ImportError: cannot import name 'unicode_csv_reader' from 'torchtext.utils' (/opt/anaconda3/lib/python3.8/site-packages/torchtext/utils.py)
2
  • Perhaps you need to update torchtext? Have you checked what version you have? Commented Jul 20, 2022 at 16:34
  • the version is 1.12.0. Commented Jul 20, 2022 at 16:55

1 Answer 1

3

you can try this:!pip install torch==1.8.0 torchtext==0.9.0

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.