ImportError: cannot import name ‘text_classification‘ from ‘torchtext.datasets‘

问题描述:

输入以下代码报错

from torchtext.datasets import text_classification

ImportError: cannot import name ‘text_classification’ from ‘torchtext.datasets’(F:\Anaconda\envs\pytorch_hu\lib\site-packages\torchtext\datasets_init_.py)

解决方案:

#注释掉from torchtext.datasets import text_classification 
#将文本分类数据集保存在根目录下的代码改为:
train_dataset, test_dataset = torchtext.datasets.AG_NEWS(root='./data/ag_news_csv/', split=('train', 'test'))

你可能感兴趣的:(工具安装和代码实战,pytorch,深度学习,python)