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

conda install -c pytorch torchtext

The problem is solved!

Restart jupyter notebook and it should work