cannot import name 'unicode_csv_reader' from 'torchtext.utils'

308 Views Asked by At
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-25-b2b2b2ad7bcb> in <cell line: 12>()
     10 from torch.utils.data import Dataset, DataLoader
     11 
---> 12 import pytorch_lightning as pl
     13 import seaborn as sns
     14 from pylab import rcParams

13 frames
/usr/local/lib/python3.9/dist-packages/torchtext/legacy/data/dataset.py 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
     14 
     15 

ImportError: cannot import name 'unicode_csv_reader' from 'torchtext.utils' (/usr/local/lib/python3.9/dist-packages/torchtext/utils.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

I was implementing a youtube video tutorial. i do the same but it doesnt work

https://www.youtube.com/watch?v=PCgrgHgy26c

torch: 1.8.1 texttorch: 0.9.1 pytroch-lightning: 1.2.6

please help me to let know about problem :(

1

There are 1 best solutions below

0
Toyo On

The problem is with your torchtext version.
The function unicode_csv_reader is no more available in the version 0.9.1 of torchtext.

To read a csv with the unicode encoding, you can just use the csv library, open your csv file with open using the utf-8 encoding and load your data.

import csv

with open("my_text_data.csv", "r", encoding="utf-8") as f:
    my_text_data = csv.reader(f)