做文本分類的時候發(fā)現(xiàn)這個問題:
from torchtext.datasets import text_classification
報錯
ImportError: cannot import name 'text_classification' from 'torchtext.datasets'
閱讀源碼發(fā)現(xiàn)沒有這個模塊,查看文檔發(fā)現(xiàn)新版本較大改動,
解決方法:
#注釋掉from torchtext.datasets import text_classification
#原代碼改為:
train_dataset, test_dataset = torchtext.datasets.AG_NEWS(root='./data/ag_news_csv/', split=('train', 'test'))
#原代碼:
#train_dataset, test_dataset = text_classification.DATASETS['AG_NEWS'](root=load_data_path)