When I run the tutorial, there is an error

in text_sentiment_ngrams_tutorial.ipynb

import torch
from torchtext.datasets import AG_NEWS
train_iter = iter(AG_NEWS(split='train'))

----> 3 train_iter = iter(AG_NEWS(split=‘train’))

File ~/opt/anaconda3/lib/python3.9/site-packages/torchtext/data/datasets_utils.py:248, in _create_dataset_directory..decorator..wrapper(root, *args, **kwargs)
246 if not os.path.exists(new_root):
247 os.makedirs(new_root)
→ 248 return fn(root=new_root, *args, **kwargs)

File ~/opt/anaconda3/lib/python3.9/site-packages/torchtext/data/datasets_utils.py:212, in _wrap_split_argument_with_fn..new_fn(root, split, **kwargs)
210 result = []
211 for item in _check_default_set(split, splits, fn.name):
→ 212 result.append(fn(root, item, **kwargs))
213 return _wrap_datasets(tuple(result), split)

File ~/opt/anaconda3/lib/python3.9/site-packages/torchtext/datasets/ag_news.py:55, in AG_NEWS(root, split)
50 if not is_module_available(“torchdata”):
51 raise ModuleNotFoundError(
52 "Package torchdata not found. Please install following instructions at https://github.com/pytorch/data"
53 )
—> 55 url_dp = IterableWrapper([URL[split]])
56 cache_dp = url_dp.on_disk_cache(
57 filepath_fn=lambda x: os.path.join(root, split + “.csv”),
58 hash_dict={os.path.join(root, split + “.csv”): MD5[split]},
59 hash_type=“md5”,
60 )
61 cache_dp = HttpReader(cache_dp)

NameError: name ‘IterableWrapper’ is not defined

1 Like

conda install -c pytorch torchtext

The problem is solved!

Restart jupyter notebook and it should work

3 Likes

I’ve got a different error on the same code lines.

import torch
from torchtext.datasets import AG_NEWS
train_iter = iter(AG_NEWS(split='train'))

TypeError Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 train_iter = iter(AG_NEWS(split=‘train’))

File ~/anaconda3/envs/mitre_gan/lib/python3.10/site-packages/torchtext/datasets/text_classification.py:170, in AG_NEWS(*args, **kwargs)
145 def AG_NEWS(args, **kwargs):
146 “”" Defines AG_NEWS datasets.
147 The labels includes:
148 - 1 : World
(…)
167
168 “”"
→ 170 return _setup_datasets(
((“AG_NEWS”,) + args), **kwargs)

TypeError: _setup_datasets() got an unexpected keyword argument ‘split’

I don’t know what the problem is.
Thx.

Not sure if this related, but it seems that torchtext 0.13m made quite some changes; see also this post.

1 Like